From 598572b09b1f12ca8a639eaa0bb6e608b5ce1a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 18 Mar 2024 12:04:06 +0800 Subject: [PATCH 1/5] fix: false positives in 5.4.0 for functions that aren't ESLint rules fixes #450 --- lib/utils.js | 29 ++++++++++++++++++++--------- tests/lib/utils.js | 8 ++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index da5faa74..414d3d05 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -139,15 +139,26 @@ function getRuleExportsESM(ast, scopeManager) { possibleNodes.push(specifier.local); } if (statement.declaration) { - if (statement.declaration.type === 'VariableDeclaration') { - for (const declarator of statement.declaration.declarations) { - if (declarator.init) { - possibleNodes.push(declarator.init); - } - } - } else { - possibleNodes.push(statement.declaration); - } + let nodes = []; + + nodes = + statement.declaration.type === 'VariableDeclaration' + ? statement.declaration.declarations.map( + (declarator) => declarator.init + ) + : [statement.declaration]; + + // named exports like `export const rule = { ... };` + // skip if it's function-style to avoid false positives + // refs: https://github.com/eslint-community/eslint-plugin-eslint-plugin/issues/450 + possibleNodes.push( + ...nodes.filter( + (node) => + node && + node.type !== 'FunctionDeclaration' && + node.type !== 'FunctionExpression' + ) + ); } break; } diff --git a/tests/lib/utils.js b/tests/lib/utils.js index e90ecd6e..0e8c83ea 100644 --- a/tests/lib/utils.js +++ b/tests/lib/utils.js @@ -86,6 +86,14 @@ describe('utils', () => { 'export default function () { return {}; }', 'export default function (foo, bar) { return {}; }', + // named export of functions + // refs: https://github.com/eslint-community/eslint-plugin-eslint-plugin/issues/450 + 'export function foo(options) { return {}; }', + 'export async function foo(options) { return {}; }', + 'export const foo = function (options) { return {}; }', + 'export function foo(options) { return; }', + 'export function foo({opt1, opt2}) { return {}; }', + // Incorrect TypeScript helper structure: 'export default foo()({ create() {}, meta: {} });', 'export default foo().bar({ create() {}, meta: {} });', From 76d12455ff9b44a9acc4791e668f0c4763ff1df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 18 Mar 2024 12:50:21 +0800 Subject: [PATCH 2/5] fix: ignore fixtures --- eslint-remote-tester.config.js | 3 ++- package.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/eslint-remote-tester.config.js b/eslint-remote-tester.config.js index f9d44f69..b5faf57d 100644 --- a/eslint-remote-tester.config.js +++ b/eslint-remote-tester.config.js @@ -43,8 +43,9 @@ module.exports = { /** ESLint configuration */ eslintrc: { + root: true, extends: ['plugin:eslint-plugin/all'], - + ignorePatterns: ['fixtures/**/*'], overrides: [ { files: ['*.ts', '*.mts', '*.cts'], diff --git a/package.json b/package.json index 792a8c97..88476267 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "eslint-plugin-n": "^16.6.2", "eslint-plugin-prettier": "^4.2.1", "eslint-plugin-unicorn": "^46.0.0", - "eslint-remote-tester": "^3.0.0", + "eslint-remote-tester": "^3.0.1", "eslint-scope": "^7.1.1", "espree": "^9.4.0", "globals": "^13.20.0", From fcb5d4bdedbf8e1b2f14bc76991d4a746f89b110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 18 Mar 2024 12:53:11 +0800 Subject: [PATCH 3/5] fix: use pathIgnorePattern --- eslint-remote-tester.config.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eslint-remote-tester.config.js b/eslint-remote-tester.config.js index b5faf57d..daf06010 100644 --- a/eslint-remote-tester.config.js +++ b/eslint-remote-tester.config.js @@ -41,11 +41,13 @@ module.exports = { /** Optional boolean flag used to enable caching of cloned repositories. For CIs it's ideal to disable caching. Defaults to true. */ cache: false, + pathIgnorePattern: 'fixtures', + /** ESLint configuration */ eslintrc: { root: true, extends: ['plugin:eslint-plugin/all'], - ignorePatterns: ['fixtures/**/*'], + // ignorePatterns: ['fixtures/**/*'], // not working somehow - using `pathIgnorePattern` as of now. overrides: [ { files: ['*.ts', '*.mts', '*.cts'], From a7ccefd20ca5bd72d23ad924c585a45bb7fb62df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 18 Mar 2024 12:56:02 +0800 Subject: [PATCH 4/5] chore: upgrade eslint-doc-generator --- README.md | 4 ++-- docs/rules/no-only-tests.md | 2 +- docs/rules/no-property-in-node.md | 2 +- docs/rules/require-meta-schema.md | 2 +- package.json | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2e95af12..908c2ad4 100644 --- a/README.md +++ b/README.md @@ -79,8 +79,8 @@ module.exports = [ 💼 [Configurations](https://github.com/eslint-community/eslint-plugin-eslint-plugin#presets) enabled in.\ ✅ Set in the `recommended` [configuration](https://github.com/eslint-community/eslint-plugin-eslint-plugin#presets).\ 🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\ -💡 Manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).\ -💭 Requires type information. +💡 Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).\ +💭 Requires [type information](https://typescript-eslint.io/linting/typed-linting). ### Rules diff --git a/docs/rules/no-only-tests.md b/docs/rules/no-only-tests.md index d5db7dd0..3e8828c1 100644 --- a/docs/rules/no-only-tests.md +++ b/docs/rules/no-only-tests.md @@ -2,7 +2,7 @@ 💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-eslint-plugin#presets). -💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). +💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions). diff --git a/docs/rules/no-property-in-node.md b/docs/rules/no-property-in-node.md index 22da26dd..1a44c31c 100644 --- a/docs/rules/no-property-in-node.md +++ b/docs/rules/no-property-in-node.md @@ -1,6 +1,6 @@ # Disallow using `in` to narrow node types instead of looking at properties (`eslint-plugin/no-property-in-node`) -💭 This rule requires type information. +💭 This rule requires [type information](https://typescript-eslint.io/linting/typed-linting). diff --git a/docs/rules/require-meta-schema.md b/docs/rules/require-meta-schema.md index de1b6825..c479d257 100644 --- a/docs/rules/require-meta-schema.md +++ b/docs/rules/require-meta-schema.md @@ -2,7 +2,7 @@ 💼 This rule is enabled in the ✅ `recommended` [config](https://github.com/eslint-community/eslint-plugin-eslint-plugin#presets). -💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). +💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions). diff --git a/package.json b/package.json index 88476267..51511b35 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "eslint": "^8.23.0", "eslint-config-not-an-aardvark": "^2.1.0", "eslint-config-prettier": "^8.5.0", - "eslint-doc-generator": "^1.6.1", + "eslint-doc-generator": "^1.7.0", "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-eslint-plugin": "file:./", "eslint-plugin-markdown": "^3.0.0", From badaa662dcac73f32ac7194f733a37a6bfcd3a78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 18 Mar 2024 13:01:18 +0800 Subject: [PATCH 5/5] refactor: nodes decl --- lib/utils.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 414d3d05..ae708f80 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -139,9 +139,7 @@ function getRuleExportsESM(ast, scopeManager) { possibleNodes.push(specifier.local); } if (statement.declaration) { - let nodes = []; - - nodes = + const nodes = statement.declaration.type === 'VariableDeclaration' ? statement.declaration.declarations.map( (declarator) => declarator.init