func-style
UnreleasedConfiguration
Rule Details
There are two ways of defining functions in JavaScript: function declarations and function expressions assigned to variables. Function expressions can either be arrow functions or use the function keyword with an optional name.
The primary difference between function declarations and function expressions is that declarations are hoisted to the top of the scope in which they are defined, which allows using the function before its declaration; a function expression must be defined before it is used.
This rule enforces a particular type of function style, either function declarations or expressions assigned to variables.
This rule does not apply to all functions. A callback function passed as an argument to another function, or a method assigned to an object, is not checked by this rule.
Examples of incorrect code for this rule with the default "expression" option:
Examples of correct code for this rule with the default "expression" option:
Overloaded function declarations (multiple declarations of the same name with different parameter or return types) are never reported by this rule, regardless of the configured style:
Examples of incorrect code for this rule with the "declaration" option:
Examples of correct code for this rule with the "declaration" option:
Options
This rule has a string option:
"expression"(default) requires the use of function expressions instead of function declarations"declaration"requires the use of function declarations instead of function expressions
This rule has an object option:
"allowArrowFunctions":true(defaultfalse) allows the use of arrow functions when the string option is"declaration". Arrow functions are always allowed when the string option is"expression", regardless of this option."allowTypeAnnotation":true(defaultfalse) allows a function expression or arrow function whose variable declaration has a type annotation, regardless ofallowArrowFunctions. This option applies only when the string option is"declaration"."overrides":"namedExports":"expression" | "declaration" | "ignore"overrides the function style required for named exports."ignore"accepts either style.
allowArrowFunctions
Examples of additional correct code for this rule with { "allowArrowFunctions": true }:
allowTypeAnnotation
Examples of incorrect code for this rule with { "allowTypeAnnotation": true }:
Examples of correct code for this rule with { "allowTypeAnnotation": true }:
overrides.namedExports
Examples of incorrect code for this rule with { "overrides": { "namedExports": "expression" } }:
Examples of correct code for this rule with { "overrides": { "namedExports": "expression" } }:
Examples of incorrect code for this rule with { "overrides": { "namedExports": "declaration" } }:
Examples of correct code for this rule with { "overrides": { "namedExports": "declaration" } }:
Examples of correct code for this rule with { "overrides": { "namedExports": "ignore" } }: