diff --git a/.changeset/no-default-exported-function.md b/.changeset/no-default-exported-function.md new file mode 100644 index 0000000..49876af --- /dev/null +++ b/.changeset/no-default-exported-function.md @@ -0,0 +1,7 @@ +--- +"@gaia-react/lint": patch +--- + +Close `prefer-arrow-functions` upstream gap for `export default function NamedFn(){}` via `no-restricted-syntax` selector. + +The `eslint-plugin-prefer-arrow-functions` plugin has a hardcoded exemption (`guard.js:hasNameAndIsExportedAsDefaultExport`) that silently passes named default-exported declarations regardless of `allowNamedFunctions` setting. This release adds a `no-restricted-syntax` rule with selector `ExportDefaultDeclaration > FunctionDeclaration` to flag the pattern. Convert to `const Name = () => {}; export default Name;` instead. Ignored on `**/*.d.ts` since ambient declarations have no body to convert. diff --git a/src/configs/base.ts b/src/configs/base.ts index 5fc3578..2616709 100644 --- a/src/configs/base.ts +++ b/src/configs/base.ts @@ -257,6 +257,26 @@ const preferArrowFunctionsConfig: Linter.Config[] = [ 'prefer-arrow-functions/prefer-arrow-functions': 'error', }, }, + { + // `prefer-arrow-functions` has a hardcoded exemption for named + // default-exported declarations (`guard.js:hasNameAndIsExportedAsDefaultExport`), + // so `export default function Foo() {}` slips through. This selector closes + // that gap. Convert to `const Foo = () => {}; export default Foo;` instead. + // `.d.ts` is ignored because ambient `export default function …(): T;` + // declarations have no body to convert. + ignores: ['**/*.d.ts'], + name: 'prefer-arrow/no-default-exported-function', + rules: { + 'no-restricted-syntax': [ + 'error', + { + message: + 'Use `const Name = () => {}; export default Name;` instead. The prefer-arrow-functions plugin exempts named default-exported declarations upstream.', + selector: 'ExportDefaultDeclaration > FunctionDeclaration', + }, + ], + }, + }, { files: ['**/*.d.ts'], name: 'ts-definition-files/prefer-arrow-off',