Skip to content

Commit

Permalink
fix: improve eslint rule detecting
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 408f59a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
const { getStaticValue, findVariable } = require('eslint-utils');
const estraverse = require('estraverse');

const functionTypes = [

Check failure on line 6 in lib/utils.js

View workflow job for this annotation

GitHub Actions / lint

`functionTypes` should be a `Set`, and use `functionTypes.has()` to check existence or non-existence

Check failure on line 6 in lib/utils.js

View workflow job for this annotation

GitHub Actions / lint

`functionTypes` should be a `Set`, and use `functionTypes.has()` to check existence or non-existence
'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;
}

Expand Down Expand Up @@ -152,9 +153,7 @@ function getRuleExportsESM(ast, scopeManager) {
possibleNodes.push(
...nodes.filter(
(node) =>

Check failure on line 155 in lib/utils.js

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎···············`

Check failure on line 155 in lib/utils.js

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎···············`
node &&
node.type !== 'FunctionDeclaration' &&
node.type !== 'FunctionExpression'
node && !functionTypes.includes(node.type)
)
);
}
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 408f59a

Please sign in to comment.