refactor: replace ignored numeric literals with constants
This commit is contained in:
@@ -45,3 +45,19 @@ test('focused tests are rejected and generated code is excluded', async () => {
|
||||
assert.ok(await eslint.isPathIgnored('generated/prisma/client.ts'));
|
||||
assert.ok(await eslint.isPathIgnored('dist/src/main.js'));
|
||||
});
|
||||
|
||||
test('numeric literals require names, including previously ignored numbers and bigints', async () => {
|
||||
const literals = [-60, -24, -10, -2, -1, 0, 1, 2, 10, 24, 60].map(String);
|
||||
for (const literal of [...literals, ...literals.map((value) => `${value}n`)]) {
|
||||
const [inline] = await eslint.lintText(
|
||||
`export function value() { return ${literal}; }`,
|
||||
{ filePath: 'src/main.ts' },
|
||||
);
|
||||
assert.ok(inline.messages.some(({ ruleId }) => ruleId === '@typescript-eslint/no-magic-numbers'), literal);
|
||||
const [named] = await eslint.lintText(
|
||||
`const boundary = ${literal}; export function value() { return boundary; }`,
|
||||
{ filePath: 'src/main.ts' },
|
||||
);
|
||||
assert.ok(!named.messages.some(({ ruleId }) => ruleId === '@typescript-eslint/no-magic-numbers'), literal);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user