Eslint, warn on prefer-const rule (#1719)

"This rule is aimed at flagging variables that are declared using let
keyword, but never reassigned after the initial assignment."
https://eslint.org/docs/rules/prefer-const

This is a rule that helps you spot mistakes while writing code with a
let statement. When thinking that you will need to reassign it, eslint
will point out you're not actually doing so.

This could be because you've forgotten something, assigned the wrong
variable, or no longer need to reassign.
This commit is contained in:
Robin van Boven 2020-04-03 15:44:27 +02:00 committed by GitHub
parent c755216ebd
commit f2403ce33f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 7 additions and 6 deletions

View File

@ -21,6 +21,7 @@ module.exports = {
"plugin:flowtype/recommended", "plugin:flowtype/recommended",
], ],
rules: { rules: {
"prefer-const": ["warn"],
camelcase: ["error", {properties: "never", allow: ["^_unused_.*"]}], camelcase: ["error", {properties: "never", allow: ["^_unused_.*"]}],
eqeqeq: ["error", "always", {null: "ignore"}], eqeqeq: ["error", "always", {null: "ignore"}],
"no-unused-vars": [ "no-unused-vars": [

View File

@ -203,7 +203,7 @@ export function findStationaryDistribution(
params: PagerankParams, params: PagerankParams,
options: PagerankOptions options: PagerankOptions
): Promise<StationaryDistributionResult> { ): Promise<StationaryDistributionResult> {
let gen = findStationaryDistributionGenerator(params, { const gen = findStationaryDistributionGenerator(params, {
verbose: options.verbose, verbose: options.verbose,
convergenceThreshold: options.convergenceThreshold, convergenceThreshold: options.convergenceThreshold,
maxIterations: options.maxIterations, maxIterations: options.maxIterations,

View File

@ -84,7 +84,7 @@ describe("explorer/legacy/pagerankTable/Table", () => {
const {element} = await setup(); const {element} = await setup();
findButton(element).simulate("click"); findButton(element).simulate("click");
findButton(element).simulate("click"); findButton(element).simulate("click");
let button = findButton(element); const button = findButton(element);
expect(button.text()).toEqual("Show weight configuration"); expect(button.text()).toEqual("Show weight configuration");
expect(element.find({"data-test-weight-config": true})).toHaveLength(0); expect(element.find({"data-test-weight-config": true})).toHaveLength(0);
}); });

View File

@ -75,7 +75,7 @@ function lengthDecode(
} }
function multiLengthDecode(x: $ReadOnlyArray<string>, fail: () => Error) { function multiLengthDecode(x: $ReadOnlyArray<string>, fail: () => Error) {
let remaining = x; let remaining = x;
let partses = []; const partses = [];
while (remaining.length > 0) { while (remaining.length > 0) {
const {parts, rest} = lengthDecode(remaining, fail); const {parts, rest} = lengthDecode(remaining, fail);
partses.push(parts); partses.push(parts);

View File

@ -177,7 +177,7 @@ function lengthDecode(
} }
function multiLengthDecode(x: $ReadOnlyArray<string>, fail: () => Error) { function multiLengthDecode(x: $ReadOnlyArray<string>, fail: () => Error) {
let remaining = x; let remaining = x;
let partses = []; const partses = [];
while (remaining.length > 0) { while (remaining.length > 0) {
const {parts, rest} = lengthDecode(remaining, fail); const {parts, rest} = lengthDecode(remaining, fail);
partses.push(parts); partses.push(parts);

View File

@ -299,7 +299,7 @@ describe("plugins/github/relationalView", () => {
} }
function commitChain(n: number): T.Commit[] { function commitChain(n: number): T.Commit[] {
let head = wrapCommit(0, []); let head = wrapCommit(0, []);
let results = [head]; const results = [head];
for (let i = 1; i < n; i++) { for (let i = 1; i < n; i++) {
head = wrapCommit(i, [head]); head = wrapCommit(i, [head]);
results.push(head); results.push(head);
@ -307,7 +307,7 @@ describe("plugins/github/relationalView", () => {
return results; return results;
} }
const commits = commitChain(COMMIT_CHAIN_LENGTH); const commits = commitChain(COMMIT_CHAIN_LENGTH);
let pullRequests: T.PullRequest[] = []; const pullRequests: T.PullRequest[] = [];
function pullRequest( function pullRequest(
prNumber: number, prNumber: number,
mergeCommit: T.Commit mergeCommit: T.Commit