From ab48f547864a1e325dd92bfb4790833917e1d71f Mon Sep 17 00:00:00 2001 From: Michael Novotny Date: Sun, 7 Aug 2022 23:52:02 -0500 Subject: [PATCH] Adds `eslint-plugin-eslint-plugin` to ensure `eslint-plugin-next` rules follow ESLint rule best practices along with enforcing some consistency. (#37920) * Adds eslint-plugin-eslint-plugin and recommended rules. * Removes `fixable` as none of the rules contain fixers. * Adds description and url rules. * Adds message format. * Removes optional dependencies. * Lints eslint-plugin-next tests too. * Removes optional dependencies from pnpm lock file. * Resets pnpm lock file. * Resets package.json too. * Fixes pnpm lockfile. --- .eslintrc.json | 24 +++++++++++++++++++ package.json | 1 + .../lib/rules/google-font-display.js | 2 ++ .../lib/rules/google-font-preconnect.js | 2 ++ .../lib/rules/inline-script-id.js | 2 ++ .../lib/rules/next-script-for-ga.js | 3 ++- .../lib/rules/no-assign-module-variable.js | 2 ++ ...ore-interactive-script-outside-document.js | 2 ++ .../lib/rules/no-css-tags.js | 3 ++- .../lib/rules/no-document-import-in-page.js | 2 ++ .../lib/rules/no-duplicate-head.js | 2 ++ .../lib/rules/no-head-element.js | 3 ++- .../lib/rules/no-head-import-in-document.js | 2 ++ .../lib/rules/no-html-link-for-pages.js | 2 +- .../lib/rules/no-img-element.js | 3 ++- .../lib/rules/no-page-custom-font.js | 2 ++ .../lib/rules/no-script-component-in-head.js | 2 ++ .../lib/rules/no-styled-jsx-in-document.js | 5 ++-- .../lib/rules/no-sync-scripts.js | 3 ++- .../lib/rules/no-title-in-document-head.js | 2 ++ .../eslint-plugin-next/lib/rules/no-typos.js | 5 ++-- .../lib/rules/no-unwanted-polyfillio.js | 3 ++- pnpm-lock.yaml | 13 ++++++++++ 23 files changed, 78 insertions(+), 12 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 3f4f64868a1e..4f3c9e2164f1 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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": { diff --git a/package.json b/package.json index 5877847f2216..789310d73bcd 100644 --- a/package.json +++ b/package.json @@ -126,6 +126,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", diff --git a/packages/eslint-plugin-next/lib/rules/google-font-display.js b/packages/eslint-plugin-next/lib/rules/google-font-display.js index a1ca8a9a7a95..19a7096eca90 100644 --- a/packages/eslint-plugin-next/lib/rules/google-font-display.js +++ b/packages/eslint-plugin-next/lib/rules/google-font-display.js @@ -9,6 +9,8 @@ module.exports = { recommended: true, url, }, + type: 'problem', + schema: [], }, create: function (context) { return { diff --git a/packages/eslint-plugin-next/lib/rules/google-font-preconnect.js b/packages/eslint-plugin-next/lib/rules/google-font-preconnect.js index cbc1a65ac682..ae5491f964c6 100644 --- a/packages/eslint-plugin-next/lib/rules/google-font-preconnect.js +++ b/packages/eslint-plugin-next/lib/rules/google-font-preconnect.js @@ -9,6 +9,8 @@ module.exports = { recommended: true, url, }, + type: 'problem', + schema: [], }, create: function (context) { return { diff --git a/packages/eslint-plugin-next/lib/rules/inline-script-id.js b/packages/eslint-plugin-next/lib/rules/inline-script-id.js index d936825912d8..e7cd994bd189 100644 --- a/packages/eslint-plugin-next/lib/rules/inline-script-id.js +++ b/packages/eslint-plugin-next/lib/rules/inline-script-id.js @@ -8,6 +8,8 @@ module.exports = { recommended: true, url, }, + type: 'problem', + schema: [], }, create: function (context) { let nextScriptImportName = null diff --git a/packages/eslint-plugin-next/lib/rules/next-script-for-ga.js b/packages/eslint-plugin-next/lib/rules/next-script-for-ga.js index 260ab65c17d8..4dfd6bea6889 100644 --- a/packages/eslint-plugin-next/lib/rules/next-script-for-ga.js +++ b/packages/eslint-plugin-next/lib/rules/next-script-for-ga.js @@ -25,8 +25,9 @@ module.exports = { recommended: true, url, }, + type: 'problem', + schema: [], }, - schema: [], create: function (context) { return { JSXOpeningElement(node) { diff --git a/packages/eslint-plugin-next/lib/rules/no-assign-module-variable.js b/packages/eslint-plugin-next/lib/rules/no-assign-module-variable.js index b69153062ee9..459546741ca8 100644 --- a/packages/eslint-plugin-next/lib/rules/no-assign-module-variable.js +++ b/packages/eslint-plugin-next/lib/rules/no-assign-module-variable.js @@ -7,6 +7,8 @@ module.exports = { recommended: true, url, }, + type: 'problem', + schema: [], }, create: function (context) { diff --git a/packages/eslint-plugin-next/lib/rules/no-before-interactive-script-outside-document.js b/packages/eslint-plugin-next/lib/rules/no-before-interactive-script-outside-document.js index 075c61ed7356..9125fa0b2491 100644 --- a/packages/eslint-plugin-next/lib/rules/no-before-interactive-script-outside-document.js +++ b/packages/eslint-plugin-next/lib/rules/no-before-interactive-script-outside-document.js @@ -11,6 +11,8 @@ module.exports = { recommended: true, url, }, + type: 'problem', + schema: [], }, create: function (context) { let scriptImportName = null diff --git a/packages/eslint-plugin-next/lib/rules/no-css-tags.js b/packages/eslint-plugin-next/lib/rules/no-css-tags.js index 765555853019..520ae3a5f99d 100644 --- a/packages/eslint-plugin-next/lib/rules/no-css-tags.js +++ b/packages/eslint-plugin-next/lib/rules/no-css-tags.js @@ -7,8 +7,9 @@ module.exports = { recommended: true, url, }, + type: 'problem', + schema: [], }, - schema: [], create: function (context) { return { JSXOpeningElement(node) { diff --git a/packages/eslint-plugin-next/lib/rules/no-document-import-in-page.js b/packages/eslint-plugin-next/lib/rules/no-document-import-in-page.js index 76b46ed9dc1a..b801650e34e0 100644 --- a/packages/eslint-plugin-next/lib/rules/no-document-import-in-page.js +++ b/packages/eslint-plugin-next/lib/rules/no-document-import-in-page.js @@ -10,6 +10,8 @@ module.exports = { recommended: true, url, }, + type: 'problem', + schema: [], }, create: function (context) { return { diff --git a/packages/eslint-plugin-next/lib/rules/no-duplicate-head.js b/packages/eslint-plugin-next/lib/rules/no-duplicate-head.js index a8b052141129..8b574fd73492 100644 --- a/packages/eslint-plugin-next/lib/rules/no-duplicate-head.js +++ b/packages/eslint-plugin-next/lib/rules/no-duplicate-head.js @@ -8,6 +8,8 @@ module.exports = { recommended: true, url, }, + type: 'problem', + schema: [], }, create: function (context) { let documentImportName diff --git a/packages/eslint-plugin-next/lib/rules/no-head-element.js b/packages/eslint-plugin-next/lib/rules/no-head-element.js index 045e21a31131..42b44991c910 100644 --- a/packages/eslint-plugin-next/lib/rules/no-head-element.js +++ b/packages/eslint-plugin-next/lib/rules/no-head-element.js @@ -8,7 +8,8 @@ module.exports = { recommended: true, url, }, - fixable: 'code', + type: 'problem', + schema: [], }, create: function (context) { return { diff --git a/packages/eslint-plugin-next/lib/rules/no-head-import-in-document.js b/packages/eslint-plugin-next/lib/rules/no-head-import-in-document.js index 5a98ebd8497c..9a852f40558a 100644 --- a/packages/eslint-plugin-next/lib/rules/no-head-import-in-document.js +++ b/packages/eslint-plugin-next/lib/rules/no-head-import-in-document.js @@ -9,6 +9,8 @@ module.exports = { recommended: true, url, }, + type: 'problem', + schema: [], }, create: function (context) { return { diff --git a/packages/eslint-plugin-next/lib/rules/no-html-link-for-pages.js b/packages/eslint-plugin-next/lib/rules/no-html-link-for-pages.js index 967984492d1f..df4dfc58c0b7 100644 --- a/packages/eslint-plugin-next/lib/rules/no-html-link-for-pages.js +++ b/packages/eslint-plugin-next/lib/rules/no-html-link-for-pages.js @@ -30,7 +30,7 @@ module.exports = { recommended: true, url, }, - fixable: null, // or "code" or "whitespace" + type: 'problem', schema: [ { oneOf: [ diff --git a/packages/eslint-plugin-next/lib/rules/no-img-element.js b/packages/eslint-plugin-next/lib/rules/no-img-element.js index 588fb39aa62c..7d071ef86792 100644 --- a/packages/eslint-plugin-next/lib/rules/no-img-element.js +++ b/packages/eslint-plugin-next/lib/rules/no-img-element.js @@ -8,7 +8,8 @@ module.exports = { recommended: true, url, }, - fixable: 'code', + type: 'problem', + schema: [], }, create: function (context) { diff --git a/packages/eslint-plugin-next/lib/rules/no-page-custom-font.js b/packages/eslint-plugin-next/lib/rules/no-page-custom-font.js index 61ecf534d8f3..6bd5e7872aba 100644 --- a/packages/eslint-plugin-next/lib/rules/no-page-custom-font.js +++ b/packages/eslint-plugin-next/lib/rules/no-page-custom-font.js @@ -10,6 +10,8 @@ module.exports = { recommended: true, url, }, + type: 'problem', + schema: [], }, create: function (context) { const paths = context.getFilename().split('pages') diff --git a/packages/eslint-plugin-next/lib/rules/no-script-component-in-head.js b/packages/eslint-plugin-next/lib/rules/no-script-component-in-head.js index 82dc94b7bff3..379ef8e2d98c 100644 --- a/packages/eslint-plugin-next/lib/rules/no-script-component-in-head.js +++ b/packages/eslint-plugin-next/lib/rules/no-script-component-in-head.js @@ -8,6 +8,8 @@ module.exports = { recommended: true, url, }, + type: 'problem', + schema: [], }, create: function (context) { let isNextHead = null diff --git a/packages/eslint-plugin-next/lib/rules/no-styled-jsx-in-document.js b/packages/eslint-plugin-next/lib/rules/no-styled-jsx-in-document.js index 0b0efea0e0e0..342f93eb1a06 100644 --- a/packages/eslint-plugin-next/lib/rules/no-styled-jsx-in-document.js +++ b/packages/eslint-plugin-next/lib/rules/no-styled-jsx-in-document.js @@ -9,7 +9,8 @@ module.exports = { recommended: true, url, }, - fixable: 'code', + type: 'problem', + schema: [], }, create: function (context) { return { @@ -44,5 +45,3 @@ module.exports = { } }, } - -module.exports.schema = [] diff --git a/packages/eslint-plugin-next/lib/rules/no-sync-scripts.js b/packages/eslint-plugin-next/lib/rules/no-sync-scripts.js index 2025750b0256..335c429fa563 100644 --- a/packages/eslint-plugin-next/lib/rules/no-sync-scripts.js +++ b/packages/eslint-plugin-next/lib/rules/no-sync-scripts.js @@ -7,8 +7,9 @@ module.exports = { recommended: true, url, }, + type: 'problem', + schema: [], }, - schema: [], create: function (context) { return { JSXOpeningElement(node) { diff --git a/packages/eslint-plugin-next/lib/rules/no-title-in-document-head.js b/packages/eslint-plugin-next/lib/rules/no-title-in-document-head.js index 1bd3664dab76..5c6346ee84cc 100644 --- a/packages/eslint-plugin-next/lib/rules/no-title-in-document-head.js +++ b/packages/eslint-plugin-next/lib/rules/no-title-in-document-head.js @@ -8,6 +8,8 @@ module.exports = { recommended: true, url, }, + type: 'problem', + schema: [], }, create: function (context) { let headFromNextDocument = false diff --git a/packages/eslint-plugin-next/lib/rules/no-typos.js b/packages/eslint-plugin-next/lib/rules/no-typos.js index 22092912fcd5..09ca6f312899 100644 --- a/packages/eslint-plugin-next/lib/rules/no-typos.js +++ b/packages/eslint-plugin-next/lib/rules/no-typos.js @@ -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) { diff --git a/packages/eslint-plugin-next/lib/rules/no-unwanted-polyfillio.js b/packages/eslint-plugin-next/lib/rules/no-unwanted-polyfillio.js index f5751e0e2b6f..f874fba64266 100644 --- a/packages/eslint-plugin-next/lib/rules/no-unwanted-polyfillio.js +++ b/packages/eslint-plugin-next/lib/rules/no-unwanted-polyfillio.js @@ -72,7 +72,8 @@ module.exports = { recommended: true, url, }, - fixable: null, + type: 'problem', + schema: [], }, create: function (context) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f34119622c7f..133b246a474f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -89,6 +89,7 @@ importers: 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 @@ -243,6 +244,7 @@ importers: escape-string-regexp: 2.0.0 eslint: 7.24.0 eslint-config-next: link:packages/eslint-config-next + eslint-plugin-eslint-plugin: 4.3.0_eslint@7.24.0 eslint-plugin-import: 2.22.1_23iivq3ybsthf4qrv3kgatrvhe eslint-plugin-jest: 24.3.5_lqson4bxnnkvr5juyhnlzmz4rq eslint-plugin-react: 7.23.2_eslint@7.24.0 @@ -10326,6 +10328,17 @@ packages: - supports-color dev: true + /eslint-plugin-eslint-plugin/4.3.0_eslint@7.24.0: + resolution: {integrity: sha512-0xZ++ilIpGY+gBwsaW/uIhG/Rrl/sltPCai3UUPzWbaOPud2tel9UCWj8sLTADNmVqBD+vcqLHzHY86q/b71yg==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + eslint: '>=6.0.0' + dependencies: + eslint: 7.24.0 + eslint-utils: 3.0.0_eslint@7.24.0 + estraverse: 5.3.0 + dev: true + /eslint-plugin-import/2.22.1_23iivq3ybsthf4qrv3kgatrvhe: resolution: {integrity: sha512-8K7JjINHOpH64ozkAhpT3sd+FswIZTfMZTjdx052pnWrgRCVfp8op9tbjpAk3DdUeI/Ba4C8OjdC0r90erHEOw==} engines: {node: '>=4'}