Skip to content

Commit

Permalink
Run ESLint over our JS files, fix all lints (#50172)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey authored Aug 15, 2022
1 parent 03b12a6 commit 9f7c0cb
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/tests/**
/lib/**
/src/lib/*.generated.d.ts
/scripts/*.js
/scripts/eslint/built/**
11 changes: 11 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
"plugins": [
"@typescript-eslint", "jsdoc", "no-null", "import"
],
"overrides": [
// By default, the ESLint CLI only looks at .js files. But, it will also look at
// any files which are referenced in an override config. Most users of typescript-eslint
// get this behavior by default by extending a recommended typescript-eslint config, which
// just so happens to override some core ESLint rules. We don't extend from any config, so
// explicitly reference TS files here so the CLI picks them up.
//
// ESLint in VS Code will lint any opened file (so long as it's not eslintignore'd), so
// that will work regardless of the below.
{ "files": ["*.ts"] }
],
"rules": {
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
Expand Down
1 change: 0 additions & 1 deletion .vscode/settings.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
],
"eslint.options": {
"rulePaths": ["./scripts/eslint/built/rules/"],
"extensions": [".ts"]
},
// To use the last-known-good (LKG) compiler version:
// "typescript.tsdk": "lib"
Expand Down
1 change: 0 additions & 1 deletion Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ const eslint = (folder) => async () => {
"--cache-location", `${folder}/.eslintcache`,
"--format", formatter,
"--rulesdir", "scripts/eslint/built/rules",
"--ext", ".ts",
];

if (cmdLineOptions.fix) {
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"typescript": "^4.5.5",
"vinyl": "latest",
"vinyl-sourcemaps-apply": "latest",
"which": "^2.0.2",
"xml2js": "^0.4.23"
},
"overrides": {
Expand Down
2 changes: 2 additions & 0 deletions scripts/build/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = minimist(process.argv.slice(2), {
boolean: ["dirty", "light", "colors", "lint", "lkg", "soft", "fix", "failed", "keepFailed", "force", "built"],
string: ["browser", "tests", "break", "host", "reporter", "stackTraceLimit", "timeout", "shards", "shardId"],
alias: {
/* eslint-disable quote-props */
"b": "browser",
"i": ["inspect", "inspect-brk", "break", "debug", "debug-brk"],
"t": ["tests", "test"],
Expand All @@ -16,6 +17,7 @@ module.exports = minimist(process.argv.slice(2), {
"skippercent": "skipPercent",
"w": "workers",
"f": "fix"
/* eslint-enable quote-props */
},
default: {
soft: false,
Expand Down
8 changes: 4 additions & 4 deletions scripts/build/prepend.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @ts-check
const stream = require("stream");
const Vinyl = require("vinyl");
const ts = require("../../lib/typescript");
const fs = require("fs");
const { base64VLQFormatEncode } = require("./sourcemaps");
Expand Down Expand Up @@ -43,13 +42,14 @@ function prepend(data) {
sourcesContent: input.sourcesContent
};
}
// eslint-disable-next-line boolean-trivia, no-null/no-null
return cb(null, output);
}
catch (e) {
return cb(e);
}
}
})
});
}
exports.prepend = prepend;

Expand All @@ -59,6 +59,6 @@ exports.prepend = prepend;
function prependFile(file) {
const data = typeof file === "string" ? fs.readFileSync(file, "utf8") :
vinyl => fs.readFileSync(file(vinyl), "utf8");
return prepend(data)
return prepend(data);
}
exports.prependFile = prependFile;
exports.prependFile = prependFile;
8 changes: 4 additions & 4 deletions scripts/build/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ProjectQueue {
}
}

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

/**
* @param {string} project
* @param {object} [options]
* @param {object} options
* @param {boolean} [options.lkg=true]
* @param {boolean} [options.force=false]
*/
Expand All @@ -58,11 +58,11 @@ const projectCleaner = new ProjectQueue((projects, lkg) => execTsc(lkg, "--clean
*/
exports.cleanProject = (project) => projectCleaner.enqueue(project);

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

/**
* @param {string} project
* @param {object} [options]
* @param {object} options
* @param {boolean} [options.lkg=true]
*/
exports.watchProject = (project, { lkg } = {}) => projectWatcher.enqueue(project, { lkg });
4 changes: 3 additions & 1 deletion scripts/build/sourcemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ function base64VLQFormatEncode(value) {

return result;
}
exports.base64VLQFormatEncode = base64VLQFormatEncode;
exports.base64VLQFormatEncode = base64VLQFormatEncode;

/** @typedef {object} RawSourceMap */
10 changes: 5 additions & 5 deletions scripts/build/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exports.localTest262Baseline = "internal/baselines/test262/local";
*/
async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode, cancelToken = CancellationToken.none) {
let testTimeout = cmdLineOptions.timeout;
let tests = cmdLineOptions.tests;
const tests = cmdLineOptions.tests;
const inspect = cmdLineOptions.break || cmdLineOptions.inspect;
const runners = cmdLineOptions.runners;
const light = cmdLineOptions.light;
Expand Down Expand Up @@ -72,7 +72,7 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode,
const reporter = cmdLineOptions.reporter || defaultReporter;

/** @type {string[]} */
let args = [];
const args = [];

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

async function cleanTestDirs() {
await del([exports.localBaseline, exports.localRwcBaseline])
await del([exports.localBaseline, exports.localRwcBaseline]);
mkdirP.sync(exports.localRwcBaseline);
mkdirP.sync(exports.localBaseline);
}
Expand Down Expand Up @@ -214,5 +214,5 @@ function deleteTemporaryProjectOutput() {
}

function regExpEscape(text) {
return text.replace(/[.*+?^${}()|\[\]\\]/g, '\\$&');
return text.replace(/[.*+?^${}()|\[\]\\]/g, "\\$&");
}
14 changes: 11 additions & 3 deletions scripts/build/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @ts-check

/* eslint-disable no-restricted-globals */
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../types/ambient.d.ts" />

const fs = require("fs");
Expand Down Expand Up @@ -128,6 +131,7 @@ function streamFromBuffer(buffer) {
return new Readable({
read() {
this.push(buffer);
// eslint-disable-next-line no-null/no-null
this.push(null);
}
});
Expand Down Expand Up @@ -249,7 +253,7 @@ function flatten(projectSpec, flattenedProjectSpec, options = {}) {
const files = [];
const resolvedOutputSpec = path.resolve(cwd, flattenedProjectSpec);
const resolvedOutputDirectory = path.dirname(resolvedOutputSpec);
const resolvedProjectSpec = resolveProjectSpec(projectSpec, cwd, undefined);
const resolvedProjectSpec = resolveProjectSpec(projectSpec, cwd, /*referrer*/ undefined);
const project = readJson(resolvedProjectSpec);
const skipProjects = /**@type {Set<string>}*/(new Set());
const skipFiles = new Set(options && options.exclude && options.exclude.map(file => normalizeSlashes(path.resolve(cwd, file))));
Expand Down Expand Up @@ -310,7 +314,7 @@ function normalizeSlashes(file) {
* @returns {string}
*/
function resolveProjectSpec(projectSpec, cwd, referrer) {
let projectPath = normalizeSlashes(path.resolve(cwd, referrer ? path.dirname(referrer) : "", projectSpec));
const projectPath = normalizeSlashes(path.resolve(cwd, referrer ? path.dirname(referrer) : "", projectSpec));
const stats = fs.statSync(projectPath);
if (stats.isFile()) return normalizeSlashes(projectPath);
return normalizeSlashes(path.resolve(cwd, projectPath, "tsconfig.json"));
Expand All @@ -321,7 +325,10 @@ function resolveProjectSpec(projectSpec, cwd, referrer) {
* @param {{ cwd?: string }} [opts]
*/
function rm(dest, opts) {
if (dest && typeof dest === "object") opts = dest, dest = undefined;
if (dest && typeof dest === "object") {
opts = dest;
dest = undefined;
}
let failed = false;

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

0 comments on commit 9f7c0cb

Please sign in to comment.