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 23 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
1 change: 1 addition & 0 deletions .eslintignore
Expand Up @@ -34,3 +34,4 @@ packages/next-swc/crates/**
bench/nested-deps/pages/**
bench/nested-deps/components/**
packages/next-bundle-analyzer/index.d.ts
packages/eslint-plugin-next/lib/**/*
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,6 +3,7 @@ dist
.next
target
packages/next/wasm/@next
packages/eslint-plugin-next/lib

# dependencies
node_modules
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Expand Up @@ -26,3 +26,4 @@ bench/nested-deps/pages/**/*
bench/nested-deps/components/**/*
pnpm-lock.yaml
**/convex/_generated/**
packages/eslint-plugin-next/lib/**/*
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"
}
}
43 changes: 0 additions & 43 deletions packages/eslint-plugin-next/lib/rules/no-img-element.js

This file was deleted.

6 changes: 5 additions & 1 deletion packages/eslint-plugin-next/package.json
Expand Up @@ -15,6 +15,10 @@
"glob": "7.1.7"
},
"devDependencies": {
"@types/eslint": "7.28.0"
"eslint": "7.24.0"
},
"scripts": {
"build": "swc -d lib src",
balazsorban44 marked this conversation as resolved.
Show resolved Hide resolved
"prepublishOnly": "cd ../../ && turbo run build"
}
}
37 changes: 37 additions & 0 deletions packages/eslint-plugin-next/src/rules/no-img-element.ts
@@ -0,0 +1,37 @@
import type { Rule } from 'eslint'

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

export const meta: Rule.RuleMetaData = {
docs: {
description: 'Prevent usage of `<img>` element to prevent layout shift.',
category: 'HTML',
recommended: true,
url,
},
type: 'problem',
schema: [],
}

export const create: Rule.RuleModule['create'] = (context) => {
return {
JSXOpeningElement(node) {
if (node.name.name !== 'img') {
return
}

if (node.attributes.length === 0) {
return
}

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

context.report({
node,
message: `Do not use \`<img>\` element. Use \`<Image />\` from \`next/image\` instead. See: ${url}`,
})
},
}
}
Expand Up @@ -3,5 +3,6 @@
"module": "commonjs",
"target": "es2019"
},
"include": ["src/**/*"],
"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.

3 changes: 2 additions & 1 deletion test/unit/eslint-plugin-next/index.test.ts
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/unit/eslint-plugin-next/no-img-element.test.ts
@@ -1,4 +1,4 @@
import rule from '@next/eslint-plugin-next/lib/rules/no-img-element'
import * as rule from '@next/eslint-plugin-next/lib/rules/no-img-element'
import { RuleTester } from 'eslint'
;(RuleTester as any).setDefaultConfig({
parserOptions: {
Expand Down