Skip to content

Commit

Permalink
Merge pull request #31777 from a-tarasyuk/feature/eslint
Browse files Browse the repository at this point in the history
Migrate the repo to ESLint
  • Loading branch information
uniqueiniquity committed Sep 11, 2019
2 parents e934a0d + 861f0be commit d7c83f0
Show file tree
Hide file tree
Showing 271 changed files with 8,436 additions and 7,109 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
@@ -0,0 +1,4 @@
/built/local/**
/tests/**
/lib/**
/src/lib/*.generated.d.ts
110 changes: 110 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,110 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"warnOnUnsupportedTypeScriptVersion": false,
"ecmaVersion": 6,
"sourceType": "module"
},
"env": {
"browser": false,
"node": true,
"es6": true
},
"plugins": [
"@typescript-eslint", "jsdoc", "no-null", "import"
],
"rules": {
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",

"camelcase": "off",
"@typescript-eslint/camelcase": ["error", { "properties": "never", "allow": ["^[A-Za-z][a-zA-Za-z]+_[A-Za-z]+$"] }],

"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
"@typescript-eslint/interface-name-prefix": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-this-alias": "error",
"@typescript-eslint/prefer-for-of": "error",
"@typescript-eslint/prefer-function-type": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",

"quotes": "off",
"@typescript-eslint/quotes": ["error", "double", { "avoidEscape": true, "allowTemplateLiterals": true }],

"semi": "off",
"@typescript-eslint/semi": "error",

"@typescript-eslint/triple-slash-reference": "error",
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unified-signatures": "error",

// scripts/eslint/rules
"object-literal-surrounding-space": "error",
"no-type-assertion-whitespace": "error",
"type-operator-spacing": "error",
"only-arrow-functions": ["error", {
"allowNamedFunctions": true ,
"allowDeclarations": true
}],
"no-double-space": "error",
"boolean-trivia": "error",
"no-in-operator": "error",
"simple-indent": "error",
"debug-assert": "error",
"no-keywords": "error",

// eslint-plugin-import
"import/no-extraneous-dependencies": ["error", { "optionalDependencies": false }],

// eslint-plugin-no-null
"no-null/no-null": "error",

// eslint-plugin-jsdoc
"jsdoc/check-alignment": "error",

// eslint
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
"constructor-super": "error",
"curly": ["error", "multi-line"],
"dot-notation": "error",
"eqeqeq": "error",
"linebreak-style": ["error", "windows"],
"new-parens": "error",
"no-caller": "error",
"no-duplicate-case": "error",
"no-duplicate-imports": "error",
"no-empty": "error",
"no-eval": "error",
"no-extra-bind": "error",
"no-fallthrough": "error",
"no-new-func": "error",
"no-new-wrappers": "error",
"no-return-await": "error",
"no-restricted-globals": ["error",
{ "name": "setTimeout" },
{ "name": "clearTimeout" },
{ "name": "setInterval" },
{ "name": "clearInterval" },
{ "name": "setImmediate" },
{ "name": "clearImmediate" }
],
"no-sparse-arrays": "error",
"no-template-curly-in-string": "error",
"no-throw-literal": "error",
"no-trailing-spaces": "error",
"no-undef-init": "error",
"no-unsafe-finally": "error",
"no-unused-expressions": ["error", { "allowTernary": true }],
"no-unused-labels": "error",
"no-var": "error",
"object-shorthand": "error",
"prefer-const": "error",
"prefer-object-spread": "error",
"quote-props": ["error", "consistent-as-needed"],
"space-in-parens": "error",
"unicode-bom": ["error", "never"],
"use-isnan": "error"
}
}
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -37,6 +37,7 @@ tests/cases/**/*.js
!tests/cases/docker/*.js/
tests/cases/**/*.js.map
*.config
scripts/eslint/built/
scripts/debug.bat
scripts/run.bat
scripts/word2md.js
Expand All @@ -60,6 +61,8 @@ internal/
**/.vs
**/.vscode
!**/.vscode/tasks.json
!**/.vscode/settings.json
!**/.vscode/extensions.json
!tests/cases/projects/projectOption/**/node_modules
!tests/cases/projects/NodeModulesSearch/**/*
!tests/baselines/reference/project/nodeModules*/**/*
Expand Down
3 changes: 2 additions & 1 deletion .npmignore
Expand Up @@ -9,8 +9,9 @@ netci.groovy
scripts
src
tests
tslint.json
Jakefile.js
.eslintrc
.eslintignore
.editorconfig
.failed-tests
.git
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -18,7 +18,6 @@ branches:

install:
- npm uninstall typescript --no-save
- npm uninstall tslint --no-save
- npm install

cache:
Expand Down
9 changes: 9 additions & 0 deletions .vscode/extensions.json
@@ -0,0 +1,9 @@
{
"recommendations": [
"dbaeumer.vscode-eslint"
],

"unwantedRecommendations": [
"ms-vscode.vscode-typescript-tslint-plugin"
]
}
13 changes: 13 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,13 @@
{
"eslint.validate": [
{
"language": "typescript",
"autoFix": true
}
],
"eslint.options": {
"rulePaths": ["../scripts/eslint/built/rules/"],
"ext": [".ts"]
},
"eslint.workingDirectories": ["./src", "./scripts"]
}
82 changes: 57 additions & 25 deletions Gulpfile.js
Expand Up @@ -318,36 +318,68 @@ task("clean-tests").description = "Cleans the outputs for the test infrastructur

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

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

const cleanRules = () => cleanProject("scripts/tslint");
cleanTasks.push(cleanRules);
task("clean-rules", cleanRules);
task("clean-rules").description = "Cleans the outputs for the lint rules";
const cleanEslintRules = () => cleanProject("scripts/eslint");
cleanTasks.push(cleanEslintRules);
task("clean-eslint-rules", cleanEslintRules);
task("clean-eslint-rules").description = "Cleans the outputs for the eslint rules";

const runEslintRulesTests = () => runConsoleTests("scripts/eslint/built/tests", "mocha-fivemat-progress-reporter", /*runInParallel*/ false, /*watchMode*/ false);
task("run-eslint-rules-tests", series(buildEslintRules, runEslintRulesTests));
task("run-eslint-rules-tests").description = "Runs the eslint rule tests";

const lintFoldStart = async () => { if (fold.isTravis()) console.log(fold.start("lint")); };
const lintFoldEnd = async () => { if (fold.isTravis()) console.log(fold.end("lint")); };
const lint = series([
lintFoldStart,
...["scripts/tslint/tsconfig.json", "src/tsconfig-base.json"].map(project => {
const lintOne = () => {
const args = ["node_modules/tslint/bin/tslint", "--project", project, "--formatters-dir", "./built/local/tslint/formatters", "--format", "autolinkableStylish"];
if (cmdLineOptions.fix) args.push("--fix");
log(`Linting: node ${args.join(" ")}`);
return exec(process.execPath, args);
};
lintOne.dispayName = `lint(${project})`;
return lintOne;
}),
lintFoldEnd
]);
const eslint = (folder) => async () => {
const ESLINTRC_CI = ".eslintrc.ci.json";
const isCIEnv = cmdLineOptions.ci || process.env.CI === "true";

const args = [
"node_modules/eslint/bin/eslint",
"--format", "autolinkable-stylish",
"--rulesdir", "scripts/eslint/built/rules",
"--ext", ".ts",
];

if (
isCIEnv &&
fs.existsSync(path.resolve(folder, ESLINTRC_CI))
) {
args.push("--config", path.resolve(folder, ESLINTRC_CI));
}

if (cmdLineOptions.fix) {
args.push("--fix");
}

args.push(folder);

log(`Linting: ${args.join(" ")}`);
return exec(process.execPath, args);
}

const lintScripts = eslint("scripts");
lintScripts.displayName = "lint-scripts";
task("lint-scripts", series([buildEslintRules, lintFoldStart, lintScripts, lintFoldEnd]));
task("lint-scripts").description = "Runs eslint on the scripts sources.";

const lintCompiler = eslint("src");
lintCompiler.displayName = "lint-compiler";
task("lint-compiler", series([buildEslintRules, lintFoldStart, lintCompiler, lintFoldEnd]));
task("lint-compiler").description = "Runs eslint on the compiler sources.";
task("lint-compiler").flags = {
" --ci": "Runs eslint additional rules",
};

const lint = series([buildEslintRules, lintFoldStart, lintScripts, lintCompiler, lintFoldEnd]);
lint.displayName = "lint";
task("lint", series(buildRules, lint));
task("lint").description = "Runs tslint on the compiler sources.";
task("lint", series([buildEslintRules, lintFoldStart, lint, lintFoldEnd]));
task("lint").description = "Runs eslint on the compiler and scripts sources.";
task("lint").flags = {
" --f[iles]=<regex>": "pattern to match files to lint",
" --ci": "Runs eslint additional rules",
};

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

const preTest = parallel(buildRules, buildTests, buildServices, buildLssl);
const preTest = parallel(buildTests, buildServices, buildLssl);
preTest.displayName = "preTest";

const postTest = (done) => cmdLineOptions.lint ? lint(done) : done();
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -90,7 +90,7 @@ gulp runtests # Run tests using the built compiler and test infrastruct
gulp runtests-parallel # Like runtests, but split across multiple threads. Uses a number of threads equal to the system
# core count by default. Use --workers=<number> to adjust this.
gulp baseline-accept # This replaces the baseline test results with the results obtained from gulp runtests.
gulp lint # Runs tslint on the TypeScript source.
gulp lint # Runs eslint on the TypeScript source.
gulp help # List the above commands.
```

Expand Down
18 changes: 15 additions & 3 deletions package.json
Expand Up @@ -33,7 +33,6 @@
"@types/browserify": "latest",
"@types/chai": "latest",
"@types/convert-source-map": "latest",
"@types/del": "latest",
"@types/glob": "latest",
"@types/gulp": "^4.0.5",
"@types/gulp-concat": "latest",
Expand All @@ -55,15 +54,25 @@
"@types/through2": "latest",
"@types/travis-fold": "latest",
"@types/xml2js": "^0.4.0",
"@typescript-eslint/eslint-plugin": "2.2.0",
"@typescript-eslint/experimental-utils": "2.2.0",
"@typescript-eslint/parser": "2.2.0",
"async": "latest",
"azure-devops-node-api": "^8.0.0",
"browser-resolve": "^1.11.2",
"browserify": "latest",
"chai": "latest",
"chalk": "latest",
"convert-source-map": "latest",
"del": "latest",
"del": "5.1.0",
"eslint": "6.3.0",
"eslint-formatter-autolinkable-stylish": "1.0.3",
"eslint-plugin-import": "2.18.2",
"eslint-plugin-jsdoc": "15.9.1",
"eslint-plugin-no-null": "1.0.2",
"fancy-log": "latest",
"fs-extra": "^6.0.1",
"glob": "latest",
"gulp": "^4.0.0",
"gulp-concat": "latest",
"gulp-insert": "latest",
Expand All @@ -87,7 +96,6 @@
"source-map-support": "latest",
"through2": "latest",
"travis-fold": "latest",
"tslint": "latest",
"typescript": "next",
"vinyl": "latest",
"vinyl-sourcemaps-apply": "latest",
Expand All @@ -96,6 +104,7 @@
"scripts": {
"pretest": "gulp tests",
"test": "gulp runtests-parallel --light=false",
"test:eslint-rules": "gulp run-eslint-rules-tests",
"build": "npm run build:compiler && npm run build:tests",
"build:compiler": "gulp local",
"build:tests": "gulp tests",
Expand All @@ -104,6 +113,9 @@
"gulp": "gulp",
"jake": "gulp",
"lint": "gulp lint",
"lint:ci": "gulp lint --ci",
"lint:compiler": "gulp lint-compiler",
"lint:scripts": "gulp lint-scripts",
"setup-hooks": "node scripts/link-hooks.js",
"update-costly-tests": "node scripts/costly-tests.js"
},
Expand Down

0 comments on commit d7c83f0

Please sign in to comment.