Skip to content

Commit b3d6e1b

Browse files
authored
replace tslint by typescript-eslint (#1979)
* replace tslint by typescript-eslint * remove tslint config file and comments * Fix eslint issue in src directory * Migrate simple eslint rules in __test__ directory * use stricter types in __tests__ directory * Fix or ignore all eslint issues in website directory * Ignore eslint report in main immutable.d.ts file for now
1 parent 680e3ed commit b3d6e1b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+763
-595
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/pages/generated/**
33
/dist/**
44
node_modules
5+
/type-definitions/flow-tests

.eslintrc.json

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
{
22
"root": true,
3+
"parser": "@typescript-eslint/parser",
34
"parserOptions": {
45
"ecmaVersion": 6,
56
"sourceType": "module"
67
},
7-
"extends": ["airbnb", "prettier"],
8-
"plugins": ["react", "prettier"],
8+
"extends": [
9+
"airbnb",
10+
"plugin:@typescript-eslint/recommended",
11+
"plugin:import/typescript",
12+
"prettier"
13+
],
14+
"plugins": ["react", "prettier", "@typescript-eslint"],
915
"rules": {
1016
"array-callback-return": "off",
1117
"block-scoped-var": "off",
@@ -35,7 +41,7 @@
3541
"no-this-before-super": "off",
3642
"no-underscore-dangle": "off",
3743
"no-unused-expressions": "off",
38-
"no-unused-vars": "error",
44+
"no-unused-vars": "off",
3945
"no-use-before-define": "off",
4046
"no-useless-concat": "error",
4147
"no-var": "error",
@@ -61,10 +67,15 @@
6167
"react/self-closing-comp": "error",
6268
"react/sort-comp": "off",
6369
"react/jsx-props-no-spreading": "off",
70+
"react/require-default-props": [
71+
"error",
72+
{
73+
"functions": "ignore"
74+
}
75+
],
6476
"jsx-a11y/no-static-element-interactions": "off",
6577
"import/extensions": [
6678
"error",
67-
"always",
6879
{ "js": "never", "ts": "never", "tsx": "never" }
6980
],
7081
"import/newline-after-import": "error",
@@ -74,6 +85,39 @@
7485
"import/no-unresolved": "error",
7586
"import/no-useless-path-segments": "off",
7687
"import/prefer-default-export": "off",
77-
"prettier/prettier": "error"
78-
}
88+
"prettier/prettier": "error",
89+
"@typescript-eslint/no-unused-vars": [
90+
"error",
91+
{ "argsIgnorePattern": "^_" }
92+
]
93+
},
94+
"overrides": [
95+
{
96+
"files": ["__tests__/*"],
97+
"rules": {
98+
"import/no-unresolved": [
99+
"error",
100+
{
101+
"ignore": ["immutable"]
102+
}
103+
]
104+
}
105+
},
106+
107+
{
108+
"files": ["type-definitions/ts-tests/*"],
109+
"rules": {
110+
"no-lone-blocks": "off",
111+
"@typescript-eslint/no-explicit-any": "off",
112+
"@typescript-eslint/no-unused-vars": "off",
113+
"prefer-const": "off",
114+
"import/no-unresolved": [
115+
"error",
116+
{
117+
"ignore": ["immutable"]
118+
}
119+
]
120+
}
121+
}
122+
]
79123
}

__tests__/Comparator.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ const expectedSortedNumbers: readonly number[] = [
66
7, 95, 90, 92, 3, 5, 9, 4, 6, 10, 12,
77
];
88

9+
/* eslint-disable no-else-return */
910
const testComparator: Comparator<number> = (left, right) => {
1011
//The number 7 always goes first...
11-
if (left == 7) {
12+
if (left === 7) {
1213
return PairSorting.LeftThenRight;
13-
} else if (right == 7) {
14+
} else if (right === 7) {
1415
return PairSorting.RightThenLeft;
1516
}
1617

@@ -31,6 +32,7 @@ const testComparator: Comparator<number> = (left, right) => {
3132
//...and, finally, sort the numbers of each subgroup in ascending order.
3233
return left - right;
3334
};
35+
/* eslint-enable no-else-return */
3436

3537
describe.each([
3638
['List', List],

__tests__/Conversion.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { fromJS, is, List, Map, OrderedMap, Record } from 'immutable';
2-
32
import * as jasmineCheck from 'jasmine-check';
4-
jasmineCheck.install();
53

6-
// Symbols
7-
declare function Symbol(name: string): any;
4+
jasmineCheck.install();
85

96
describe('Conversion', () => {
107
// Note: order of keys based on Map's hashing order
@@ -107,7 +104,9 @@ describe('Conversion', () => {
107104
});
108105

109106
it('Throws when provided circular reference', () => {
110-
const o = { a: { b: { c: null as any } } };
107+
type OType = { a: { b: { c: OType | null } } };
108+
109+
const o: OType = { a: { b: { c: null } } };
111110
o.a.b.c = o;
112111
expect(() => fromJS(o)).toThrow(
113112
'Cannot convert circular structure to Immutable'
@@ -117,7 +116,8 @@ describe('Conversion', () => {
117116
it('Converts deep JSON with custom conversion', () => {
118117
const seq = fromJS(js, function (key, sequence) {
119118
if (key === 'point') {
120-
return new Point(sequence as any);
119+
// @ts-expect-error -- to convert to real typing
120+
return new Point(sequence);
121121
}
122122
return Array.isArray(this[key])
123123
? sequence.toList()
@@ -128,7 +128,8 @@ describe('Conversion', () => {
128128
});
129129

130130
it('Converts deep JSON with custom conversion including keypath if requested', () => {
131-
const paths: Array<any> = [];
131+
const paths: Array<Array<string | number> | undefined> = [];
132+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
132133
const seq1 = fromJS(js, function (key, sequence, keypath) {
133134
expect(arguments.length).toBe(3);
134135
paths.push(keypath);
@@ -147,6 +148,8 @@ describe('Conversion', () => {
147148
['point'],
148149
['list'],
149150
]);
151+
152+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
150153
const seq2 = fromJS(js, function (key, sequence) {
151154
expect(arguments[2]).toBe(undefined);
152155
});

__tests__/Equality.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { is, List, Map, Seq, Set } from 'immutable';
2-
32
import * as jasmineCheck from 'jasmine-check';
3+
44
jasmineCheck.install();
55

66
describe('Equality', () => {
@@ -53,8 +53,8 @@ describe('Equality', () => {
5353
});
5454

5555
it('dereferences things', () => {
56-
const ptrA = { foo: 1 },
57-
ptrB = { foo: 2 };
56+
const ptrA = { foo: 1 };
57+
const ptrB = { foo: 2 };
5858
expectIsNot(ptrA, ptrB);
5959
ptrA.valueOf = ptrB.valueOf = function () {
6060
return 5;
@@ -66,11 +66,13 @@ describe('Equality', () => {
6666
};
6767
expectIs(ptrA, ptrB);
6868
ptrA.valueOf = ptrB.valueOf = function () {
69+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6970
return null as any;
7071
};
7172
expectIs(ptrA, ptrB);
7273
ptrA.valueOf = ptrB.valueOf = function () {
73-
return void 0 as any;
74+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
75+
return undefined as any;
7476
};
7577
expectIs(ptrA, ptrB);
7678
ptrA.valueOf = function () {

__tests__/IndexedSeq.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Seq } from 'immutable';
2-
32
import * as jasmineCheck from 'jasmine-check';
3+
44
jasmineCheck.install();
55

66
describe('IndexedSequence', () => {

__tests__/KeyedSeq.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Range, Seq } from 'immutable';
2-
32
import * as jasmineCheck from 'jasmine-check';
3+
44
jasmineCheck.install();
55

66
describe('KeyedSeq', () => {
@@ -11,7 +11,8 @@ describe('KeyedSeq', () => {
1111
const seqEntries = seq.entries();
1212
const keyedEntries = keyed.entries();
1313

14-
let seqStep, keyedStep;
14+
let seqStep;
15+
let keyedStep;
1516
do {
1617
seqStep = seqEntries.next();
1718
keyedStep = keyedEntries.next();

0 commit comments

Comments
 (0)