diff --git a/lib/utils.js b/lib/utils.js index ae708f80..c1be12c2 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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; } /** @@ -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; diff --git a/tests/lib/utils.js b/tests/lib/utils.js index 0e8c83ea..eaf7a285 100644 --- a/tests/lib/utils.js +++ b/tests/lib/utils.js @@ -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 {}; }',