Skip to content

Commit e00b5ec

Browse files
Enable max-statements-per-line lint rule (#45475)
* Enable the rule * Fix all the violations
1 parent 339ad92 commit e00b5ec

37 files changed

+215
-109
lines changed

.eslintrc.json

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
3737
"@typescript-eslint/consistent-type-assertions": ["error", { "assertionStyle": "as" }],
3838

39+
"max-statements-per-line": ["error", { "max": 1 }],
40+
3941
"no-duplicate-imports": "off",
4042
"@typescript-eslint/no-duplicate-imports": "error",
4143

scripts/processDiagnosticMessages.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ function createKey(name: string, code: number): string {
105105

106106
function convertPropertyName(origName: string): string {
107107
let result = origName.split("").map(char => {
108-
if (char === "*") { return "_Asterisk"; }
109-
if (char === "/") { return "_Slash"; }
110-
if (char === ":") { return "_Colon"; }
108+
if (char === "*") return "_Asterisk";
109+
if (char === "/") return "_Slash";
110+
if (char === ":") return "_Colon";
111111
return /\w/.test(char) ? char : "_";
112112
}).join("");
113113

scripts/produceLKG.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,9 @@ async function exec(path: string, args: string[] = []) {
102102
childProcess.execSync(cmdLine);
103103
}
104104

105-
process.on("unhandledRejection", err => { throw err; });
106-
produceLKG().then(() => console.log("Done"), err => { throw err; });
105+
process.on("unhandledRejection", err => {
106+
throw err;
107+
});
108+
produceLKG().then(() => console.log("Done"), err => {
109+
throw err;
110+
});

src/compiler/builder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ namespace ts {
232232
else if (canCopySemanticDiagnostics) {
233233
const sourceFile = newProgram.getSourceFileByPath(sourceFilePath)!;
234234

235-
if (sourceFile.isDeclarationFile && !copyDeclarationFileDiagnostics) { return; }
236-
if (sourceFile.hasNoDefaultLib && !copyLibFileDiagnostics) { return; }
235+
if (sourceFile.isDeclarationFile && !copyDeclarationFileDiagnostics) return;
236+
if (sourceFile.hasNoDefaultLib && !copyLibFileDiagnostics) return;
237237

238238
// Unchanged file copy diagnostics
239239
const diagnostics = oldState!.semanticDiagnosticsPerFile!.get(sourceFilePath);

src/compiler/builderState.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ namespace ts {
258258
if (sourceFile.moduleAugmentations.length) {
259259
const checker = program.getTypeChecker();
260260
for (const moduleName of sourceFile.moduleAugmentations) {
261-
if (!isStringLiteral(moduleName)) { continue; }
261+
if (!isStringLiteral(moduleName)) continue;
262262
const symbol = checker.getSymbolAtLocation(moduleName);
263-
if (!symbol) { continue; }
263+
if (!symbol) continue;
264264

265265
// Add any file other than our own as reference
266266
addReferenceFromAmbientModule(symbol);

src/compiler/checker.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -34531,7 +34531,9 @@ namespace ts {
3453134531
case SyntaxKind.ImportClause:
3453234532
let result = DeclarationSpaces.None;
3453334533
const target = resolveAlias(getSymbolOfNode(d)!);
34534-
forEach(target.declarations, d => { result |= getDeclarationSpaces(d); });
34534+
forEach(target.declarations, d => {
34535+
result |= getDeclarationSpaces(d);
34536+
});
3453534537
return result;
3453634538
case SyntaxKind.VariableDeclaration:
3453734539
case SyntaxKind.BindingElement:
@@ -37943,7 +37945,9 @@ namespace ts {
3794337945
return properties;
3794437946
}
3794537947
const seen = new Map<__String, Symbol>();
37946-
forEach(properties, p => { seen.set(p.escapedName, p); });
37948+
forEach(properties, p => {
37949+
seen.set(p.escapedName, p);
37950+
});
3794737951

3794837952
for (const base of baseTypes) {
3794937953
const properties = getPropertiesOfType(getTypeWithThisArgument(base, type.thisType));
@@ -37966,7 +37970,9 @@ namespace ts {
3796637970

3796737971
interface InheritanceInfoMap { prop: Symbol; containingType: Type; }
3796837972
const seen = new Map<__String, InheritanceInfoMap>();
37969-
forEach(resolveDeclaredMembers(type).declaredProperties, p => { seen.set(p.escapedName, { prop: p, containingType: type }); });
37973+
forEach(resolveDeclaredMembers(type).declaredProperties, p => {
37974+
seen.set(p.escapedName, { prop: p, containingType: type });
37975+
});
3797037976
let ok = true;
3797137977

3797237978
for (const base of baseTypes) {

src/compiler/core.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -1568,19 +1568,29 @@ namespace ts {
15681568
export function noop(_?: {} | null | undefined): void { }
15691569

15701570
/** Do nothing and return false */
1571-
export function returnFalse(): false { return false; }
1571+
export function returnFalse(): false {
1572+
return false;
1573+
}
15721574

15731575
/** Do nothing and return true */
1574-
export function returnTrue(): true { return true; }
1576+
export function returnTrue(): true {
1577+
return true;
1578+
}
15751579

15761580
/** Do nothing and return undefined */
1577-
export function returnUndefined(): undefined { return undefined; }
1581+
export function returnUndefined(): undefined {
1582+
return undefined;
1583+
}
15781584

15791585
/** Returns its argument. */
1580-
export function identity<T>(x: T) { return x; }
1586+
export function identity<T>(x: T) {
1587+
return x;
1588+
}
15811589

15821590
/** Returns lower case string */
1583-
export function toLowerCase(x: string) { return x.toLowerCase(); }
1591+
export function toLowerCase(x: string) {
1592+
return x.toLowerCase();
1593+
}
15841594

15851595
// We convert the file names to lower case as key for file name on case insensitive file system
15861596
// While doing so we need to handle special characters (eg \u0130) to ensure that we dont convert

src/compiler/factory/nodeFactory.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -1059,18 +1059,18 @@ namespace ts {
10591059
// @api
10601060
function createModifiersFromModifierFlags(flags: ModifierFlags) {
10611061
const result: Modifier[] = [];
1062-
if (flags & ModifierFlags.Export) { result.push(createModifier(SyntaxKind.ExportKeyword)); }
1063-
if (flags & ModifierFlags.Ambient) { result.push(createModifier(SyntaxKind.DeclareKeyword)); }
1064-
if (flags & ModifierFlags.Default) { result.push(createModifier(SyntaxKind.DefaultKeyword)); }
1065-
if (flags & ModifierFlags.Const) { result.push(createModifier(SyntaxKind.ConstKeyword)); }
1066-
if (flags & ModifierFlags.Public) { result.push(createModifier(SyntaxKind.PublicKeyword)); }
1067-
if (flags & ModifierFlags.Private) { result.push(createModifier(SyntaxKind.PrivateKeyword)); }
1068-
if (flags & ModifierFlags.Protected) { result.push(createModifier(SyntaxKind.ProtectedKeyword)); }
1069-
if (flags & ModifierFlags.Abstract) { result.push(createModifier(SyntaxKind.AbstractKeyword)); }
1070-
if (flags & ModifierFlags.Static) { result.push(createModifier(SyntaxKind.StaticKeyword)); }
1071-
if (flags & ModifierFlags.Override) { result.push(createModifier(SyntaxKind.OverrideKeyword)); }
1072-
if (flags & ModifierFlags.Readonly) { result.push(createModifier(SyntaxKind.ReadonlyKeyword)); }
1073-
if (flags & ModifierFlags.Async) { result.push(createModifier(SyntaxKind.AsyncKeyword)); }
1062+
if (flags & ModifierFlags.Export) result.push(createModifier(SyntaxKind.ExportKeyword));
1063+
if (flags & ModifierFlags.Ambient) result.push(createModifier(SyntaxKind.DeclareKeyword));
1064+
if (flags & ModifierFlags.Default) result.push(createModifier(SyntaxKind.DefaultKeyword));
1065+
if (flags & ModifierFlags.Const) result.push(createModifier(SyntaxKind.ConstKeyword));
1066+
if (flags & ModifierFlags.Public) result.push(createModifier(SyntaxKind.PublicKeyword));
1067+
if (flags & ModifierFlags.Private) result.push(createModifier(SyntaxKind.PrivateKeyword));
1068+
if (flags & ModifierFlags.Protected) result.push(createModifier(SyntaxKind.ProtectedKeyword));
1069+
if (flags & ModifierFlags.Abstract) result.push(createModifier(SyntaxKind.AbstractKeyword));
1070+
if (flags & ModifierFlags.Static) result.push(createModifier(SyntaxKind.StaticKeyword));
1071+
if (flags & ModifierFlags.Override) result.push(createModifier(SyntaxKind.OverrideKeyword));
1072+
if (flags & ModifierFlags.Readonly) result.push(createModifier(SyntaxKind.ReadonlyKeyword));
1073+
if (flags & ModifierFlags.Async) result.push(createModifier(SyntaxKind.AsyncKeyword));
10741074
return result;
10751075
}
10761076

src/compiler/program.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ namespace ts {
556556
// Visit project references first
557557
if (cbRef) {
558558
const result = cbRef(projectReferences, parent);
559-
if (result) { return result; }
559+
if (result) return result;
560560
}
561561

562562
return forEach(resolvedProjectReferences, (resolvedRef, index) => {
@@ -2238,7 +2238,7 @@ namespace ts {
22382238
}
22392239

22402240
function getOptionsDiagnosticsOfConfigFile() {
2241-
if (!options.configFile) { return emptyArray; }
2241+
if (!options.configFile) return emptyArray;
22422242
let diagnostics = programDiagnostics.getDiagnostics(options.configFile.fileName);
22432243
forEachResolvedProjectReference(resolvedRef => {
22442244
diagnostics = concatenate(diagnostics, programDiagnostics.getDiagnostics(resolvedRef.sourceFile.fileName));

src/compiler/resolutionCache.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -764,14 +764,14 @@ namespace ts {
764764
}
765765

766766
function removeResolutionsFromProjectReferenceRedirects(filePath: Path) {
767-
if (!fileExtensionIs(filePath, Extension.Json)) { return; }
767+
if (!fileExtensionIs(filePath, Extension.Json)) return;
768768

769769
const program = resolutionHost.getCurrentProgram();
770-
if (!program) { return; }
770+
if (!program) return;
771771

772772
// If this file is input file for the referenced project, get it
773773
const resolvedProjectReference = program.getResolvedProjectReferenceByPath(filePath);
774-
if (!resolvedProjectReference) { return; }
774+
if (!resolvedProjectReference) return;
775775

776776
// filePath is for the projectReference and the containing file is from this project reference, invalidate the resolution
777777
resolvedProjectReference.commandLine.fileNames.forEach(f => removeResolutionsOfFile(resolutionHost.toPath(f)));

src/compiler/sys.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ namespace ts {
366366
FileSystemEntryKind.Directory,
367367
(_eventName: string, relativeFileName) => {
368368
// When files are deleted from disk, the triggered "rename" event would have a relativefileName of "undefined"
369-
if (!isString(relativeFileName)) { return; }
369+
if (!isString(relativeFileName)) return;
370370
const fileName = getNormalizedAbsolutePath(relativeFileName, dirName);
371371
// Some applications save a working file via rename operations
372372
const callbacks = fileName && fileWatcherCallbacks.get(toCanonicalName(fileName));

src/compiler/tsbuildPublic.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ namespace ts {
601601
// Set initial build if not already built
602602
if (!state.allProjectBuildPending) return;
603603
state.allProjectBuildPending = false;
604-
if (state.options.watch) { reportWatchStatus(state, Diagnostics.Starting_compilation_in_watch_mode); }
604+
if (state.options.watch) reportWatchStatus(state, Diagnostics.Starting_compilation_in_watch_mode);
605605
enableCache(state);
606606
const buildOrder = getBuildOrderFromAnyBuildOrder(getBuildOrder(state));
607607
buildOrder.forEach(configFileName =>
@@ -1358,7 +1358,7 @@ namespace ts {
13581358
}
13591359

13601360
if (!force) {
1361-
const inputTime = getModifiedTime(host, inputFile); host.getModifiedTime(inputFile);
1361+
const inputTime = getModifiedTime(host, inputFile);
13621362
if (inputTime > newestInputFileTime) {
13631363
newestInputFileName = inputFile;
13641364
newestInputFileTime = inputTime;

src/compiler/utilities.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6702,9 +6702,9 @@ namespace ts {
67026702
}
67036703

67046704
export function getSuppoertedExtensionsWithJsonIfResolveJsonModule(options: CompilerOptions | undefined, supportedExtensions: readonly string[]): readonly string[] {
6705-
if (!options || !options.resolveJsonModule) { return supportedExtensions; }
6706-
if (supportedExtensions === allSupportedExtensions) { return allSupportedExtensionsWithJson; }
6707-
if (supportedExtensions === supportedTSExtensions) { return supportedTSExtensionsWithJson; }
6705+
if (!options || !options.resolveJsonModule) return supportedExtensions;
6706+
if (supportedExtensions === allSupportedExtensions) return allSupportedExtensionsWithJson;
6707+
if (supportedExtensions === supportedTSExtensions) return supportedTSExtensionsWithJson;
67086708
return [...supportedExtensions, Extension.Json];
67096709
}
67106710

@@ -6721,7 +6721,7 @@ namespace ts {
67216721
}
67226722

67236723
export function isSupportedSourceFileName(fileName: string, compilerOptions?: CompilerOptions, extraFileExtensions?: readonly FileExtensionInfo[]) {
6724-
if (!fileName) { return false; }
6724+
if (!fileName) return false;
67256725

67266726
const supportedExtensions = getSupportedExtensions(compilerOptions, extraFileExtensions);
67276727
for (const extension of getSuppoertedExtensionsWithJsonIfResolveJsonModule(compilerOptions, supportedExtensions)) {

src/harness/fourslashImpl.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2100,7 +2100,7 @@ namespace FourSlash {
21002100
}
21012101

21022102
private printMembersOrCompletions(info: ts.CompletionInfo | undefined) {
2103-
if (info === undefined) { return "No completion info."; }
2103+
if (info === undefined) return "No completion info.";
21042104
const { entries } = info;
21052105

21062106
function pad(s: string, length: number) {
@@ -2836,7 +2836,7 @@ namespace FourSlash {
28362836

28372837
public verifyTodoComments(descriptors: string[], spans: Range[]) {
28382838
const actual = this.languageService.getTodoComments(this.activeFile.fileName,
2839-
descriptors.map(d => { return { text: d, priority: 0 }; }));
2839+
descriptors.map(d => ({ text: d, priority: 0 })));
28402840

28412841
if (actual.length !== spans.length) {
28422842
this.raiseError(`verifyTodoComments failed - expected total spans to be ${spans.length}, but was ${actual.length}`);
@@ -4498,7 +4498,7 @@ namespace FourSlash {
44984498

44994499
// put ranges in the correct order
45004500
localRanges = localRanges.sort((a, b) => a.pos < b.pos ? -1 : a.pos === b.pos && a.end > b.end ? -1 : 1);
4501-
localRanges.forEach((r) => { ranges.push(r); });
4501+
localRanges.forEach(r => ranges.push(r));
45024502

45034503
return {
45044504
content: output,

src/harness/harnessGlobals.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ globalThis.assert = _chai.assert;
99
{
1010
// chai's builtin `assert.isFalse` is featureful but slow - we don't use those features,
1111
// so we'll just overwrite it as an alterative to migrating a bunch of code off of chai
12-
assert.isFalse = (expr: any, msg: string) => { if (expr !== false) throw new Error(msg); };
12+
assert.isFalse = (expr: any, msg: string) => {
13+
if (expr !== false) throw new Error(msg);
14+
};
1315

1416
const assertDeepImpl = assert.deepEqual;
1517
assert.deepEqual = (a, b, msg) => {

src/harness/harnessIO.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ namespace Harness {
219219
}
220220

221221
public Close() {
222-
if (this.currentLine !== undefined) { this.lines.push(this.currentLine); }
222+
if (this.currentLine !== undefined) this.lines.push(this.currentLine);
223223
this.currentLine = undefined!;
224224
}
225225

src/harness/harnessUtils.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ namespace Utils {
113113
});
114114

115115
const childNodesAndArrays: any[] = [];
116-
ts.forEachChild(node, child => { childNodesAndArrays.push(child); }, array => { childNodesAndArrays.push(array); });
116+
ts.forEachChild(node, child => {
117+
childNodesAndArrays.push(child);
118+
}, array => {
119+
childNodesAndArrays.push(array);
120+
});
117121

118122
for (const childName in node) {
119123
if (childName === "parent" || childName === "nextContainer" || childName === "modifiers" || childName === "externalModuleIndicator" ||
@@ -198,7 +202,9 @@ namespace Utils {
198202
return result;
199203
}
200204

201-
function getNodeFlagName(f: number) { return getFlagName((ts as any).NodeFlags, f); }
205+
function getNodeFlagName(f: number) {
206+
return getFlagName((ts as any).NodeFlags, f);
207+
}
202208

203209
function serializeNode(n: ts.Node): any {
204210
const o: any = { kind: getKindName(n.kind) };

src/harness/typeWriter.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ namespace Harness {
2929

3030
const resChildren: ts.Node[] = [];
3131
// push onto work queue in reverse order to maintain preorder traversal
32-
ts.forEachChild(elem, c => { resChildren.unshift(c); });
32+
ts.forEachChild(elem, c => {
33+
resChildren.unshift(c);
34+
});
3335
work.push(...resChildren);
3436
}
3537
}

src/harness/vfsUtil.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -848,14 +848,18 @@ namespace vfs {
848848
// no difference if links are empty
849849
if (!changedLinks.size) return false;
850850

851-
changedLinks.forEach((node, basename) => { FileSystem.trackCreatedInode(container, basename, changed, node); });
851+
changedLinks.forEach((node, basename) => {
852+
FileSystem.trackCreatedInode(container, basename, changed, node);
853+
});
852854
return true;
853855
}
854856

855857
private static trackDeletedInodes(container: FileSet, baseLinks: ReadonlyMap<string, Inode>) {
856858
// no difference if links are empty
857859
if (!baseLinks.size) return false;
858-
baseLinks.forEach((node, basename) => { container[basename] = isDirectory(node) ? new Rmdir() : new Unlink(); });
860+
baseLinks.forEach((node, basename) => {
861+
container[basename] = isDirectory(node) ? new Rmdir() : new Unlink();
862+
});
859863
return true;
860864
}
861865

src/server/project.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,9 @@ namespace ts.server {
15811581

15821582
const log = (message: string) => this.projectService.logger.info(message);
15831583
let errorLogs: string[] | undefined;
1584-
const logError = (message: string) => { (errorLogs || (errorLogs = [])).push(message); };
1584+
const logError = (message: string) => {
1585+
(errorLogs || (errorLogs = [])).push(message);
1586+
};
15851587
const resolvedModule = firstDefined(searchPaths, searchPath =>
15861588
Project.resolveModule(pluginConfigEntry.name, searchPath, this.projectService.host, log, logError) as PluginModuleFactory | undefined);
15871589
if (resolvedModule) {

src/services/codefixes/fixExpectedComma.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ts.codefix {
99
getCodeActions(context) {
1010
const { sourceFile } = context;
1111
const info = getInfo(sourceFile, context.span.start, context.errorCode);
12-
if (!info) { return undefined; }
12+
if (!info) return undefined;
1313

1414
const changes = textChanges.ChangeTracker.with(context, t => doChange(t, sourceFile, info));
1515

src/services/codefixes/inferFromUsage.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ namespace ts.codefix {
5353

5454
const token = getTokenAtPosition(sourceFile, start);
5555
let declaration: Declaration | undefined;
56-
const changes = textChanges.ChangeTracker.with(context, changes => { declaration = doChange(changes, sourceFile, token, errorCode, program, cancellationToken, /*markSeen*/ returnTrue, host, preferences); });
56+
const changes = textChanges.ChangeTracker.with(context, changes => {
57+
declaration = doChange(changes, sourceFile, token, errorCode, program, cancellationToken, /*markSeen*/ returnTrue, host, preferences);
58+
});
5759
const name = declaration && getNameOfDeclaration(declaration);
5860
return !name || changes.length === 0 ? undefined
5961
: [createCodeFixAction(fixId, changes, [getDiagnostic(errorCode, token), name.getText(sourceFile)], fixId, Diagnostics.Infer_all_types_from_usage)];

0 commit comments

Comments
 (0)