eslint/rules/functions
Functions: Declarations, parameters, return values and callbacks: consistent, small and predictable functions. Rules of ESLint, typescript-eslint and SonarJS (the Sonar way profile of SonarQube) on this subject, every rule listed; the TypeScript rules apply to TypeScript files only.
46 rules, 25 on. Source: lint/eslint/rules/functions.mjs.
| Rule | Setting | Files | What it checks | Why |
|---|---|---|---|---|
no-func-assign | error | JS + TS | Disallow reassigning function declarations | — |
no-obj-calls | error | JS + TS | Disallow calling global object properties as functions | — |
arrow-body-style | off | JS + TS | Require braces around arrow function bodies | Off: breaks the prettier/prettier autofix (eslint-plugin-prettier docs). |
consistent-return | off | JS + TS | Require return statements to either always or never specify values | Off: TypeScript noImplicitReturns covers it. |
default-param-last | info | JS + TS | Enforce default parameters to be last | Replaced by the TS version. |
func-style | info, ["declaration",{"allowArrowFunctions":false}] | JS + TS | Enforce the consistent use of either function declarations or expressions assigned to variables | Custom: named functions use function foo(), not const foo = () =>. |
max-lines-per-function | off | JS + TS | Enforce a maximum number of lines of code in a function | Off: replaced by sonarjs/max-lines-per-function, like SonarQube. |
max-nested-callbacks | off | JS + TS | Enforce a maximum depth that callbacks can be nested | Off: replaced by sonarjs/no-nested-functions, like SonarQube. |
max-params | warn, {"max":7,"countThis":"never"} | JS + TS | Enforce a maximum number of parameters in function definitions | 7 = SonarQube default (S107). Warn: a size limit: a justified exception (a data table, a state machine) may pass. |
no-caller | error | JS + TS | Disallow the use of arguments.caller or arguments.callee | — |
no-empty-function | warn | JS + TS | Disallow empty functions | Replaced by the TS version. |
no-extra-bind | error | JS + TS | Disallow unnecessary calls to .bind() | — |
no-param-reassign | warn, {"props":true} | JS + TS | Disallow reassigning function parameters | Custom: parameters' properties cannot be mutated either; libraries must expose methods instead. |
no-return-assign | warn, "always" | JS + TS | Disallow assignment operators in return statements | No assignment in return, even in parentheses. |
no-useless-call | info | JS + TS | Disallow unnecessary calls to .call() and .apply() | — |
no-useless-return | off | JS + TS | Disallow redundant return statements | Off: replaced by sonarjs/no-redundant-jump, like SonarQube. |
prefer-arrow-callback | off | JS + TS | Require using arrow functions for callbacks | Off: breaks the prettier/prettier autofix (eslint-plugin-prettier docs). |
prefer-rest-params | info | JS + TS | Require rest parameters instead of arguments | — |
sonarjs/max-lines-per-function | warn, {"maximum":60} | JS + TS | Functions should not have too many lines of code | Custom: outside Sonar way; replaces the core max-lines-per-function, like SonarQube. Warn: a size limit: a justified exception (a data table, a state machine) may pass. |
sonarjs/bool-param-default | off | JS + TS | Optional boolean parameters should have default value | Off: not in the Sonar way profile of SonarQube. |
sonarjs/prefer-immediate-return | off | JS + TS | Local variables should not be declared and then immediately returned or thrown | Off: not in the Sonar way profile of SonarQube. |
sonarjs/no-extra-arguments | off | JS + TS | Function calls should not pass extra arguments | Off: already a TypeScript compiler error. |
sonarjs/no-parameter-reassignment | off | JS + TS | Initial values of parameters, caught exceptions, and loop variables should not be ignored | Off: duplicate of no-param-reassign. |
sonarjs/no-use-of-empty-return-value | off | JS + TS | The return value of void functions should not be used | Off: duplicate of @typescript-eslint/no-confusing-void-expression. |
sonarjs/arrow-function-convention | off | JS + TS | Braces and parentheses should be used consistently with arrow functions | Off: not in the Sonar way profile of SonarQube. |
sonarjs/call-argument-line | warn | JS + TS | Function call arguments should not start on new lines | — |
sonarjs/inconsistent-function-call | warn | JS + TS | Functions should be called consistently with or without "new" | — |
sonarjs/no-function-declaration-in-block | off | JS + TS | Function declarations should not be made within blocks | Off: not in the Sonar way profile of SonarQube. |
sonarjs/no-identical-functions | warn | JS + TS | Functions should not have identical implementations | — |
sonarjs/no-ignored-return | error | JS + TS | Return values from functions without side effects should not be ignored | — |
sonarjs/no-inconsistent-returns | off | JS + TS | Functions should use "return" consistently | Off: not in the Sonar way profile of SonarQube. |
sonarjs/no-invariant-returns | warn | JS + TS | Function returns should not be invariant | — |
sonarjs/no-literal-call | error | JS + TS | Literals should not be used as functions | — |
sonarjs/no-nested-functions | warn | JS + TS | Functions should not be nested too deeply | Sonar way; replaces the core max-nested-callbacks, like SonarQube. Warn: a size limit: a justified exception (a data table, a state machine) may pass. |
sonarjs/no-selector-parameter | warn | JS + TS | Methods should not contain selector parameters | — |
sonarjs/no-unused-function-argument | off | JS + TS | Unused function parameters should be removed | Off: not in the Sonar way profile of SonarQube. |
no-func-assign | off | TS | Disallow reassigning function declarations | — |
no-obj-calls | off | TS | Disallow calling global object properties as functions | — |
@typescript-eslint/consistent-return | off | TS | Require return statements to either always or never specify values | Off: TypeScript noImplicitReturns covers it. |
default-param-last | off | TS | Enforce default parameters to be last | Replaced by the TS version. |
@typescript-eslint/default-param-last | info | TS | Enforce default parameters to be last | — |
max-params | off | TS | Enforce a maximum number of parameters in function definitions | 7 = SonarQube default (S107). Warn: a size limit: a justified exception (a data table, a state machine) may pass. |
@typescript-eslint/max-params | warn, {"max":7} | TS | Enforce a maximum number of parameters in function definitions | 7 = SonarQube default (S107). Warn: a size limit: a justified exception (a data table, a state machine) may pass. |
no-empty-function | off | TS | Disallow empty functions | Replaced by the TS version. |
@typescript-eslint/no-empty-function | warn | TS | Disallow empty functions | — |
@typescript-eslint/no-unnecessary-parameter-property-assignment | info | TS | Disallow unnecessary assignment of constructor property parameter | — |