Skip to content

Commit 36f511c

Browse files
committed
fix: false positives in 5.4.0 for functions that aren't ESLint rules
fixes #450
1 parent 8a6f148 commit 36f511c

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lib/utils.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,18 @@ function getRuleExportsESM(ast, scopeManager) {
139139
possibleNodes.push(specifier.local);
140140
}
141141
if (statement.declaration) {
142+
let nodes = []
143+
142144
if (statement.declaration.type === 'VariableDeclaration') {
143-
for (const declarator of statement.declaration.declarations) {
144-
if (declarator.init) {
145-
possibleNodes.push(declarator.init);
146-
}
147-
}
145+
nodes = statement.declaration.declarations.map((declarator) => declarator.init);
148146
} else {
149-
possibleNodes.push(statement.declaration);
147+
nodes = [statement.declaration];
150148
}
149+
150+
// named exports like `export const rule = { ... };`
151+
// skip if it's function-style rule to avoid false positives
152+
// refs: https://github.com/eslint-community/eslint-plugin-eslint-plugin/issues/450
153+
possibleNodes.push(...nodes.filter((node) => node && node.type !== 'FunctionDeclaration'));
151154
}
152155
break;
153156
}

tests/lib/utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ describe('utils', () => {
8686
'export default function () { return {}; }',
8787
'export default function (foo, bar) { return {}; }',
8888

89+
// named export of functions
90+
// refs: https://github.com/eslint-community/eslint-plugin-eslint-plugin/issues/450
91+
'export function foo(options) { return {}; }',
92+
'export function foo(options) { return; }',
93+
'export function foo({opt1, opt2}) { return {}; }',
94+
8995
// Incorrect TypeScript helper structure:
9096
'export default foo()({ create() {}, meta: {} });',
9197
'export default foo().bar({ create() {}, meta: {} });',

0 commit comments

Comments
 (0)