From a37d34a5b66634363f4b67e7e910ae6300ae25a0 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 4 Aug 2019 14:27:55 +0300 Subject: [PATCH] lint src/, scripts/ folders separately --- .eslintrc => .eslintrc.json | 25 ++++----- Gulpfile.js | 16 +++--- package.json | 3 +- scripts/eslint/rules/simple-indent.ts | 12 ++--- scripts/eslint/tests/simple-indent.test.ts | 52 +++++++++---------- scripts/eslint/tests/support/RuleTester.ts | 4 +- scripts/tsconfig.json | 2 +- src/compiler/types.ts | 2 +- src/testRunner/unittests/tsbuildWatchMode.ts | 8 +-- .../unittests/tscWatch/programUpdates.ts | 6 +-- tsconfig.eslint.json | 14 ++--- 11 files changed, 70 insertions(+), 74 deletions(-) rename .eslintrc => .eslintrc.json (87%) diff --git a/.eslintrc b/.eslintrc.json similarity index 87% rename from .eslintrc rename to .eslintrc.json index 2504e4be1bd..fb4ebc210b2 100644 --- a/.eslintrc +++ b/.eslintrc.json @@ -21,14 +21,6 @@ "@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"], - "indent": "off", - "@typescript-eslint/indent": ["error", 4, { - "flatTernaryExpressions": true, - "FunctionDeclaration": { "parameters": 1, "body": 1 }, - "CallExpression": { "arguments": 1 }, - "ignoredNodes": ["TSTypeAnnotation"], - "SwitchCase": 1 - }], "@typescript-eslint/interface-name-prefix": "error", "@typescript-eslint/no-inferrable-types": "error", "@typescript-eslint/no-misused-new": "error", @@ -44,7 +36,7 @@ "@typescript-eslint/type-annotation-spacing": "error", "@typescript-eslint/unified-signatures": "error", - /** scripts/eslint/rules */ + // scripts/eslint/rules "object-literal-surrounding-space": "error", "no-type-assertion-whitespace": "error", "type-operator-spacing": "error", @@ -55,19 +47,20 @@ "no-double-space": "error", "boolean-trivia": "error", "no-in-operator": "error", + "simple-indent": "error", "debug-assert": "error", "no-keywords": "error", - /** eslint-plugin-import */ + // eslint-plugin-import "import/no-extraneous-dependencies": ["error", { "optionalDependencies": false }], - /** eslint-plugin-no-null */ + // eslint-plugin-no-null "no-null/no-null": "error", - /** eslint-plugin-jsdoc */ + // eslint-plugin-jsdoc "jsdoc/check-alignment": "error", - /** eslint */ + // eslint "brace-style": ["error", "stroustrup", { "allowSingleLine": true }], "constructor-super": "error", "curly": ["error", "multi-line"], @@ -109,7 +102,7 @@ "quotes": ["error", "double", { "avoidEscape": true, "allowTemplateLiterals": true }], "space-in-parens": "error", "unicode-bom": ["error", "never"], - "use-isnan": "error", + "use-isnan": "error" }, "overrides": [{ "files": ["src/lib/*.d.ts"], @@ -118,10 +111,10 @@ "@typescript-eslint/prefer-function-type": "off", "@typescript-eslint/unified-signatures": "off", - /** scripts/eslint/rules */ + // scripts/eslint/rules "no-keywords": "off", - /** eslint */ + // eslint "no-var": "off" } }] diff --git a/Gulpfile.js b/Gulpfile.js index d234e393f26..4c04cfc8571 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -333,13 +333,13 @@ task("run-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 eslint = async () => { +const eslint = (path) => async () => { const args = [ "node_modules/eslint/bin/eslint", "--format", "autolinkable-stylish", - "--config", ".eslintrc", - "--ext", ".ts", ".", "--rulesdir", "built/eslint/rules/", + "--ext", ".ts", + `"${ path }"`, ]; if (cmdLineOptions.fix) { @@ -350,13 +350,15 @@ const eslint = async () => { return exec(process.execPath, args); } -const lint = series([buildRules, lintFoldStart, eslint, lintFoldEnd]); +const lintScripts = series([buildRules, eslint("scripts/**/*.ts")]); +lintScripts.displayName = "lint-scripts"; +task("lint-scripts", lintScripts); +task("lint-scripts").description = "Runs eslint on the scripts sources."; + +const lint = series([buildRules, lintFoldStart, eslint("src/**/*.ts"), lintFoldEnd]); lint.displayName = "lint"; task("lint", lint); task("lint").description = "Runs eslint on the compiler sources."; -task("lint").flags = { - " --f[iles]=": "pattern to match files to lint", -}; const buildCancellationToken = () => buildProject("src/cancellationToken"); const cleanCancellationToken = () => cleanProject("src/cancellationToken"); diff --git a/package.json b/package.json index e4f02ee9942..1c13a4ea7b9 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,7 @@ "scripts": { "pretest": "gulp tests", "test": "gulp runtests-parallel --light=false", + "test:eslint-rules": "gulp run-rules-tests", "build": "npm run build:compiler && npm run build:tests", "build:compiler": "gulp local", "build:tests": "gulp tests", @@ -112,7 +113,7 @@ "gulp": "gulp", "jake": "gulp", "lint": "gulp lint", - "lint:test": "gulp run-rules-tests", + "lint:scripts": "gulp lint-scripts", "setup-hooks": "node scripts/link-hooks.js", "update-costly-tests": "node scripts/costly-tests.js" }, diff --git a/scripts/eslint/rules/simple-indent.ts b/scripts/eslint/rules/simple-indent.ts index d9ab40d5252..7ae5dc0190a 100644 --- a/scripts/eslint/rules/simple-indent.ts +++ b/scripts/eslint/rules/simple-indent.ts @@ -1,4 +1,4 @@ -import { TSESTree } from "@typescript-eslint/typescript-estree"; +import { TSESTree } from "@typescript-eslint/experimental-utils"; import { createRule } from "./utils"; type MessageId = "simpleIndentError"; @@ -15,7 +15,7 @@ export = createRule({ messages: { simpleIndentError: "4 space indentation expected", }, - fixable: 'whitespace', + fixable: "whitespace", schema: [], type: "layout", }, @@ -29,8 +29,8 @@ export = createRule({ const checkIndent = (node: TSESTree.Program) => { const lines = sourceCode.getLines(); const linesLen = lines.length; - let totalLen = 0; + let totalLen = 0; for (let i = 0; i < linesLen; i++) { const lineNumber = i + 1; const line = lines[i]; @@ -48,7 +48,7 @@ export = createRule({ } context.report({ - messageId: 'simpleIndentError', + messageId: "simpleIndentError", node, loc: { column: indentEnd, line: lineNumber }, fix(fixer) { @@ -63,10 +63,10 @@ export = createRule({ totalLen += lineLen; } - } + }; return { Program: checkIndent, - } + }; }, }); diff --git a/scripts/eslint/tests/simple-indent.test.ts b/scripts/eslint/tests/simple-indent.test.ts index af655a4cfcf..161755c366b 100644 --- a/scripts/eslint/tests/simple-indent.test.ts +++ b/scripts/eslint/tests/simple-indent.test.ts @@ -104,7 +104,7 @@ module TestModule { } `, errors: [ - { messageId: 'simpleIndentError', line: 3, column: 2 }, + { messageId: "simpleIndentError", line: 3, column: 2 }, ], }, { @@ -112,14 +112,14 @@ module TestModule { function a() { \t\tvar test = 123; } - `, + `, output: ` function a() { var test = 123; } - `, + `, errors: [ - { messageId: 'simpleIndentError', line: 3, column: 3 }, + { messageId: "simpleIndentError", line: 3, column: 3 }, ], }, { @@ -142,10 +142,10 @@ class TestClass { } `, errors: [ - { messageId: 'simpleIndentError', line: 3, column: 2 }, - { messageId: 'simpleIndentError', line: 5, column: 2 }, - { messageId: 'simpleIndentError', line: 6, column: 3 }, - { messageId: 'simpleIndentError', line: 7, column: 2 }, + { messageId: "simpleIndentError", line: 3, column: 2 }, + { messageId: "simpleIndentError", line: 5, column: 2 }, + { messageId: "simpleIndentError", line: 6, column: 3 }, + { messageId: "simpleIndentError", line: 7, column: 2 }, ], }, { @@ -164,9 +164,9 @@ var obj = { }; `, errors: [ - { messageId: 'simpleIndentError', line: 3, column: 2 }, - { messageId: 'simpleIndentError', line: 4, column: 2 }, - { messageId: 'simpleIndentError', line: 5, column: 2 }, + { messageId: "simpleIndentError", line: 3, column: 2 }, + { messageId: "simpleIndentError", line: 4, column: 2 }, + { messageId: "simpleIndentError", line: 5, column: 2 }, ] }, { @@ -183,7 +183,7 @@ enum TestEnum { } `, errors: [ - { messageId: 'simpleIndentError', line: 3, column: 2 }, + { messageId: "simpleIndentError", line: 3, column: 2 }, ], }, { @@ -214,12 +214,12 @@ switch (integerValue) { } `, errors: [ - { messageId: 'simpleIndentError', line: 3, column: 2 }, - { messageId: 'simpleIndentError', line: 4, column: 3 }, - { messageId: 'simpleIndentError', line: 5, column: 3 }, - { messageId: 'simpleIndentError', line: 9, column: 2 }, - { messageId: 'simpleIndentError', line: 10, column: 3 }, - { messageId: 'simpleIndentError', line: 11, column: 3 }, + { messageId: "simpleIndentError", line: 3, column: 2 }, + { messageId: "simpleIndentError", line: 4, column: 3 }, + { messageId: "simpleIndentError", line: 5, column: 3 }, + { messageId: "simpleIndentError", line: 9, column: 2 }, + { messageId: "simpleIndentError", line: 10, column: 3 }, + { messageId: "simpleIndentError", line: 11, column: 3 }, ] }, { @@ -234,8 +234,8 @@ for (var i = 0; i < 1; ++i) { } `, errors: [ - { messageId: 'simpleIndentError', line: 3, column: 2 }, - ] + { messageId: "simpleIndentError", line: 3, column: 2 }, + ], }, { code: ` @@ -249,7 +249,7 @@ while (i < 1) { } `, errors: [ - { messageId: 'simpleIndentError', line: 3, column: 2 }, + { messageId: "simpleIndentError", line: 3, column: 2 }, ] }, { @@ -264,7 +264,7 @@ do { } while (i < 1); `, errors: [ - { messageId: 'simpleIndentError', line: 3, column: 2 }, + { messageId: "simpleIndentError", line: 3, column: 2 }, ] }, { @@ -279,7 +279,7 @@ if (i < 1) { } `, errors: [ - { messageId: 'simpleIndentError', line: 3, column: 2 }, + { messageId: "simpleIndentError", line: 3, column: 2 }, ] }, { @@ -296,7 +296,7 @@ var arr = [ ]; `, errors: [ - { messageId: 'simpleIndentError', line: 3, column: 2 }, + { messageId: "simpleIndentError", line: 3, column: 2 }, ] }, { @@ -325,8 +325,8 @@ var arr2 = [ ]; `, errors: [ - { messageId: 'simpleIndentError', line: 4, column: 3 }, - { messageId: 'simpleIndentError', line: 9, column: 3 }, + { messageId: "simpleIndentError", line: 4, column: 3 }, + { messageId: "simpleIndentError", line: 9, column: 3 }, ] } ], diff --git a/scripts/eslint/tests/support/RuleTester.ts b/scripts/eslint/tests/support/RuleTester.ts index 6c87329981f..adbae651d2d 100644 --- a/scripts/eslint/tests/support/RuleTester.ts +++ b/scripts/eslint/tests/support/RuleTester.ts @@ -1,6 +1,6 @@ import * as path from "path"; import { TSESLint } from "@typescript-eslint/experimental-utils"; -export const ROOT_DIR = path.join(process.cwd(), 'scripts', 'eslint', 'tests', 'fixtures'); -export const FILENAME = path.join(ROOT_DIR, 'file.ts'); +export const ROOT_DIR = path.join(process.cwd(), "scripts", "eslint", "tests", "fixtures"); +export const FILENAME = path.join(ROOT_DIR, "file.ts"); export const RuleTester = TSESLint.RuleTester; diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index f158359f07e..ed805def651 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -21,4 +21,4 @@ "configurePrerelease.ts", "word2md.ts" ] -} \ No newline at end of file +} diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 78c8f5a3e13..001975ad2ee 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -5917,7 +5917,7 @@ namespace ts { // If fileName is provided, gets all the diagnostics associated with that file name. // Otherwise, returns all the diagnostics (global and file associated) in this collection. getDiagnostics(): Diagnostic[]; - getDiagnostics(fileName: string): DiagnosticWithLocation[]; + getDiagnostics(fileName: string): DiagnosticWithLocation[]; // eslint-disable-line @typescript-eslint/unified-signatures reattachFileDiagnostics(newFile: SourceFile): void; } diff --git a/src/testRunner/unittests/tsbuildWatchMode.ts b/src/testRunner/unittests/tsbuildWatchMode.ts index 067befd6387..ce58a80a5f3 100644 --- a/src/testRunner/unittests/tsbuildWatchMode.ts +++ b/src/testRunner/unittests/tsbuildWatchMode.ts @@ -422,14 +422,14 @@ function myFunc() { return 100; }`, /*isLocal*/ true); content: ` interface SomeObject { - message: string; + message: string; } export function createSomeObject(): SomeObject { - return { - message: "new Object" - }; + return { + message: "new Object" + }; }` }; const libraryTsconfig: File = { diff --git a/src/testRunner/unittests/tscWatch/programUpdates.ts b/src/testRunner/unittests/tscWatch/programUpdates.ts index 3fd54264260..f9e6f0ae986 100644 --- a/src/testRunner/unittests/tscWatch/programUpdates.ts +++ b/src/testRunner/unittests/tscWatch/programUpdates.ts @@ -1146,7 +1146,7 @@ foo().hello` const currentDirectory = "/user/username/projects/myproject"; const field = "fullscreen"; const fieldWithoutReadonly = `interface Document { - ${field}: boolean; + ${field}: boolean; }`; const libFileWithDocument: File = { @@ -1227,13 +1227,13 @@ var y: number; const aFile: File = { path: `${currentDirectory}/a.ts`, content: `interface Document { - ${field}: boolean; + ${field}: boolean; }` }; const bFile: File = { path: `${currentDirectory}/b.d.ts`, content: `interface Document { - ${field}: boolean; + ${field}: boolean; }` }; const libFileWithDocument: File = { diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index a9a2de7c864..4cfd6ea1ab2 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -1,7 +1,7 @@ -{ - "extends": "./src/tsconfig-base.json", - "include": [ - "src/**/*.ts", - "scripts/**/*.ts", - ] -} \ No newline at end of file +{ + "extends": "./src/tsconfig-base.json", + "include": [ + "src/**/*", + "scripts/**/*" + ] +}