💼 This rule is enabled in the following configs: ☑️ lite
, noMutations
, ✅ recommended
, 🔒 strict
.
This rule should be combined with ESLint's built-in no-var
rule to enforce that all variables are declared as const
.
In functional programming variables should not be mutable; use const
instead.
/* eslint functional/no-let: "error" */
let x = 5;
/* eslint functional/no-let: "error" */
for (let i = 0; i < array.length; i++) {}
/* eslint functional/no-let: "error" */
const x = 5;
/* eslint functional/no-let: "error" */
for (const element of array) {
}
/* eslint functional/no-let: "error" */
for (const [index, element] of array.entries()) {
}
This rule accepts an options object of the following type:
type Options = {
allowInFunctions: boolean;
ignoreIdentifierPattern?: string[] | string;
};
const defaults = {
allowInForLoopInit: false,
allowInFunctions: false,
};
const recommendedAndLiteOptions = {
allowInForLoopInit: true,
};
If set, let
s inside of for a loop initializer are allowed. This does not include for...of or for...in loops as they
should use const
instead.
/* eslint functional/no-let: ["error", { "allowInForLoopInit": true } ] */
for (let element of array) {
}
/* eslint functional/no-let: ["error", { "allowInForLoopInit": true } ] */
for (let [index, element] of array.entries()) {
}
/* eslint functional/no-let: ["error", { "allowInForLoopInit": true } ] */
for (let i = 0; i < array.length; i++) {}
If true, the rule will not flag any statements that are inside of function bodies.
This option takes a RegExp string or an array of RegExp strings. It allows for the ability to ignore violations based on a variable's name.