💼🚫 This rule is enabled in the following configs: noStatements
, ✅ recommended
, 🔒 strict
. This rule is disabled in the following configs: disableTypeChecked
, ☑️ lite
.
💭 This rule requires type information.
This rule checks that the value of an expression is assigned to a variable and thus helps promote side-effect free (pure) functions.
When you call a function and don’t use it’s return value, chances are high that it is being called for its side effect. e.g.
/* eslint functional/no-expression-statements: "error" */
console.log("Hello world!");
/* eslint functional/no-expression-statements: "error" */
array.push(3);
/* eslint functional/no-expression-statements: "error" */
foo(bar);
/* eslint functional/no-expression-statements: "error" */
const baz = foo(bar);
/* eslint functional/no-expression-statements: ["error", { "ignoreVoid": true }] */
console.log("hello world");
This rule accepts an options object of the following type:
type Options = {
ignoreCodePattern?: string[] | string;
ignoreVoid?: boolean;
ignoreSelfReturning?: boolean;
};
const defaults = {
ignoreVoid: false,
ignoreSelfReturning: false,
};
When enabled, expression of type void
and Promise<void>
are not flagged as violations.
This options requires TypeScript in order to work.
Like ignoreVoid
but instead does not flag function calls that always only return this
.
Limitation: The function declaration must explicitly use return this
; equivalents
(such as assign this to a variable first, that is then returned) won't be considered valid.
This option takes a RegExp string or an array of RegExp strings. It allows for the ability to ignore violations based on the code itself.