Enable max-statements-per-line lint rule (#45475)

* Enable the rule

* Fix all the violations
This commit is contained in:
Ryan Cavanaugh
2021-08-16 13:53:51 -07:00
committed by GitHub
parent 339ad92b98
commit e00b5ecd40
37 changed files with 215 additions and 109 deletions

View File

@@ -85,13 +85,15 @@ namespace Harness {
}
compilerTest = new CompilerTest(fileName, payload, configuration);
});
it(`Correct errors for ${fileName}`, () => { compilerTest.verifyDiagnostics(); });
it(`Correct module resolution tracing for ${fileName}`, () => { compilerTest.verifyModuleResolution(); });
it(`Correct sourcemap content for ${fileName}`, () => { compilerTest.verifySourceMapRecord(); });
it(`Correct JS output for ${fileName}`, () => { if (this.emit) compilerTest.verifyJavaScriptOutput(); });
it(`Correct Sourcemap output for ${fileName}`, () => { compilerTest.verifySourceMapOutput(); });
it(`Correct type/symbol baselines for ${fileName}`, () => { compilerTest.verifyTypesAndSymbols(); });
after(() => { compilerTest = undefined!; });
it(`Correct errors for ${fileName}`, () => compilerTest.verifyDiagnostics());
it(`Correct module resolution tracing for ${fileName}`, () => compilerTest.verifyModuleResolution());
it(`Correct sourcemap content for ${fileName}`, () => compilerTest.verifySourceMapRecord());
it(`Correct JS output for ${fileName}`, () => (this.emit && compilerTest.verifyJavaScriptOutput()));
it(`Correct Sourcemap output for ${fileName}`, () => compilerTest.verifySourceMapOutput());
it(`Correct type/symbol baselines for ${fileName}`, () => compilerTest.verifyTypesAndSymbols());
after(() => {
compilerTest = undefined!;
});
}
private parseOptions() {

View File

@@ -98,10 +98,10 @@ namespace Harness.Parallel.Worker {
*/
function shimTestInterface(rootSuite: Mocha.Suite, context: Mocha.MochaGlobals) {
const suites = [rootSuite];
context.before = (title: string | Mocha.Func | Mocha.AsyncFunc, fn?: Mocha.Func | Mocha.AsyncFunc) => { suites[0].beforeAll(title as string, fn); };
context.after = (title: string | Mocha.Func | Mocha.AsyncFunc, fn?: Mocha.Func | Mocha.AsyncFunc) => { suites[0].afterAll(title as string, fn); };
context.beforeEach = (title: string | Mocha.Func | Mocha.AsyncFunc, fn?: Mocha.Func | Mocha.AsyncFunc) => { suites[0].beforeEach(title as string, fn); };
context.afterEach = (title: string | Mocha.Func | Mocha.AsyncFunc, fn?: Mocha.Func | Mocha.AsyncFunc) => { suites[0].afterEach(title as string, fn); };
context.before = (title: string | Mocha.Func | Mocha.AsyncFunc, fn?: Mocha.Func | Mocha.AsyncFunc) => suites[0].beforeAll(title as string, fn);
context.after = (title: string | Mocha.Func | Mocha.AsyncFunc, fn?: Mocha.Func | Mocha.AsyncFunc) => suites[0].afterAll(title as string, fn);
context.beforeEach = (title: string | Mocha.Func | Mocha.AsyncFunc, fn?: Mocha.Func | Mocha.AsyncFunc) => suites[0].beforeEach(title as string, fn);
context.afterEach = (title: string | Mocha.Func | Mocha.AsyncFunc, fn?: Mocha.Func | Mocha.AsyncFunc) => suites[0].afterEach(title as string, fn);
context.describe = context.context = ((title: string, fn: (this: Mocha.Suite) => void) => addSuite(title, fn)) as Mocha.SuiteFunction;
context.describe.skip = context.xdescribe = context.xcontext = (title: string) => addSuite(title, /*fn*/ undefined);
context.describe.only = (title: string, fn?: (this: Mocha.Suite) => void) => addSuite(title, fn);

View File

@@ -56,14 +56,18 @@ namespace project {
for (const { name, payload } of ProjectTestCase.getConfigurations(testCaseFileName)) {
describe("Compiling project for " + payload.testCase.scenario + ": testcase " + testCaseFileName + (name ? ` (${name})` : ``), () => {
let projectTestCase: ProjectTestCase | undefined;
before(() => { projectTestCase = new ProjectTestCase(testCaseFileName, payload); });
before(() => {
projectTestCase = new ProjectTestCase(testCaseFileName, payload);
});
it(`Correct module resolution tracing for ${testCaseFileName}`, () => projectTestCase && projectTestCase.verifyResolution());
it(`Correct errors for ${testCaseFileName}`, () => projectTestCase && projectTestCase.verifyDiagnostics());
it(`Correct JS output for ${testCaseFileName}`, () => projectTestCase && projectTestCase.verifyJavaScriptOutput());
// NOTE: This check was commented out in previous code. Leaving this here to eventually be restored if needed.
// it(`Correct sourcemap content for ${testCaseFileName}`, () => projectTestCase && projectTestCase.verifySourceMapRecord());
it(`Correct declarations for ${testCaseFileName}`, () => projectTestCase && projectTestCase.verifyDeclarations());
after(() => { projectTestCase = undefined; });
after(() => {
projectTestCase = undefined;
});
});
}
}

View File

@@ -319,7 +319,7 @@ namespace ts {
map.set("c", "d");
map.set("a", "b");
const actual: [string, string][] = [];
map.forEach((value, key) => { actual.push([key, value]); });
map.forEach((value, key) => actual.push([key, value]));
assert.deepEqual(actual, [["c", "d"], ["a", "b"]]);
});
});

View File

@@ -302,7 +302,7 @@ namespace ts {
set.add("c");
set.add("a");
const actual: [string, string][] = [];
set.forEach((value, key) => { actual.push([key, value]); });
set.forEach((value, key) => actual.push([key, value]));
assert.deepEqual(actual, [["c", "c"], ["a", "a"]]);
});
});

View File

@@ -13,7 +13,11 @@ namespace ts {
typeScriptVersion: "3.8"
});
let logWritten = false;
Debug.loggingHost = { log() { logWritten = true; } };
Debug.loggingHost = {
log() {
logWritten = true;
}
};
deprecation();
assert.isFalse(logWritten);
});
@@ -23,7 +27,11 @@ namespace ts {
typeScriptVersion: "3.9"
});
let logWritten = false;
Debug.loggingHost = { log() { logWritten = true; } };
Debug.loggingHost = {
log() {
logWritten = true;
}
};
deprecation();
assert.isTrue(logWritten);
});
@@ -32,7 +40,11 @@ namespace ts {
typeScriptVersion: "3.9"
});
let logWritten = false;
Debug.loggingHost = { log() { logWritten = true; } };
Debug.loggingHost = {
log() {
logWritten = true;
}
};
deprecation();
assert.isTrue(logWritten);
});
@@ -41,7 +53,11 @@ namespace ts {
typeScriptVersion: "3.9"
});
let logWrites = 0;
Debug.loggingHost = { log() { logWrites++; } };
Debug.loggingHost = {
log() {
logWrites++;
}
};
deprecation();
deprecation();
assert.equal(logWrites, 1);
@@ -53,7 +69,11 @@ namespace ts {
typeScriptVersion: "3.9"
});
let logWritten = false;
Debug.loggingHost = { log() { logWritten = true; } };
Debug.loggingHost = {
log() {
logWritten = true;
}
};
expect(deprecation).throws();
assert.isFalse(logWritten);
});
@@ -62,7 +82,11 @@ namespace ts {
error: true,
});
let logWritten = false;
Debug.loggingHost = { log() { logWritten = true; } };
Debug.loggingHost = {
log() {
logWritten = true;
}
};
expect(deprecation).throws();
assert.isFalse(logWritten);
});

View File

@@ -23,15 +23,34 @@ describe("unittests:: services:: Colorization", () => {
return undefined;
}
function punctuation(text: string, position?: number) { return createClassification(text, ts.TokenClass.Punctuation, position); }
function keyword(text: string, position?: number) { return createClassification(text, ts.TokenClass.Keyword, position); }
function operator(text: string, position?: number) { return createClassification(text, ts.TokenClass.Operator, position); }
function comment(text: string, position?: number) { return createClassification(text, ts.TokenClass.Comment, position); }
function whitespace(text: string, position?: number) { return createClassification(text, ts.TokenClass.Whitespace, position); }
function identifier(text: string, position?: number) { return createClassification(text, ts.TokenClass.Identifier, position); }
function numberLiteral(text: string, position?: number) { return createClassification(text, ts.TokenClass.NumberLiteral, position); }
function stringLiteral(text: string, position?: number) { return createClassification(text, ts.TokenClass.StringLiteral, position); }
function finalEndOfLineState(value: number): ClassificationEntry { return { value, classification: undefined!, position: 0 }; } // TODO: GH#18217
function punctuation(text: string, position?: number) {
return createClassification(text, ts.TokenClass.Punctuation, position);
}
function keyword(text: string, position?: number) {
return createClassification(text, ts.TokenClass.Keyword, position);
}
function operator(text: string, position?: number) {
return createClassification(text, ts.TokenClass.Operator, position);
}
function comment(text: string, position?: number) {
return createClassification(text, ts.TokenClass.Comment, position);
}
function whitespace(text: string, position?: number) {
return createClassification(text, ts.TokenClass.Whitespace, position);
}
function identifier(text: string, position?: number) {
return createClassification(text, ts.TokenClass.Identifier, position);
}
function numberLiteral(text: string, position?: number) {
return createClassification(text, ts.TokenClass.NumberLiteral, position);
}
function stringLiteral(text: string, position?: number) {
return createClassification(text, ts.TokenClass.StringLiteral, position);
}
function finalEndOfLineState(value: number): ClassificationEntry {
// TODO: GH#18217
return { value, classification: undefined!, position: 0 };
}
function createClassification(value: string, classification: ts.TokenClass, position?: number): ClassificationEntry {
return { value, classification, position };
}

View File

@@ -2,7 +2,9 @@ namespace ts {
describe("unittests:: tsbuild:: outFile:: on amd modules with --out", () => {
let outFileFs: vfs.FileSystem;
const enum Project { lib, app }
function relName(path: string) { return path.slice(1); }
function relName(path: string) {
return path.slice(1);
}
type Sources = [string, readonly string[]];
const enum Source { config, ts }
const sources: [Sources, Sources] = [

View File

@@ -4,7 +4,9 @@ namespace ts {
const enum Ext { js, jsmap, dts, dtsmap, buildinfo }
const enum Project { first, second, third }
type OutputFile = [string, string, string, string, string];
function relName(path: string) { return path.slice(1); }
function relName(path: string) {
return path.slice(1);
}
const outputFiles: [OutputFile, OutputFile, OutputFile] = [
[
"/src/first/bin/first-output.js",