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

Adds eslint-plugin-eslint-plugin to ensure eslint-plugin-next rules follow ESLint rule best practices along with enforcing some consistency. #37920

Merged
merged 15 commits into from Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
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
24 changes: 24 additions & 0 deletions .eslintrc.json
Expand Up @@ -145,6 +145,30 @@
}
]
}
},
{
"files": [
"packages/eslint-plugin-next/**/*.js",
"test/unit/eslint-plugin-next/**/*.test.ts"
],
"extends": ["plugin:eslint-plugin/recommended"],
"parserOptions": {
"sourceType": "script"
},
"rules": {
"eslint-plugin/prefer-replace-text": "error",
"eslint-plugin/report-message-format": [
"error",
".+\\. See: https://nextjs.org/docs/messages/[a-z\\-]+$"
],
"eslint-plugin/require-meta-docs-description": [
"error",
{
"pattern": ".+"
}
],
"eslint-plugin/require-meta-docs-url": "error"
}
}
],
"rules": {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -123,6 +123,7 @@
"escape-string-regexp": "2.0.0",
"eslint": "7.24.0",
"eslint-config-next": "workspace:*",
"eslint-plugin-eslint-plugin": "4.3.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jest": "24.3.5",
"eslint-plugin-react": "7.23.2",
Expand Down
Expand Up @@ -9,6 +9,8 @@ module.exports = {
recommended: true,
url,
},
type: 'problem',
schema: [],
},
create: function (context) {
return {
Expand Down
Expand Up @@ -9,6 +9,8 @@ module.exports = {
recommended: true,
url,
},
type: 'problem',
schema: [],
},
create: function (context) {
return {
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin-next/lib/rules/inline-script-id.js
Expand Up @@ -8,6 +8,8 @@ module.exports = {
recommended: true,
url,
},
type: 'problem',
schema: [],
},
create: function (context) {
let nextScriptImportName = null
Expand Down
Expand Up @@ -25,8 +25,9 @@ module.exports = {
recommended: true,
url,
},
type: 'problem',
schema: [],
},
schema: [],
create: function (context) {
return {
JSXOpeningElement(node) {
Expand Down
Expand Up @@ -5,6 +5,8 @@ module.exports = {
recommended: true,
url: 'https://nextjs.org/docs/messages/no-assign-module-variable',
},
type: 'problem',
schema: [],
},

create: function (context) {
Expand Down
Expand Up @@ -11,6 +11,8 @@ module.exports = {
recommended: true,
url,
},
type: 'problem',
schema: [],
},
create: function (context) {
let scriptImportName = null
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin-next/lib/rules/no-css-tags.js
Expand Up @@ -7,8 +7,9 @@ module.exports = {
recommended: true,
url,
},
type: 'problem',
schema: [],
},
schema: [],
create: function (context) {
return {
JSXOpeningElement(node) {
Expand Down
Expand Up @@ -10,6 +10,8 @@ module.exports = {
recommended: true,
url,
},
type: 'problem',
schema: [],
},
create: function (context) {
return {
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin-next/lib/rules/no-duplicate-head.js
Expand Up @@ -8,6 +8,8 @@ module.exports = {
recommended: true,
url,
},
type: 'problem',
schema: [],
},
create: function (context) {
let documentImportName
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin-next/lib/rules/no-head-element.js
Expand Up @@ -8,7 +8,8 @@ module.exports = {
recommended: true,
url,
},
fixable: 'code',
type: 'problem',
schema: [],
},
create: function (context) {
return {
Expand Down
Expand Up @@ -9,6 +9,8 @@ module.exports = {
recommended: true,
url,
},
type: 'problem',
schema: [],
},
create: function (context) {
return {
Expand Down
Expand Up @@ -30,7 +30,7 @@ module.exports = {
recommended: true,
url,
},
fixable: null, // or "code" or "whitespace"
type: 'problem',
schema: [
{
oneOf: [
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin-next/lib/rules/no-img-element.js
Expand Up @@ -8,7 +8,8 @@ module.exports = {
recommended: true,
url,
},
fixable: 'code',
type: 'problem',
schema: [],
},

create: function (context) {
Expand Down
Expand Up @@ -10,6 +10,8 @@ module.exports = {
recommended: true,
url,
},
type: 'problem',
schema: [],
},
create: function (context) {
const paths = context.getFilename().split('pages')
Expand Down
Expand Up @@ -8,6 +8,8 @@ module.exports = {
recommended: true,
url,
},
type: 'problem',
schema: [],
},
create: function (context) {
let isNextHead = null
Expand Down
Expand Up @@ -9,7 +9,8 @@ module.exports = {
recommended: true,
url,
},
fixable: 'code',
type: 'problem',
schema: [],
},
create: function (context) {
return {
Expand Down Expand Up @@ -44,5 +45,3 @@ module.exports = {
}
},
}

module.exports.schema = []
3 changes: 2 additions & 1 deletion packages/eslint-plugin-next/lib/rules/no-sync-scripts.js
Expand Up @@ -7,8 +7,9 @@ module.exports = {
recommended: true,
url,
},
type: 'problem',
schema: [],
},
schema: [],
create: function (context) {
return {
JSXOpeningElement(node) {
Expand Down
Expand Up @@ -7,6 +7,8 @@ module.exports = {
'Prevent usage of `<title>` with `Head` component from `next/document`.',
url,
},
type: 'problem',
schema: [],
},
create: function (context) {
let headFromNextDocument = false
Expand Down
5 changes: 3 additions & 2 deletions packages/eslint-plugin-next/lib/rules/no-typos.js
Expand Up @@ -39,14 +39,15 @@ function minDistance(a, b) {
return previousRow[previousRow.length - 1]
}

/* eslint-disable eslint-plugin/require-meta-docs-url */
module.exports = {
meta: {
docs: {
description: 'Prevent common typos in Next.js data fetching functions.',
category: 'Stylistic Issues',
recommended: true,
},
fixable: null,
type: 'problem',
schema: [],
},

create: function (context) {
Expand Down
Expand Up @@ -72,7 +72,8 @@ module.exports = {
recommended: true,
url,
},
fixable: null,
type: 'problem',
schema: [],
},

create: function (context) {
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

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