Skip to content

Commit

Permalink
fix: improve eslint rule detecting (#457)
Browse files Browse the repository at this point in the history
fixes #455
  • Loading branch information
aladdin-add committed Apr 8, 2024
1 parent 3d12851 commit 5dccb61
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
20 changes: 8 additions & 12 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
const { getStaticValue, findVariable } = require('eslint-utils');
const estraverse = require('estraverse');

const functionTypes = new Set([
'FunctionExpression',
'ArrowFunctionExpression',
'FunctionDeclaration',
]);

/**
* Determines whether a node is a 'normal' (i.e. non-async, non-generator) function expression.
* @param {ASTNode} node The node in question
* @returns {boolean} `true` if the node is a normal function expression
*/
function isNormalFunctionExpression(node) {
const functionTypes = [
'FunctionExpression',
'ArrowFunctionExpression',
'FunctionDeclaration',
];
return functionTypes.includes(node.type) && !node.generator && !node.async;
return functionTypes.has(node.type) && !node.generator && !node.async;
}

/**
Expand Down Expand Up @@ -150,12 +151,7 @@ function getRuleExportsESM(ast, scopeManager) {
// 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'
)
...nodes.filter((node) => node && !functionTypes.has(node.type))
);
}
break;
Expand Down
1 change: 1 addition & 0 deletions tests/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ describe('utils', () => {
'export function foo(options) { return {}; }',
'export async function foo(options) { return {}; }',
'export const foo = function (options) { return {}; }',
'export const foo = (options) => { return {}; }',
'export function foo(options) { return; }',
'export function foo({opt1, opt2}) { return {}; }',

Expand Down

0 comments on commit 5dccb61

Please sign in to comment.