Skip to content

Commit a37d34a

Browse files
committed
lint src/, scripts/ folders separately
1 parent ee90fdb commit a37d34a

11 files changed

Lines changed: 70 additions & 74 deletions

File tree

.eslintrc renamed to .eslintrc.json

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@
2121
"@typescript-eslint/camelcase": ["error", { "properties": "never", "allow": ["^[A-Za-z][a-zA-Za-z]+_[A-Za-z]+$"] }],
2222
"@typescript-eslint/class-name-casing": "error",
2323
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
24-
"indent": "off",
25-
"@typescript-eslint/indent": ["error", 4, {
26-
"flatTernaryExpressions": true,
27-
"FunctionDeclaration": { "parameters": 1, "body": 1 },
28-
"CallExpression": { "arguments": 1 },
29-
"ignoredNodes": ["TSTypeAnnotation"],
30-
"SwitchCase": 1
31-
}],
3224
"@typescript-eslint/interface-name-prefix": "error",
3325
"@typescript-eslint/no-inferrable-types": "error",
3426
"@typescript-eslint/no-misused-new": "error",
@@ -44,7 +36,7 @@
4436
"@typescript-eslint/type-annotation-spacing": "error",
4537
"@typescript-eslint/unified-signatures": "error",
4638

47-
/** scripts/eslint/rules */
39+
// scripts/eslint/rules
4840
"object-literal-surrounding-space": "error",
4941
"no-type-assertion-whitespace": "error",
5042
"type-operator-spacing": "error",
@@ -55,19 +47,20 @@
5547
"no-double-space": "error",
5648
"boolean-trivia": "error",
5749
"no-in-operator": "error",
50+
"simple-indent": "error",
5851
"debug-assert": "error",
5952
"no-keywords": "error",
6053

61-
/** eslint-plugin-import */
54+
// eslint-plugin-import
6255
"import/no-extraneous-dependencies": ["error", { "optionalDependencies": false }],
6356

64-
/** eslint-plugin-no-null */
57+
// eslint-plugin-no-null
6558
"no-null/no-null": "error",
6659

67-
/** eslint-plugin-jsdoc */
60+
// eslint-plugin-jsdoc
6861
"jsdoc/check-alignment": "error",
6962

70-
/** eslint */
63+
// eslint
7164
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
7265
"constructor-super": "error",
7366
"curly": ["error", "multi-line"],
@@ -109,7 +102,7 @@
109102
"quotes": ["error", "double", { "avoidEscape": true, "allowTemplateLiterals": true }],
110103
"space-in-parens": "error",
111104
"unicode-bom": ["error", "never"],
112-
"use-isnan": "error",
105+
"use-isnan": "error"
113106
},
114107
"overrides": [{
115108
"files": ["src/lib/*.d.ts"],
@@ -118,10 +111,10 @@
118111
"@typescript-eslint/prefer-function-type": "off",
119112
"@typescript-eslint/unified-signatures": "off",
120113

121-
/** scripts/eslint/rules */
114+
// scripts/eslint/rules
122115
"no-keywords": "off",
123116

124-
/** eslint */
117+
// eslint
125118
"no-var": "off"
126119
}
127120
}]

Gulpfile.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,13 @@ task("run-rules-tests").description = "Runs the eslint rule tests";
333333

334334
const lintFoldStart = async () => { if (fold.isTravis()) console.log(fold.start("lint")); };
335335
const lintFoldEnd = async () => { if (fold.isTravis()) console.log(fold.end("lint")); };
336-
const eslint = async () => {
336+
const eslint = (path) => async () => {
337337
const args = [
338338
"node_modules/eslint/bin/eslint",
339339
"--format", "autolinkable-stylish",
340-
"--config", ".eslintrc",
341-
"--ext", ".ts", ".",
342340
"--rulesdir", "built/eslint/rules/",
341+
"--ext", ".ts",
342+
`"${ path }"`,
343343
];
344344

345345
if (cmdLineOptions.fix) {
@@ -350,13 +350,15 @@ const eslint = async () => {
350350
return exec(process.execPath, args);
351351
}
352352

353-
const lint = series([buildRules, lintFoldStart, eslint, lintFoldEnd]);
353+
const lintScripts = series([buildRules, eslint("scripts/**/*.ts")]);
354+
lintScripts.displayName = "lint-scripts";
355+
task("lint-scripts", lintScripts);
356+
task("lint-scripts").description = "Runs eslint on the scripts sources.";
357+
358+
const lint = series([buildRules, lintFoldStart, eslint("src/**/*.ts"), lintFoldEnd]);
354359
lint.displayName = "lint";
355360
task("lint", lint);
356361
task("lint").description = "Runs eslint on the compiler sources.";
357-
task("lint").flags = {
358-
" --f[iles]=<regex>": "pattern to match files to lint",
359-
};
360362

361363
const buildCancellationToken = () => buildProject("src/cancellationToken");
362364
const cleanCancellationToken = () => cleanProject("src/cancellationToken");

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"scripts": {
105105
"pretest": "gulp tests",
106106
"test": "gulp runtests-parallel --light=false",
107+
"test:eslint-rules": "gulp run-rules-tests",
107108
"build": "npm run build:compiler && npm run build:tests",
108109
"build:compiler": "gulp local",
109110
"build:tests": "gulp tests",
@@ -112,7 +113,7 @@
112113
"gulp": "gulp",
113114
"jake": "gulp",
114115
"lint": "gulp lint",
115-
"lint:test": "gulp run-rules-tests",
116+
"lint:scripts": "gulp lint-scripts",
116117
"setup-hooks": "node scripts/link-hooks.js",
117118
"update-costly-tests": "node scripts/costly-tests.js"
118119
},

scripts/eslint/rules/simple-indent.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TSESTree } from "@typescript-eslint/typescript-estree";
1+
import { TSESTree } from "@typescript-eslint/experimental-utils";
22
import { createRule } from "./utils";
33

44
type MessageId = "simpleIndentError";
@@ -15,7 +15,7 @@ export = createRule<Options, MessageId>({
1515
messages: {
1616
simpleIndentError: "4 space indentation expected",
1717
},
18-
fixable: 'whitespace',
18+
fixable: "whitespace",
1919
schema: [],
2020
type: "layout",
2121
},
@@ -29,8 +29,8 @@ export = createRule<Options, MessageId>({
2929
const checkIndent = (node: TSESTree.Program) => {
3030
const lines = sourceCode.getLines();
3131
const linesLen = lines.length;
32-
let totalLen = 0;
3332

33+
let totalLen = 0;
3434
for (let i = 0; i < linesLen; i++) {
3535
const lineNumber = i + 1;
3636
const line = lines[i];
@@ -48,7 +48,7 @@ export = createRule<Options, MessageId>({
4848
}
4949

5050
context.report({
51-
messageId: 'simpleIndentError',
51+
messageId: "simpleIndentError",
5252
node,
5353
loc: { column: indentEnd, line: lineNumber },
5454
fix(fixer) {
@@ -63,10 +63,10 @@ export = createRule<Options, MessageId>({
6363

6464
totalLen += lineLen;
6565
}
66-
}
66+
};
6767

6868
return {
6969
Program: checkIndent,
70-
}
70+
};
7171
},
7272
});

scripts/eslint/tests/simple-indent.test.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,22 @@ module TestModule {
104104
}
105105
`,
106106
errors: [
107-
{ messageId: 'simpleIndentError', line: 3, column: 2 },
107+
{ messageId: "simpleIndentError", line: 3, column: 2 },
108108
],
109109
},
110110
{
111111
code: `
112112
function a() {
113113
\t\tvar test = 123;
114114
}
115-
`,
115+
`,
116116
output: `
117117
function a() {
118118
var test = 123;
119119
}
120-
`,
120+
`,
121121
errors: [
122-
{ messageId: 'simpleIndentError', line: 3, column: 3 },
122+
{ messageId: "simpleIndentError", line: 3, column: 3 },
123123
],
124124
},
125125
{
@@ -142,10 +142,10 @@ class TestClass {
142142
}
143143
`,
144144
errors: [
145-
{ messageId: 'simpleIndentError', line: 3, column: 2 },
146-
{ messageId: 'simpleIndentError', line: 5, column: 2 },
147-
{ messageId: 'simpleIndentError', line: 6, column: 3 },
148-
{ messageId: 'simpleIndentError', line: 7, column: 2 },
145+
{ messageId: "simpleIndentError", line: 3, column: 2 },
146+
{ messageId: "simpleIndentError", line: 5, column: 2 },
147+
{ messageId: "simpleIndentError", line: 6, column: 3 },
148+
{ messageId: "simpleIndentError", line: 7, column: 2 },
149149
],
150150
},
151151
{
@@ -164,9 +164,9 @@ var obj = {
164164
};
165165
`,
166166
errors: [
167-
{ messageId: 'simpleIndentError', line: 3, column: 2 },
168-
{ messageId: 'simpleIndentError', line: 4, column: 2 },
169-
{ messageId: 'simpleIndentError', line: 5, column: 2 },
167+
{ messageId: "simpleIndentError", line: 3, column: 2 },
168+
{ messageId: "simpleIndentError", line: 4, column: 2 },
169+
{ messageId: "simpleIndentError", line: 5, column: 2 },
170170
]
171171
},
172172
{
@@ -183,7 +183,7 @@ enum TestEnum {
183183
}
184184
`,
185185
errors: [
186-
{ messageId: 'simpleIndentError', line: 3, column: 2 },
186+
{ messageId: "simpleIndentError", line: 3, column: 2 },
187187
],
188188
},
189189
{
@@ -214,12 +214,12 @@ switch (integerValue) {
214214
}
215215
`,
216216
errors: [
217-
{ messageId: 'simpleIndentError', line: 3, column: 2 },
218-
{ messageId: 'simpleIndentError', line: 4, column: 3 },
219-
{ messageId: 'simpleIndentError', line: 5, column: 3 },
220-
{ messageId: 'simpleIndentError', line: 9, column: 2 },
221-
{ messageId: 'simpleIndentError', line: 10, column: 3 },
222-
{ messageId: 'simpleIndentError', line: 11, column: 3 },
217+
{ messageId: "simpleIndentError", line: 3, column: 2 },
218+
{ messageId: "simpleIndentError", line: 4, column: 3 },
219+
{ messageId: "simpleIndentError", line: 5, column: 3 },
220+
{ messageId: "simpleIndentError", line: 9, column: 2 },
221+
{ messageId: "simpleIndentError", line: 10, column: 3 },
222+
{ messageId: "simpleIndentError", line: 11, column: 3 },
223223
]
224224
},
225225
{
@@ -234,8 +234,8 @@ for (var i = 0; i < 1; ++i) {
234234
}
235235
`,
236236
errors: [
237-
{ messageId: 'simpleIndentError', line: 3, column: 2 },
238-
]
237+
{ messageId: "simpleIndentError", line: 3, column: 2 },
238+
],
239239
},
240240
{
241241
code: `
@@ -249,7 +249,7 @@ while (i < 1) {
249249
}
250250
`,
251251
errors: [
252-
{ messageId: 'simpleIndentError', line: 3, column: 2 },
252+
{ messageId: "simpleIndentError", line: 3, column: 2 },
253253
]
254254
},
255255
{
@@ -264,7 +264,7 @@ do {
264264
} while (i < 1);
265265
`,
266266
errors: [
267-
{ messageId: 'simpleIndentError', line: 3, column: 2 },
267+
{ messageId: "simpleIndentError", line: 3, column: 2 },
268268
]
269269
},
270270
{
@@ -279,7 +279,7 @@ if (i < 1) {
279279
}
280280
`,
281281
errors: [
282-
{ messageId: 'simpleIndentError', line: 3, column: 2 },
282+
{ messageId: "simpleIndentError", line: 3, column: 2 },
283283
]
284284
},
285285
{
@@ -296,7 +296,7 @@ var arr = [
296296
];
297297
`,
298298
errors: [
299-
{ messageId: 'simpleIndentError', line: 3, column: 2 },
299+
{ messageId: "simpleIndentError", line: 3, column: 2 },
300300
]
301301
},
302302
{
@@ -325,8 +325,8 @@ var arr2 = [
325325
];
326326
`,
327327
errors: [
328-
{ messageId: 'simpleIndentError', line: 4, column: 3 },
329-
{ messageId: 'simpleIndentError', line: 9, column: 3 },
328+
{ messageId: "simpleIndentError", line: 4, column: 3 },
329+
{ messageId: "simpleIndentError", line: 9, column: 3 },
330330
]
331331
}
332332
],
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from "path";
22
import { TSESLint } from "@typescript-eslint/experimental-utils";
33

4-
export const ROOT_DIR = path.join(process.cwd(), 'scripts', 'eslint', 'tests', 'fixtures');
5-
export const FILENAME = path.join(ROOT_DIR, 'file.ts');
4+
export const ROOT_DIR = path.join(process.cwd(), "scripts", "eslint", "tests", "fixtures");
5+
export const FILENAME = path.join(ROOT_DIR, "file.ts");
66
export const RuleTester = TSESLint.RuleTester;

scripts/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
"configurePrerelease.ts",
2222
"word2md.ts"
2323
]
24-
}
24+
}

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5917,7 +5917,7 @@ namespace ts {
59175917
// If fileName is provided, gets all the diagnostics associated with that file name.
59185918
// Otherwise, returns all the diagnostics (global and file associated) in this collection.
59195919
getDiagnostics(): Diagnostic[];
5920-
getDiagnostics(fileName: string): DiagnosticWithLocation[];
5920+
getDiagnostics(fileName: string): DiagnosticWithLocation[]; // eslint-disable-line @typescript-eslint/unified-signatures
59215921

59225922
reattachFileDiagnostics(newFile: SourceFile): void;
59235923
}

src/testRunner/unittests/tsbuildWatchMode.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,14 @@ function myFunc() { return 100; }`, /*isLocal*/ true);
422422
content: `
423423
interface SomeObject
424424
{
425-
message: string;
425+
message: string;
426426
}
427427
428428
export function createSomeObject(): SomeObject
429429
{
430-
return {
431-
message: "new Object"
432-
};
430+
return {
431+
message: "new Object"
432+
};
433433
}`
434434
};
435435
const libraryTsconfig: File = {

src/testRunner/unittests/tscWatch/programUpdates.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ foo().hello`
11461146
const currentDirectory = "/user/username/projects/myproject";
11471147
const field = "fullscreen";
11481148
const fieldWithoutReadonly = `interface Document {
1149-
${field}: boolean;
1149+
${field}: boolean;
11501150
}`;
11511151

11521152
const libFileWithDocument: File = {
@@ -1227,13 +1227,13 @@ var y: number;
12271227
const aFile: File = {
12281228
path: `${currentDirectory}/a.ts`,
12291229
content: `interface Document {
1230-
${field}: boolean;
1230+
${field}: boolean;
12311231
}`
12321232
};
12331233
const bFile: File = {
12341234
path: `${currentDirectory}/b.d.ts`,
12351235
content: `interface Document {
1236-
${field}: boolean;
1236+
${field}: boolean;
12371237
}`
12381238
};
12391239
const libFileWithDocument: File = {

0 commit comments

Comments
 (0)