Skip to content

Commit 526265d

Browse files
tanettrimasahnpnl
authored andcommitted
chore: migrate tslint to eslint (#1590)
1 parent 720c854 commit 526265d

57 files changed

Lines changed: 654 additions & 457 deletions

Some content is hidden

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

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ dist/
22
node_modules/
33
e2e/__cases__/
44
e2e/__workdir_synlink__/
5+
e2e/__external-repos__/
56
coverage/
67
docs/
8+
*.config.js

.eslintrc.js

Lines changed: 220 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,239 @@
11
module.exports = {
22
env: {
33
node: true,
4+
es6: true,
5+
'jest/globals': true,
46
},
5-
extends: 'eslint:recommended',
7+
extends: [
8+
'eslint:recommended',
9+
'plugin:@typescript-eslint/recommended',
10+
'plugin:@typescript-eslint/recommended-requiring-type-checking',
11+
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
12+
'plugin:jest/recommended',
13+
'plugin:prettier/recommended'
14+
],
15+
parser: '@typescript-eslint/parser',
616
parserOptions: {
17+
project: 'tsconfig.json',
718
ecmaVersion: 2020,
819
sourceType: 'module',
920
impliedStrict: true,
1021
ecmaFeatures: {
1122
jsx: true,
1223
},
1324
},
25+
plugins: ['@typescript-eslint', 'jest', 'jsdoc'],
1426
rules: {
15-
'no-console': ['error', { allow: ['warn', 'error', 'log'] }],
16-
indent: ['error', 2],
17-
'linebreak-style': ['error', 'unix'],
18-
quotes: ['error', 'single'],
19-
semi: ['error', 'never'],
20-
'comma-dangle': [
27+
'prettier/prettier': 'error',
28+
'no-unused-vars': 'off', // let typescript-eslint handle this
29+
'no-console': 'error',
30+
'linebreak-style': 'off',
31+
'comma-dangle': 'off',
32+
'constructor-super': 'error',
33+
'for-direction': ['error'],
34+
'getter-return': 'warn',
35+
'no-async-promise-executor': ['error'],
36+
'no-case-declarations': ['error'],
37+
'no-class-assign': ['error'],
38+
'no-compare-neg-zero': ['error'],
39+
'no-cond-assign': 'error',
40+
'no-const-assign': ['error'],
41+
'no-constant-condition': ['warn'],
42+
'no-control-regex': ['warn'],
43+
'no-debugger': 'error',
44+
'no-delete-var': ['error'],
45+
'no-dupe-args': ['error'],
46+
'no-dupe-class-members': 'warn',
47+
'no-dupe-keys': ['error'],
48+
'no-duplicate-case': ['error'],
49+
'no-empty': [
2150
'error',
2251
{
23-
arrays: 'always-multiline',
24-
objects: 'always-multiline',
25-
imports: 'always-multiline',
26-
exports: 'always-multiline',
27-
functions: 'never',
52+
allowEmptyCatch: true,
53+
},
54+
],
55+
'no-empty-character-class': ['error'],
56+
'no-empty-pattern': ['error'],
57+
'no-ex-assign': ['error'],
58+
'no-extra-boolean-cast': ['error'],
59+
'no-extra-semi': 'off',
60+
'no-fallthrough': 'off',
61+
'no-func-assign': ['error'],
62+
'no-global-assign': ['error'],
63+
'no-inner-declarations': ['error'],
64+
'no-invalid-regexp': ['error'],
65+
'no-irregular-whitespace': 'off',
66+
'no-misleading-character-class': ['error'],
67+
'no-mixed-spaces-and-tabs': ['error'],
68+
'no-new-symbol': ['error'],
69+
'no-obj-calls': ['error'],
70+
'no-octal': ['error'],
71+
'no-prototype-builtins': ['error'],
72+
'no-redeclare': 'warn',
73+
'no-regex-spaces': ['error'],
74+
'no-self-assign': ['error'],
75+
'no-shadow-restricted-names': ['error'],
76+
'no-sparse-arrays': ['error'],
77+
'no-this-before-super': ['error'],
78+
'no-undef': ['error'],
79+
'no-unexpected-multiline': ['error'],
80+
'no-unreachable': ['error'],
81+
'no-unsafe-finally': 'error',
82+
'no-unsafe-negation': ['error'],
83+
'no-unused-labels': 'error',
84+
'no-useless-catch': ['error'],
85+
'no-useless-escape': 'warn',
86+
'no-with': ['error'],
87+
'require-yield': ['error'],
88+
'use-isnan': 'error',
89+
'valid-typeof': 'off',
90+
'@typescript-eslint/no-unused-vars': ["error", { "argsIgnorePattern": "^_" }],
91+
'@typescript-eslint/adjacent-overload-signatures': 'error',
92+
'@typescript-eslint/array-type': [
93+
'warn',
94+
{
95+
default: 'array',
96+
},
97+
],
98+
'@typescript-eslint/ban-types': [
99+
'error',
100+
{
101+
types: {
102+
Object: {
103+
message: 'Avoid using the `Object` type. Did you mean `object`?',
104+
},
105+
Function: {
106+
message: 'Avoid using the `Function` type. Prefer a specific function type, like `() => void`.',
107+
},
108+
Boolean: {
109+
message: 'Avoid using the `Boolean` type. Did you mean `boolean`?',
110+
},
111+
Number: {
112+
message: 'Avoid using the `Number` type. Did you mean `number`?',
113+
},
114+
String: {
115+
message: 'Avoid using the `String` type. Did you mean `string`?',
116+
},
117+
Symbol: {
118+
message: 'Avoid using the `Symbol` type. Did you mean `symbol`?',
119+
},
120+
},
121+
},
122+
],
123+
'@typescript-eslint/class-name-casing': 'error',
124+
'@typescript-eslint/prefer-regexp-exec': 'warn',
125+
'@typescript-eslint/prefer-string-starts-ends-with': 'warn',
126+
'@typescript-eslint/unbound-method': 'off',
127+
'@typescript-eslint/prefer-includes': 'warn',
128+
'@typescript-eslint/consistent-type-assertions': 'error',
129+
'@typescript-eslint/consistent-type-definitions': 'error',
130+
'@typescript-eslint/explicit-member-accessibility': [
131+
'error',
132+
{
133+
accessibility: 'no-public',
134+
},
135+
],
136+
'@typescript-eslint/interface-name-prefix': 'off',
137+
'@typescript-eslint/member-delimiter-style': [
138+
'error',
139+
{
140+
multiline: {
141+
delimiter: 'none',
142+
requireLast: true,
143+
},
144+
singleline: {
145+
delimiter: 'semi',
146+
requireLast: false,
147+
},
148+
},
149+
],
150+
'@typescript-eslint/require-await': 'off',
151+
'@typescript-eslint/ban-ts-ignore': 'off',
152+
'@typescript-eslint/no-empty-function': ['error', { 'allow': ['arrowFunctions']}],
153+
'@typescript-eslint/no-empty-interface': 'off',
154+
'@typescript-eslint/explicit-function-return-type': 'off',
155+
'@typescript-eslint/no-explicit-any': 'off',
156+
'@typescript-eslint/no-for-in-array': 'error',
157+
'@typescript-eslint/no-inferrable-types': 'error',
158+
'@typescript-eslint/no-misused-new': 'error',
159+
'@typescript-eslint/no-namespace': 'warn',
160+
'@typescript-eslint/no-non-null-assertion': 'off',
161+
'@typescript-eslint/no-parameter-properties': 'off',
162+
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
163+
'@typescript-eslint/no-use-before-define': 'off',
164+
'@typescript-eslint/no-var-requires': 'off',
165+
'@typescript-eslint/prefer-for-of': 'off',
166+
'@typescript-eslint/prefer-function-type': 'error',
167+
'@typescript-eslint/prefer-namespace-keyword': 'error',
168+
'@typescript-eslint/prefer-readonly': 'error',
169+
'@typescript-eslint/triple-slash-reference': [
170+
'error',
171+
{
172+
path: 'always',
173+
types: 'prefer-import',
174+
lib: 'always',
175+
},
176+
],
177+
'@typescript-eslint/type-annotation-spacing': 'off',
178+
'@typescript-eslint/unified-signatures': 'error',
179+
'@typescript-eslint/no-unnecessary-type-assertion': 'warn',
180+
'arrow-body-style': 'warn',
181+
'arrow-parens': ['off', 'always'],
182+
'brace-style': ['off', 'off'],
183+
camelcase: 'warn',
184+
'class-methods-use-this': 'warn',
185+
complexity: 'off',
186+
curly: ['warn', 'multi-line'],
187+
'default-case': 'error',
188+
'dot-notation': 'error',
189+
'eol-last': 'off',
190+
eqeqeq: ['error', 'smart'],
191+
'guard-for-in': 'error',
192+
'id-match': 'error',
193+
'jsdoc/check-alignment': 'error',
194+
'jsdoc/check-indentation': 'error',
195+
'jsdoc/newline-after-description': 'warn',
196+
'max-classes-per-file': 'off',
197+
'max-len': 'off',
198+
'new-parens': 'off',
199+
'newline-per-chained-call': 'off',
200+
'no-bitwise': 'off',
201+
'no-caller': 'error',
202+
'no-duplicate-imports': 'error',
203+
'no-eval': 'error',
204+
'no-invalid-this': 'off',
205+
'no-multiple-empty-lines': 'off',
206+
'no-new-wrappers': 'error',
207+
'no-return-await': 'error',
208+
'no-shadow': [
209+
'off',
210+
{
211+
hoist: 'all',
212+
},
213+
],
214+
'no-template-curly-in-string': 'error',
215+
'no-throw-literal': 'error',
216+
'no-trailing-spaces': 'off',
217+
'no-undef-init': 'error',
218+
'no-underscore-dangle': 'off',
219+
'no-unused-expressions': 'error',
220+
'no-var': 'error',
221+
'object-shorthand': 'error',
222+
'one-var': ['error', 'never'],
223+
'prefer-const': 'warn',
224+
'prefer-object-spread': 'error',
225+
'prefer-template': 'error',
226+
'quote-props': 'off',
227+
radix: 'error',
228+
'space-before-function-paren': 'off',
229+
'space-in-parens': ['off', 'never'],
230+
'spaced-comment': [
231+
'warn',
232+
'always',
233+
{
234+
markers: ['/'],
28235
},
29236
],
30237
},
238+
settings: {},
31239
}

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ tsconfig.json
6666
.prettierrc
6767
.travis.yml
6868
tsconfig.build.json
69-
tslint.json
7069
.npmrc
7170
.markdownlint.yaml
7271
.cache

e2e/__external-repos__/yarn-workspace-composite/packages/my-app/main.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { main } from './main'
22

33
test('main', () => {
4-
// tslint:disable-next-line:no-console
54
const mockLog = console.log = jest.fn()
65

76
main()

e2e/__external-repos__/yarn-workspace-composite/packages/my-app/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { myLibraryFunction } from '../my-library'
33
export function main() {
44
const value = myLibraryFunction()
55

6-
// tslint:disable-next-line:no-console
76
console.log(`You got foo: "${value.foo}" and bar: ${value.bar}`)
87
}
98

e2e/__helpers__/test-case/processed-file-io.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Config } from '@jest/types'
33

44
import ProcessedSource from '../../../src/__helpers__/processed-source'
55

6-
// tslint:disable-next-line:no-default-export
76
export default class ProcessedFileIo extends ProcessedSource {
87
constructor(
98
cwd: string,

e2e/__helpers__/test-case/run-descriptor.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import RunResult from './run-result'
66
import { run } from './runtime'
77
import { RunTestOptions, RunWithTemplateIteratorContext, RunWithTemplatesIterator, TestRunResultsMap } from './types'
88

9-
// tslint:disable-next-line:no-default-export
109
export default class RunDescriptor {
1110
protected _options: RunTestOptions
1211
protected _sourcePackageJson: any
@@ -46,8 +45,8 @@ export default class RunDescriptor {
4645
template: this.templateName,
4746
})
4847
if (logUnlessStatus != null && logUnlessStatus !== result.status) {
49-
// tslint:disable-next-line:no-console
50-
console.log(
48+
// eslint-disable-next-line no-console
49+
console.log(
5150
'='.repeat(70),
5251
'\n',
5352
`Test exited with unexpected status in "${this.name}" using template "${this.templateName}" (exit code: ${result.status}):\n`,
@@ -72,17 +71,15 @@ export default class RunDescriptor {
7271
throw new RangeError(`There must be at least one template to run the test case with.`)
7372
}
7473

75-
if (!templates.every((t, i) => templates.indexOf(t, i + 1) === -1)) {
74+
if (!templates.every((t, i) => !templates.includes(t, i + 1))) {
7675
throw new Error(`Each template must be unique. Given ${templates.join(', ')}`)
7776
}
7877
return templates.reduce((map, template) => {
7978
const desc = new RunDescriptor(this.name, {
8079
...this._options,
8180
template,
8281
})
83-
const runTest = () => {
84-
return (map[template] = desc.run(expectedStatus))
85-
}
82+
const runTest = () => (map[template] = desc.run(expectedStatus))
8683
if (iterator) {
8784
iterator(runTest, createIteratorContext(template, expectedStatus))
8885
} else {

e2e/__helpers__/test-case/run-result.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { cacheDir } from '../../../scripts/lib/paths'
1010
import ProcessedFileIo from './processed-file-io'
1111
import { escapeRegex, normalizeJestOutput, stripAnsiColors } from './utils'
1212

13-
// tslint:disable-next-line:no-default-export
1413
export default class RunResult {
1514
constructor(
1615
readonly cwd: string,
@@ -112,8 +111,6 @@ export default class RunResult {
112111

113112
return map
114113
.sort((a, b) => ((b.from as any).length || Infinity) - ((a.from as any).length || Infinity))
115-
.reduce((str, { from, to }) => {
116-
return str.replace(typeof from === 'string' ? new RegExp(`${escapeRegex(from)}`, 'g') : from, to)
117-
}, str)
114+
.reduce((str, { from, to }) => str.replace(typeof from === 'string' ? new RegExp(`${escapeRegex(from)}`, 'g') : from, to), str)
118115
}
119116
}

e2e/__helpers__/test-case/runtime.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ describe.skip('__eval', () => {
4444
eval(process.env.__TS_JEST_EVAL);
4545
`
4646

47-
// tslint:disable-next-line:variable-name
4847
let __hooksSource: string
4948
function hooksSourceWith(vars: Record<string, any>): string {
5049
if (!__hooksSource) {
5150
__hooksSource = readFileSync(join(__dirname, '__hooks-source__.js.hbs'), 'utf8')
5251
}
52+
// eslint-disable-next-line no-useless-escape
5353
return __hooksSource.replace(/\{\{([^\}]+)\}\}/g, (_, key) => JSON.stringify(vars[key]))
5454
}
5555

@@ -122,6 +122,7 @@ export function run(name: string, options: RunTestOptions = {}): RunResult {
122122

123123
// write final config
124124
// FIXME: sounds like the json fail to be encoded as an arg
125+
// eslint-disable-next-line no-constant-condition
125126
if (false /* enableOptimizations() */) {
126127
cmdArgs.push('--config', JSON.stringify(finalConfig))
127128
} else if (Object.keys(extraConfig).length !== 0) {
@@ -191,11 +192,9 @@ execFile(cmd, args, options)
191192

192193
copySync(wrkDir, srcDir, {
193194
overwrite: false,
194-
filter: from => {
195-
return relative(sourceDir, from)
195+
filter: from => relative(sourceDir, from)
196196
.split(sep)
197-
.includes('__snapshots__')
198-
},
197+
.includes('__snapshots__'),
199198
})
200199
})
201200
}

e2e/__helpers__/test-case/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface RunWithTemplateIteratorContext {
2424
testLabel: string
2525
}
2626

27-
// tslint:disable-next-line:interface-over-type-literal
27+
2828
export type TestRunResultsMap<T extends string = string> = { [key in T]: RunResult }
2929

3030
export interface PreparedTest {

0 commit comments

Comments
 (0)