Repository navigation
📎 Feature: Extend useArrowFunction rule to cover top-level function declarations #7108
Closed
schickling
started this conversation in
Rule suggestion
Replies: 2 comments
|
Hello. almost 1 year, any progress on this? |
0 replies
|
https://biomejs.dev/linter/rules/use-consistent-function-style/javascript/ was added in 2.5.14 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Summary
Request to extend the existing
useArrowFunctionrule to optionally enforce arrow functions for top-level function declarations, not just function expressions.Problem
Currently, the
useArrowFunctionrule only applies to function expressions:For teams that prefer consistent arrow function usage throughout their codebase, there's no way to enforce arrow functions for top-level function declarations.
Proposed Solution
Add a configuration option to the
useArrowFunctionrule to optionally include top-level function declarations:{ "linter": { "rules": { "complexity": { "useArrowFunction": { "level": "error", "options": { "includeTopLevelDeclarations": true } } } } } }With this configuration, the rule would flag:
ESLint Precedent
ESLint ecosystem has plugins that support similar functionality:
1.
eslint-plugin-prefer-arrowThis plugin enforces arrow functions and has an option to control top-level declarations:
{ "rules": { "prefer-arrow/prefer-arrow-functions": [ "error", { "allowStandaloneDeclarations": false, // Default: flags top-level function declarations "disallowPrototype": true, "singleReturnOnly": false, "classPropertiesAllowed": false } ] } }allowStandaloneDeclarationsisfalse(default), the plugin flags ALL function declarations including top-level onesallowStandaloneDeclarationsistrue, it ignores top-level function declarations but still flags nested ones2.
func-stylerule combined withprefer-arrow-callback{ "rules": { "func-style": ["error", "expression", { "allowArrowFunctions": true }], "prefer-arrow-callback": ["error"] } }The
func-stylerule enforces function expressions over declarations, and when combined withallowArrowFunctions: true, it permits arrow functions as the preferred expression style.Benefits
Considerations
this)Alternative
If extending the existing rule is not preferred, a new rule like
useArrowFunctionDeclarationscould be introduced instead.All reactions