Skip to content

Commit 598572b

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

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

lib/utils.js

+20-9
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,26 @@ function getRuleExportsESM(ast, scopeManager) {
139139
possibleNodes.push(specifier.local);
140140
}
141141
if (statement.declaration) {
142-
if (statement.declaration.type === 'VariableDeclaration') {
143-
for (const declarator of statement.declaration.declarations) {
144-
if (declarator.init) {
145-
possibleNodes.push(declarator.init);
146-
}
147-
}
148-
} else {
149-
possibleNodes.push(statement.declaration);
150-
}
142+
let nodes = [];
143+
144+
nodes =
145+
statement.declaration.type === 'VariableDeclaration'
146+
? statement.declaration.declarations.map(
147+
(declarator) => declarator.init
148+
)
149+
: [statement.declaration];
150+
151+
// named exports like `export const rule = { ... };`
152+
// skip if it's function-style to avoid false positives
153+
// refs: https://github.com/eslint-community/eslint-plugin-eslint-plugin/issues/450
154+
possibleNodes.push(
155+
...nodes.filter(
156+
(node) =>
157+
node &&
158+
node.type !== 'FunctionDeclaration' &&
159+
node.type !== 'FunctionExpression'
160+
)
161+
);
151162
}
152163
break;
153164
}

tests/lib/utils.js

+8
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ 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 async function foo(options) { return {}; }',
93+
'export const foo = function (options) { return {}; }',
94+
'export function foo(options) { return; }',
95+
'export function foo({opt1, opt2}) { return {}; }',
96+
8997
// Incorrect TypeScript helper structure:
9098
'export default foo()({ create() {}, meta: {} });',
9199
'export default foo().bar({ create() {}, meta: {} });',

0 commit comments

Comments
 (0)