Skip to content

Commit d7c83f0

Browse files
Merge pull request #31777 from a-tarasyuk/feature/eslint
Migrate the repo to ESLint
2 parents e934a0d + 861f0be commit d7c83f0

File tree

271 files changed

+8436
-7109
lines changed

Some content is hidden

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

271 files changed

+8436
-7109
lines changed

.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/built/local/**
2+
/tests/**
3+
/lib/**
4+
/src/lib/*.generated.d.ts

.eslintrc.json

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"parserOptions": {
4+
"warnOnUnsupportedTypeScriptVersion": false,
5+
"ecmaVersion": 6,
6+
"sourceType": "module"
7+
},
8+
"env": {
9+
"browser": false,
10+
"node": true,
11+
"es6": true
12+
},
13+
"plugins": [
14+
"@typescript-eslint", "jsdoc", "no-null", "import"
15+
],
16+
"rules": {
17+
"@typescript-eslint/adjacent-overload-signatures": "error",
18+
"@typescript-eslint/array-type": "error",
19+
20+
"camelcase": "off",
21+
"@typescript-eslint/camelcase": ["error", { "properties": "never", "allow": ["^[A-Za-z][a-zA-Za-z]+_[A-Za-z]+$"] }],
22+
23+
"@typescript-eslint/class-name-casing": "error",
24+
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
25+
"@typescript-eslint/interface-name-prefix": "error",
26+
"@typescript-eslint/no-inferrable-types": "error",
27+
"@typescript-eslint/no-misused-new": "error",
28+
"@typescript-eslint/no-this-alias": "error",
29+
"@typescript-eslint/prefer-for-of": "error",
30+
"@typescript-eslint/prefer-function-type": "error",
31+
"@typescript-eslint/prefer-namespace-keyword": "error",
32+
33+
"quotes": "off",
34+
"@typescript-eslint/quotes": ["error", "double", { "avoidEscape": true, "allowTemplateLiterals": true }],
35+
36+
"semi": "off",
37+
"@typescript-eslint/semi": "error",
38+
39+
"@typescript-eslint/triple-slash-reference": "error",
40+
"@typescript-eslint/type-annotation-spacing": "error",
41+
"@typescript-eslint/unified-signatures": "error",
42+
43+
// scripts/eslint/rules
44+
"object-literal-surrounding-space": "error",
45+
"no-type-assertion-whitespace": "error",
46+
"type-operator-spacing": "error",
47+
"only-arrow-functions": ["error", {
48+
"allowNamedFunctions": true ,
49+
"allowDeclarations": true
50+
}],
51+
"no-double-space": "error",
52+
"boolean-trivia": "error",
53+
"no-in-operator": "error",
54+
"simple-indent": "error",
55+
"debug-assert": "error",
56+
"no-keywords": "error",
57+
58+
// eslint-plugin-import
59+
"import/no-extraneous-dependencies": ["error", { "optionalDependencies": false }],
60+
61+
// eslint-plugin-no-null
62+
"no-null/no-null": "error",
63+
64+
// eslint-plugin-jsdoc
65+
"jsdoc/check-alignment": "error",
66+
67+
// eslint
68+
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
69+
"constructor-super": "error",
70+
"curly": ["error", "multi-line"],
71+
"dot-notation": "error",
72+
"eqeqeq": "error",
73+
"linebreak-style": ["error", "windows"],
74+
"new-parens": "error",
75+
"no-caller": "error",
76+
"no-duplicate-case": "error",
77+
"no-duplicate-imports": "error",
78+
"no-empty": "error",
79+
"no-eval": "error",
80+
"no-extra-bind": "error",
81+
"no-fallthrough": "error",
82+
"no-new-func": "error",
83+
"no-new-wrappers": "error",
84+
"no-return-await": "error",
85+
"no-restricted-globals": ["error",
86+
{ "name": "setTimeout" },
87+
{ "name": "clearTimeout" },
88+
{ "name": "setInterval" },
89+
{ "name": "clearInterval" },
90+
{ "name": "setImmediate" },
91+
{ "name": "clearImmediate" }
92+
],
93+
"no-sparse-arrays": "error",
94+
"no-template-curly-in-string": "error",
95+
"no-throw-literal": "error",
96+
"no-trailing-spaces": "error",
97+
"no-undef-init": "error",
98+
"no-unsafe-finally": "error",
99+
"no-unused-expressions": ["error", { "allowTernary": true }],
100+
"no-unused-labels": "error",
101+
"no-var": "error",
102+
"object-shorthand": "error",
103+
"prefer-const": "error",
104+
"prefer-object-spread": "error",
105+
"quote-props": ["error", "consistent-as-needed"],
106+
"space-in-parens": "error",
107+
"unicode-bom": ["error", "never"],
108+
"use-isnan": "error"
109+
}
110+
}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ tests/cases/**/*.js
3737
!tests/cases/docker/*.js/
3838
tests/cases/**/*.js.map
3939
*.config
40+
scripts/eslint/built/
4041
scripts/debug.bat
4142
scripts/run.bat
4243
scripts/word2md.js
@@ -60,6 +61,8 @@ internal/
6061
**/.vs
6162
**/.vscode
6263
!**/.vscode/tasks.json
64+
!**/.vscode/settings.json
65+
!**/.vscode/extensions.json
6366
!tests/cases/projects/projectOption/**/node_modules
6467
!tests/cases/projects/NodeModulesSearch/**/*
6568
!tests/baselines/reference/project/nodeModules*/**/*

.npmignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ netci.groovy
99
scripts
1010
src
1111
tests
12-
tslint.json
1312
Jakefile.js
13+
.eslintrc
14+
.eslintignore
1415
.editorconfig
1516
.failed-tests
1617
.git

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ branches:
1818

1919
install:
2020
- npm uninstall typescript --no-save
21-
- npm uninstall tslint --no-save
2221
- npm install
2322

2423
cache:

.vscode/extensions.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"recommendations": [
3+
"dbaeumer.vscode-eslint"
4+
],
5+
6+
"unwantedRecommendations": [
7+
"ms-vscode.vscode-typescript-tslint-plugin"
8+
]
9+
}

.vscode/settings.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"eslint.validate": [
3+
{
4+
"language": "typescript",
5+
"autoFix": true
6+
}
7+
],
8+
"eslint.options": {
9+
"rulePaths": ["../scripts/eslint/built/rules/"],
10+
"ext": [".ts"]
11+
},
12+
"eslint.workingDirectories": ["./src", "./scripts"]
13+
}

Gulpfile.js

+57-25
Original file line numberDiff line numberDiff line change
@@ -318,36 +318,68 @@ task("clean-tests").description = "Cleans the outputs for the test infrastructur
318318

319319
const watchTests = () => watchProject("src/testRunner", cmdLineOptions);
320320

321-
const buildRules = () => buildProject("scripts/tslint");
322-
task("build-rules", buildRules);
323-
task("build-rules").description = "Compiles tslint rules to js";
321+
const buildEslintRules = () => buildProject("scripts/eslint");
322+
task("build-eslint-rules", buildEslintRules);
323+
task("build-eslint-rules").description = "Compiles eslint rules to js";
324324

325-
const cleanRules = () => cleanProject("scripts/tslint");
326-
cleanTasks.push(cleanRules);
327-
task("clean-rules", cleanRules);
328-
task("clean-rules").description = "Cleans the outputs for the lint rules";
325+
const cleanEslintRules = () => cleanProject("scripts/eslint");
326+
cleanTasks.push(cleanEslintRules);
327+
task("clean-eslint-rules", cleanEslintRules);
328+
task("clean-eslint-rules").description = "Cleans the outputs for the eslint rules";
329+
330+
const runEslintRulesTests = () => runConsoleTests("scripts/eslint/built/tests", "mocha-fivemat-progress-reporter", /*runInParallel*/ false, /*watchMode*/ false);
331+
task("run-eslint-rules-tests", series(buildEslintRules, runEslintRulesTests));
332+
task("run-eslint-rules-tests").description = "Runs the eslint rule tests";
329333

330334
const lintFoldStart = async () => { if (fold.isTravis()) console.log(fold.start("lint")); };
331335
const lintFoldEnd = async () => { if (fold.isTravis()) console.log(fold.end("lint")); };
332-
const lint = series([
333-
lintFoldStart,
334-
...["scripts/tslint/tsconfig.json", "src/tsconfig-base.json"].map(project => {
335-
const lintOne = () => {
336-
const args = ["node_modules/tslint/bin/tslint", "--project", project, "--formatters-dir", "./built/local/tslint/formatters", "--format", "autolinkableStylish"];
337-
if (cmdLineOptions.fix) args.push("--fix");
338-
log(`Linting: node ${args.join(" ")}`);
339-
return exec(process.execPath, args);
340-
};
341-
lintOne.dispayName = `lint(${project})`;
342-
return lintOne;
343-
}),
344-
lintFoldEnd
345-
]);
336+
const eslint = (folder) => async () => {
337+
const ESLINTRC_CI = ".eslintrc.ci.json";
338+
const isCIEnv = cmdLineOptions.ci || process.env.CI === "true";
339+
340+
const args = [
341+
"node_modules/eslint/bin/eslint",
342+
"--format", "autolinkable-stylish",
343+
"--rulesdir", "scripts/eslint/built/rules",
344+
"--ext", ".ts",
345+
];
346+
347+
if (
348+
isCIEnv &&
349+
fs.existsSync(path.resolve(folder, ESLINTRC_CI))
350+
) {
351+
args.push("--config", path.resolve(folder, ESLINTRC_CI));
352+
}
353+
354+
if (cmdLineOptions.fix) {
355+
args.push("--fix");
356+
}
357+
358+
args.push(folder);
359+
360+
log(`Linting: ${args.join(" ")}`);
361+
return exec(process.execPath, args);
362+
}
363+
364+
const lintScripts = eslint("scripts");
365+
lintScripts.displayName = "lint-scripts";
366+
task("lint-scripts", series([buildEslintRules, lintFoldStart, lintScripts, lintFoldEnd]));
367+
task("lint-scripts").description = "Runs eslint on the scripts sources.";
368+
369+
const lintCompiler = eslint("src");
370+
lintCompiler.displayName = "lint-compiler";
371+
task("lint-compiler", series([buildEslintRules, lintFoldStart, lintCompiler, lintFoldEnd]));
372+
task("lint-compiler").description = "Runs eslint on the compiler sources.";
373+
task("lint-compiler").flags = {
374+
" --ci": "Runs eslint additional rules",
375+
};
376+
377+
const lint = series([buildEslintRules, lintFoldStart, lintScripts, lintCompiler, lintFoldEnd]);
346378
lint.displayName = "lint";
347-
task("lint", series(buildRules, lint));
348-
task("lint").description = "Runs tslint on the compiler sources.";
379+
task("lint", series([buildEslintRules, lintFoldStart, lint, lintFoldEnd]));
380+
task("lint").description = "Runs eslint on the compiler and scripts sources.";
349381
task("lint").flags = {
350-
" --f[iles]=<regex>": "pattern to match files to lint",
382+
" --ci": "Runs eslint additional rules",
351383
};
352384

353385
const buildCancellationToken = () => buildProject("src/cancellationToken");
@@ -393,7 +425,7 @@ const generateCodeCoverage = () => exec("istanbul", ["cover", "node_modules/moch
393425
task("generate-code-coverage", series(preBuild, buildTests, generateCodeCoverage));
394426
task("generate-code-coverage").description = "Generates code coverage data via istanbul";
395427

396-
const preTest = parallel(buildRules, buildTests, buildServices, buildLssl);
428+
const preTest = parallel(buildTests, buildServices, buildLssl);
397429
preTest.displayName = "preTest";
398430

399431
const postTest = (done) => cmdLineOptions.lint ? lint(done) : done();

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ gulp runtests # Run tests using the built compiler and test infrastruct
9090
gulp runtests-parallel # Like runtests, but split across multiple threads. Uses a number of threads equal to the system
9191
# core count by default. Use --workers=<number> to adjust this.
9292
gulp baseline-accept # This replaces the baseline test results with the results obtained from gulp runtests.
93-
gulp lint # Runs tslint on the TypeScript source.
93+
gulp lint # Runs eslint on the TypeScript source.
9494
gulp help # List the above commands.
9595
```
9696

package.json

+15-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"@types/browserify": "latest",
3434
"@types/chai": "latest",
3535
"@types/convert-source-map": "latest",
36-
"@types/del": "latest",
3736
"@types/glob": "latest",
3837
"@types/gulp": "^4.0.5",
3938
"@types/gulp-concat": "latest",
@@ -55,15 +54,25 @@
5554
"@types/through2": "latest",
5655
"@types/travis-fold": "latest",
5756
"@types/xml2js": "^0.4.0",
57+
"@typescript-eslint/eslint-plugin": "2.2.0",
58+
"@typescript-eslint/experimental-utils": "2.2.0",
59+
"@typescript-eslint/parser": "2.2.0",
60+
"async": "latest",
5861
"azure-devops-node-api": "^8.0.0",
5962
"browser-resolve": "^1.11.2",
6063
"browserify": "latest",
6164
"chai": "latest",
6265
"chalk": "latest",
6366
"convert-source-map": "latest",
64-
"del": "latest",
67+
"del": "5.1.0",
68+
"eslint": "6.3.0",
69+
"eslint-formatter-autolinkable-stylish": "1.0.3",
70+
"eslint-plugin-import": "2.18.2",
71+
"eslint-plugin-jsdoc": "15.9.1",
72+
"eslint-plugin-no-null": "1.0.2",
6573
"fancy-log": "latest",
6674
"fs-extra": "^6.0.1",
75+
"glob": "latest",
6776
"gulp": "^4.0.0",
6877
"gulp-concat": "latest",
6978
"gulp-insert": "latest",
@@ -87,7 +96,6 @@
8796
"source-map-support": "latest",
8897
"through2": "latest",
8998
"travis-fold": "latest",
90-
"tslint": "latest",
9199
"typescript": "next",
92100
"vinyl": "latest",
93101
"vinyl-sourcemaps-apply": "latest",
@@ -96,6 +104,7 @@
96104
"scripts": {
97105
"pretest": "gulp tests",
98106
"test": "gulp runtests-parallel --light=false",
107+
"test:eslint-rules": "gulp run-eslint-rules-tests",
99108
"build": "npm run build:compiler && npm run build:tests",
100109
"build:compiler": "gulp local",
101110
"build:tests": "gulp tests",
@@ -104,6 +113,9 @@
104113
"gulp": "gulp",
105114
"jake": "gulp",
106115
"lint": "gulp lint",
116+
"lint:ci": "gulp lint --ci",
117+
"lint:compiler": "gulp lint-compiler",
118+
"lint:scripts": "gulp lint-scripts",
107119
"setup-hooks": "node scripts/link-hooks.js",
108120
"update-costly-tests": "node scripts/costly-tests.js"
109121
},

0 commit comments

Comments
 (0)