目录

@typescript-eslint/no-magic-numbers

Disallow magic numbers.

Magic numbers are numbers that occur multiple times in code without an explicit meaning. They should preferably be replaced by named constants.

Rule Configuration

// code-linter.json5
{
  "rules": {
    "@typescript-eslint/no-magic-numbers": "warn"
  }
}

Options

For details, see @typescript-eslint/no-magic-numbers.

Example of Correct Code

const TAX = 0.25;
const dutyFreePrice = 100;
export const finalPrice = dutyFreePrice + dutyFreePrice * TAX;

Example of Incorrect Code

export const finalPrice = 100 + 100 * 0.25;

const data = ['foo', 'bar', 'baz'];
export const dataLast = data[2];

Rule Set

plugin:@typescript-eslint/all

For details about how to configure Code Linter check rules, see Code Linter.