Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add build step to eslint-plugin-next #38647

Merged
merged 30 commits into from Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e3d291e
chore: build `eslint-plugin-next` with SWC
balazsorban44 Jul 14, 2022
452dd2f
refactor rule to TS
balazsorban44 Jul 14, 2022
33618d1
fix test
balazsorban44 Jul 14, 2022
5f47f61
update lock file
balazsorban44 Jul 14, 2022
eadbd2c
bump target
balazsorban44 Jul 14, 2022
99190e5
Merge branch 'canary' into chore/add-build-to-eslint-plugin-next
balazsorban44 Jul 14, 2022
86dc4a6
Merge branch 'canary' into chore/add-build-to-eslint-plugin-next
balazsorban44 Jul 20, 2022
2aa41ea
Merge branch 'canary' into chore/add-build-to-eslint-plugin-next
balazsorban44 Aug 8, 2022
c391b99
Merge branch 'chore/add-build-to-eslint-plugin-next' of github.com:ve…
balazsorban44 Aug 8, 2022
99ff94b
use module.exports
balazsorban44 Aug 26, 2022
63dd610
simplify
balazsorban44 Aug 26, 2022
7781e75
fix
balazsorban44 Aug 26, 2022
49ea9ad
`export default`
balazsorban44 Aug 26, 2022
5d0f5d4
`export default` + `module.exports`
balazsorban44 Aug 26, 2022
5b495ea
move type
balazsorban44 Aug 26, 2022
08cbfc8
Merge branch 'canary' into chore/add-build-to-eslint-plugin-next
balazsorban44 Aug 26, 2022
fe375b7
remove `export default`, refer `dist` in test
balazsorban44 Sep 6, 2022
63bedec
move to `src`, use named exports
balazsorban44 Sep 7, 2022
989f550
keep `lib` as entry point in `package.json`
balazsorban44 Sep 7, 2022
aff5dce
revert `dist` to `lib`
balazsorban44 Sep 7, 2022
2616c8f
Prettier ignore `eslint-plugin-next/lib`
balazsorban44 Sep 7, 2022
93cb579
ESLint ignore `eslint-plugin-next/lib`
balazsorban44 Sep 7, 2022
977fec0
Merge branch 'canary' into chore/add-build-to-eslint-plugin-next
ijjk Sep 13, 2022
cb6db9b
update back to dist folder
ijjk Sep 13, 2022
c455f39
Merge branch 'canary' into chore/add-build-to-eslint-plugin-next
ijjk Sep 13, 2022
b45de36
update tests
ijjk Sep 13, 2022
6892f69
Merge branch 'canary' into chore/add-build-to-eslint-plugin-next
balazsorban44 Sep 16, 2022
201471b
revert
balazsorban44 Sep 16, 2022
b9bcb3a
revert
balazsorban44 Sep 16, 2022
788f445
Merge branch 'canary' into chore/add-build-to-eslint-plugin-next
balazsorban44 Sep 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/eslint-plugin-next/.swcrc
@@ -0,0 +1,11 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript"
}
},
"module": {
"type": "commonjs"
}
}
@@ -1,6 +1,8 @@
import type { Rule } from 'eslint'

const url = 'https://nextjs.org/docs/messages/no-img-element'

module.exports = {
const rule: Rule.RuleModule = {
meta: {
docs: {
description: 'Prevent usage of `<img>` element to prevent layout shift.',
Expand All @@ -11,8 +13,7 @@ module.exports = {
type: 'problem',
schema: [],
},

create: function (context) {
create(context) {
return {
JSXOpeningElement(node) {
if (node.name.name !== 'img') {
Expand All @@ -23,13 +24,7 @@ module.exports = {
return
}

if (
node.parent &&
node.parent.openingElement &&
node.parent.parent.openingElement &&
node.parent.parent.openingElement.name &&
node.parent.parent.openingElement.name.name === 'picture'
) {
if (node.parent?.parent?.openingElement?.name?.name === 'picture') {
return
}

Expand All @@ -41,3 +36,6 @@ module.exports = {
}
},
}

export default rule
module.exports = rule
balazsorban44 marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 7 additions & 3 deletions packages/eslint-plugin-next/package.json
Expand Up @@ -2,19 +2,23 @@
"name": "@next/eslint-plugin-next",
"version": "12.2.4",
"description": "ESLint plugin for NextJS.",
"main": "lib/index.js",
"main": "dist/index.js",
balazsorban44 marked this conversation as resolved.
Show resolved Hide resolved
"license": "MIT",
"repository": {
"url": "vercel/next.js",
"directory": "packages/eslint-plugin-next"
},
"files": [
"lib"
"dist"
],
"dependencies": {
"glob": "7.1.7"
},
"devDependencies": {
"@types/eslint": "7.28.0"
"eslint": "7.24.0"
},
"scripts": {
"build": "swc -d dist lib",
"prepublishOnly": "cd ../../ && turbo run build"
}
}
Expand Up @@ -3,5 +3,6 @@
"module": "commonjs",
"target": "es2019"
},
"include": ["lib/**/*"],
"exclude": ["node_modules"]
}
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions test/unit/eslint-plugin-next/index.test.ts
Expand Up @@ -3,7 +3,7 @@ import glob from 'glob'
import index from '@next/eslint-plugin-next'

const getRuleNameFromRulePath = (path) => basename(path, '.js')
const rulePaths = glob.sync('packages/eslint-plugin-next/lib/rules/*js', {
const rulePaths = glob.sync('packages/eslint-plugin-next/dist/rules/*js', {
absolute: true,
})

Expand All @@ -15,7 +15,8 @@ describe('@next/eslint-plugin-next index', () => {
})

rulePaths.forEach((rulePath) => {
const rule = require(rulePath)
let rule = require(rulePath)
rule = rule.default ?? rule
const ruleName = getRuleNameFromRulePath(rulePath)
const { recommended = false } = rule.meta.docs

Expand Down