Skip to content

Commit 9f7c0cb

Browse files
authored
Run ESLint over our JS files, fix all lints (microsoft#50172)
1 parent 03b12a6 commit 9f7c0cb

12 files changed

+44
-19
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
/tests/**
33
/lib/**
44
/src/lib/*.generated.d.ts
5+
/scripts/*.js
6+
/scripts/eslint/built/**

.eslintrc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
"plugins": [
1414
"@typescript-eslint", "jsdoc", "no-null", "import"
1515
],
16+
"overrides": [
17+
// By default, the ESLint CLI only looks at .js files. But, it will also look at
18+
// any files which are referenced in an override config. Most users of typescript-eslint
19+
// get this behavior by default by extending a recommended typescript-eslint config, which
20+
// just so happens to override some core ESLint rules. We don't extend from any config, so
21+
// explicitly reference TS files here so the CLI picks them up.
22+
//
23+
// ESLint in VS Code will lint any opened file (so long as it's not eslintignore'd), so
24+
// that will work regardless of the below.
25+
{ "files": ["*.ts"] }
26+
],
1627
"rules": {
1728
"@typescript-eslint/adjacent-overload-signatures": "error",
1829
"@typescript-eslint/array-type": "error",

.vscode/settings.template.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
],
77
"eslint.options": {
88
"rulePaths": ["./scripts/eslint/built/rules/"],
9-
"extensions": [".ts"]
109
},
1110
// To use the last-known-good (LKG) compiler version:
1211
// "typescript.tsdk": "lib"

Gulpfile.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ const eslint = (folder) => async () => {
358358
"--cache-location", `${folder}/.eslintcache`,
359359
"--format", formatter,
360360
"--rulesdir", "scripts/eslint/built/rules",
361-
"--ext", ".ts",
362361
];
363362

364363
if (cmdLineOptions.fix) {

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"typescript": "^4.5.5",
8989
"vinyl": "latest",
9090
"vinyl-sourcemaps-apply": "latest",
91+
"which": "^2.0.2",
9192
"xml2js": "^0.4.23"
9293
},
9394
"overrides": {

scripts/build/options.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = minimist(process.argv.slice(2), {
77
boolean: ["dirty", "light", "colors", "lint", "lkg", "soft", "fix", "failed", "keepFailed", "force", "built"],
88
string: ["browser", "tests", "break", "host", "reporter", "stackTraceLimit", "timeout", "shards", "shardId"],
99
alias: {
10+
/* eslint-disable quote-props */
1011
"b": "browser",
1112
"i": ["inspect", "inspect-brk", "break", "debug", "debug-brk"],
1213
"t": ["tests", "test"],
@@ -16,6 +17,7 @@ module.exports = minimist(process.argv.slice(2), {
1617
"skippercent": "skipPercent",
1718
"w": "workers",
1819
"f": "fix"
20+
/* eslint-enable quote-props */
1921
},
2022
default: {
2123
soft: false,

scripts/build/prepend.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @ts-check
22
const stream = require("stream");
3-
const Vinyl = require("vinyl");
43
const ts = require("../../lib/typescript");
54
const fs = require("fs");
65
const { base64VLQFormatEncode } = require("./sourcemaps");
@@ -43,13 +42,14 @@ function prepend(data) {
4342
sourcesContent: input.sourcesContent
4443
};
4544
}
45+
// eslint-disable-next-line boolean-trivia, no-null/no-null
4646
return cb(null, output);
4747
}
4848
catch (e) {
4949
return cb(e);
5050
}
5151
}
52-
})
52+
});
5353
}
5454
exports.prepend = prepend;
5555

@@ -59,6 +59,6 @@ exports.prepend = prepend;
5959
function prependFile(file) {
6060
const data = typeof file === "string" ? fs.readFileSync(file, "utf8") :
6161
vinyl => fs.readFileSync(file(vinyl), "utf8");
62-
return prepend(data)
62+
return prepend(data);
6363
}
64-
exports.prependFile = prependFile;
64+
exports.prependFile = prependFile;

scripts/build/projects.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ProjectQueue {
3535
}
3636
}
3737

38-
const execTsc = (lkg, ...args) =>
38+
const execTsc = (/** @type {boolean} */ lkg, /** @type {string[]} */ ...args) =>
3939
exec(process.execPath,
4040
[resolve(findUpRoot(), lkg ? "./lib/tsc" : "./built/local/tsc"),
4141
"-b", ...args],
@@ -45,7 +45,7 @@ const projectBuilder = new ProjectQueue((projects, lkg, force) => execTsc(lkg, .
4545

4646
/**
4747
* @param {string} project
48-
* @param {object} [options]
48+
* @param {object} options
4949
* @param {boolean} [options.lkg=true]
5050
* @param {boolean} [options.force=false]
5151
*/
@@ -58,11 +58,11 @@ const projectCleaner = new ProjectQueue((projects, lkg) => execTsc(lkg, "--clean
5858
*/
5959
exports.cleanProject = (project) => projectCleaner.enqueue(project);
6060

61-
const projectWatcher = new ProjectQueue((projects) => execTsc(true, "--watch", ...projects));
61+
const projectWatcher = new ProjectQueue((projects) => execTsc(/*lkg*/ true, "--watch", ...projects));
6262

6363
/**
6464
* @param {string} project
65-
* @param {object} [options]
65+
* @param {object} options
6666
* @param {boolean} [options.lkg=true]
6767
*/
6868
exports.watchProject = (project, { lkg } = {}) => projectWatcher.enqueue(project, { lkg });

scripts/build/sourcemaps.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ function base64VLQFormatEncode(value) {
4545

4646
return result;
4747
}
48-
exports.base64VLQFormatEncode = base64VLQFormatEncode;
48+
exports.base64VLQFormatEncode = base64VLQFormatEncode;
49+
50+
/** @typedef {object} RawSourceMap */

scripts/build/tests.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ exports.localTest262Baseline = "internal/baselines/test262/local";
2727
*/
2828
async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode, cancelToken = CancellationToken.none) {
2929
let testTimeout = cmdLineOptions.timeout;
30-
let tests = cmdLineOptions.tests;
30+
const tests = cmdLineOptions.tests;
3131
const inspect = cmdLineOptions.break || cmdLineOptions.inspect;
3232
const runners = cmdLineOptions.runners;
3333
const light = cmdLineOptions.light;
@@ -72,7 +72,7 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode,
7272
const reporter = cmdLineOptions.reporter || defaultReporter;
7373

7474
/** @type {string[]} */
75-
let args = [];
75+
const args = [];
7676

7777
// timeout normally isn't necessary but Travis-CI has been timing out on compiler baselines occasionally
7878
// default timeout is 2sec which really should be enough, but maybe we just need a small amount longer
@@ -101,7 +101,7 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode,
101101
args.push("--no-colors");
102102
}
103103
if (inspect !== undefined) {
104-
args.unshift((inspect == "" || inspect === true) ? "--inspect-brk" : "--inspect-brk="+inspect);
104+
args.unshift((inspect === "" || inspect === true) ? "--inspect-brk" : "--inspect-brk="+inspect);
105105
args.push("-t", "0");
106106
}
107107
else {
@@ -160,7 +160,7 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode,
160160
exports.runConsoleTests = runConsoleTests;
161161

162162
async function cleanTestDirs() {
163-
await del([exports.localBaseline, exports.localRwcBaseline])
163+
await del([exports.localBaseline, exports.localRwcBaseline]);
164164
mkdirP.sync(exports.localRwcBaseline);
165165
mkdirP.sync(exports.localBaseline);
166166
}
@@ -214,5 +214,5 @@ function deleteTemporaryProjectOutput() {
214214
}
215215

216216
function regExpEscape(text) {
217-
return text.replace(/[.*+?^${}()|\[\]\\]/g, '\\$&');
217+
return text.replace(/[.*+?^${}()|\[\]\\]/g, "\\$&");
218218
}

scripts/build/utils.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// @ts-check
2+
3+
/* eslint-disable no-restricted-globals */
4+
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
25
/// <reference path="../types/ambient.d.ts" />
36

47
const fs = require("fs");
@@ -128,6 +131,7 @@ function streamFromBuffer(buffer) {
128131
return new Readable({
129132
read() {
130133
this.push(buffer);
134+
// eslint-disable-next-line no-null/no-null
131135
this.push(null);
132136
}
133137
});
@@ -249,7 +253,7 @@ function flatten(projectSpec, flattenedProjectSpec, options = {}) {
249253
const files = [];
250254
const resolvedOutputSpec = path.resolve(cwd, flattenedProjectSpec);
251255
const resolvedOutputDirectory = path.dirname(resolvedOutputSpec);
252-
const resolvedProjectSpec = resolveProjectSpec(projectSpec, cwd, undefined);
256+
const resolvedProjectSpec = resolveProjectSpec(projectSpec, cwd, /*referrer*/ undefined);
253257
const project = readJson(resolvedProjectSpec);
254258
const skipProjects = /**@type {Set<string>}*/(new Set());
255259
const skipFiles = new Set(options && options.exclude && options.exclude.map(file => normalizeSlashes(path.resolve(cwd, file))));
@@ -310,7 +314,7 @@ function normalizeSlashes(file) {
310314
* @returns {string}
311315
*/
312316
function resolveProjectSpec(projectSpec, cwd, referrer) {
313-
let projectPath = normalizeSlashes(path.resolve(cwd, referrer ? path.dirname(referrer) : "", projectSpec));
317+
const projectPath = normalizeSlashes(path.resolve(cwd, referrer ? path.dirname(referrer) : "", projectSpec));
314318
const stats = fs.statSync(projectPath);
315319
if (stats.isFile()) return normalizeSlashes(projectPath);
316320
return normalizeSlashes(path.resolve(cwd, projectPath, "tsconfig.json"));
@@ -321,7 +325,10 @@ function resolveProjectSpec(projectSpec, cwd, referrer) {
321325
* @param {{ cwd?: string }} [opts]
322326
*/
323327
function rm(dest, opts) {
324-
if (dest && typeof dest === "object") opts = dest, dest = undefined;
328+
if (dest && typeof dest === "object") {
329+
opts = dest;
330+
dest = undefined;
331+
}
325332
let failed = false;
326333

327334
const cwd = path.resolve(opts && opts.cwd || process.cwd());
@@ -369,6 +376,7 @@ function rm(dest, opts) {
369376
pending.push(entry);
370377
},
371378
final(cb) {
379+
// eslint-disable-next-line no-null/no-null
372380
const endThenCb = () => (duplex.push(null), cb()); // signal end of read queue
373381
processDeleted();
374382
if (pending.length) {

0 commit comments

Comments
 (0)