Skip to content

Commit 0125516

Browse files
authored
Merge pull request #78 from Angular-RU/feature/add-numeric-ignore
add numeric ignore
2 parents aec4827 + dc680f0 commit 0125516

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ module.exports = {
4444
'no-return-assign': ['error', 'always'],
4545
'max-params': ['error', 3],
4646
'no-nested-ternary': 'error',
47-
'no-magic-numbers': ['error', { ignore: [-1, 0, 1] }],
47+
"no-magic-numbers": "off",
48+
"@typescript-eslint/no-magic-numbers": [
49+
"error",
50+
{
51+
ignoreEnums: true,
52+
ignoreNumericLiteralTypes: true,
53+
ignoreReadonlyClassProperties: true
54+
}],
4855
'sort-imports': 'off',
4956
'prettier/prettier': 'error',
5057
'import/first': 'error',

test/test.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('[TEST]: Eslint', (): void => {
1313
expect(bad.includes("expected member-variable-declaration: 'hello' to have a typedef")).toEqual(true);
1414
expect(bad.includes('Missing accessibility modifier on class property hello')).toEqual(true);
1515
expect(bad.includes('Unexpected console statement')).toEqual(true);
16+
expect(bad.includes('No magic number: 2')).toEqual(true);
1617
});
1718

1819
it('check success files', (): void => {

test/typescript.bad.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
export class A {
2+
// expect errors
3+
public hi: number = 2;
24
// expect errors
35
hello = 1;
46
}
57

68
// expect errors
79
console.log(new A().hello);
10+
console.log(new A().hi);
811

912
// expect no errors
1013
const helloWorld: Function = function (): string {

test/typescript.good.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1+
type SmallPrimes = 2 | 3 | 5 | 7 | 11;
2+
13
export class A {
2-
public hello: number = 1;
4+
public readonly hi: SmallPrimes = 2;
5+
public readonly hello: number = 1;
36
}
47

8+
console.error(new A().hi);
59
console.error(new A().hello);
10+
11+
enum foo {
12+
SECOND = 1000,
13+
VALUE_1 = 3,
14+
VALUE_2 = 4
15+
}
16+
17+
console.error(foo.SECOND);
18+
console.error(foo.VALUE_1);
19+
console.error(foo.VALUE_2);

0 commit comments

Comments
 (0)