Skip to content

Commit e7dc2a6

Browse files
author
Andy
authored
Enable "object-literal-shorthand" lint rule (microsoft#16987)
1 parent dc81b45 commit e7dc2a6

32 files changed

+94
-174
lines changed

Gulpfile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
669669
}
670670
args.push(run);
671671
setNodeEnvToDevelopment();
672-
runTestsInParallel(taskConfigsFolder, run, { testTimeout: testTimeout, noColors: colors === " --no-colors " }, function(err) {
672+
runTestsInParallel(taskConfigsFolder, run, { testTimeout, noColors: colors === " --no-colors " }, function(err) {
673673
// last worker clean everything and runs linter in case if there were no errors
674674
del(taskConfigsFolder).then(() => {
675675
if (!err) {

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21180,7 +21180,7 @@ namespace ts {
2118021180
for (const prop of properties) {
2118121181
const existing = seen.get(prop.name);
2118221182
if (!existing) {
21183-
seen.set(prop.name, { prop: prop, containingType: base });
21183+
seen.set(prop.name, { prop, containingType: base });
2118421184
}
2118521185
else {
2118621186
const isInheritedProperty = existing.containingType !== type;

src/compiler/moduleNameResolver.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,7 @@ namespace ts {
151151
*/
152152
export function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string | undefined, options: CompilerOptions, host: ModuleResolutionHost): ResolvedTypeReferenceDirectiveWithFailedLookupLocations {
153153
const traceEnabled = isTraceEnabled(options, host);
154-
const moduleResolutionState: ModuleResolutionState = {
155-
compilerOptions: options,
156-
host: host,
157-
traceEnabled
158-
};
154+
const moduleResolutionState: ModuleResolutionState = { compilerOptions: options, host, traceEnabled };
159155

160156
const typeRoots = getEffectiveTypeRoots(options, host);
161157
if (traceEnabled) {

src/compiler/sourcemap.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ namespace ts {
145145

146146
// Initialize source map data
147147
sourceMapData = {
148-
sourceMapFilePath: sourceMapFilePath,
148+
sourceMapFilePath,
149149
jsSourceMappingURL: !compilerOptions.inlineSourceMap ? getBaseFileName(normalizeSlashes(sourceMapFilePath)) : undefined,
150150
sourceMapFile: getBaseFileName(normalizeSlashes(filePath)),
151151
sourceMapSourceRoot: compilerOptions.sourceRoot || "",
@@ -292,8 +292,8 @@ namespace ts {
292292

293293
// New span
294294
lastRecordedSourceMapSpan = {
295-
emittedLine: emittedLine,
296-
emittedColumn: emittedColumn,
295+
emittedLine,
296+
emittedColumn,
297297
sourceLine: sourceLinePos.line,
298298
sourceColumn: sourceLinePos.character,
299299
sourceIndex: sourceMapSourceIndex

src/compiler/sys.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ namespace ts {
325325
const nodeSystem: System = {
326326
args: process.argv.slice(2),
327327
newLine: _os.EOL,
328-
useCaseSensitiveFileNames: useCaseSensitiveFileNames,
328+
useCaseSensitiveFileNames,
329329
write(s: string): void {
330330
process.stdout.write(s);
331331
},
@@ -394,9 +394,7 @@ namespace ts {
394394
}
395395
);
396396
},
397-
resolvePath: function(path: string): string {
398-
return _path.resolve(path);
399-
},
397+
resolvePath: path => _path.resolve(path),
400398
fileExists,
401399
directoryExists,
402400
createDirectory(directoryName: string) {

src/compiler/transformers/generators.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,8 +2220,8 @@ namespace ts {
22202220
beginBlock(<LoopBlock>{
22212221
kind: CodeBlockKind.Loop,
22222222
isScript: false,
2223-
breakLabel: breakLabel,
2224-
continueLabel: continueLabel
2223+
breakLabel,
2224+
continueLabel,
22252225
});
22262226
return breakLabel;
22272227
}
@@ -2262,7 +2262,7 @@ namespace ts {
22622262
beginBlock(<SwitchBlock>{
22632263
kind: CodeBlockKind.Switch,
22642264
isScript: false,
2265-
breakLabel: breakLabel
2265+
breakLabel,
22662266
});
22672267
return breakLabel;
22682268
}

src/harness/fourslash.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,7 +2544,7 @@ namespace FourSlash {
25442544

25452545
// if there was an explicit match kind specified, then it should be validated.
25462546
if (matchKind !== undefined) {
2547-
const missingItem = { name: name, kind: kind, searchValue: searchValue, matchKind: matchKind, fileName: fileName, parentName: parentName };
2547+
const missingItem = { name, kind, searchValue, matchKind, fileName, parentName };
25482548
this.raiseError(`verifyNavigationItemsListContains failed - could not find the item: ${stringify(missingItem)} in the returned list: (${stringify(items)})`);
25492549
}
25502550
}
@@ -2618,7 +2618,7 @@ namespace FourSlash {
26182618
}
26192619
}
26202620

2621-
const missingItem = { fileName: fileName, start: start, end: end, isWriteAccess: isWriteAccess };
2621+
const missingItem = { fileName, start, end, isWriteAccess };
26222622
this.raiseError(`verifyOccurrencesAtPositionListContains failed - could not find the item: ${stringify(missingItem)} in the returned list: (${stringify(occurrences)})`);
26232623
}
26242624

@@ -3239,7 +3239,7 @@ ${code}
32393239
}
32403240

32413241
const range: Range = {
3242-
fileName: fileName,
3242+
fileName,
32433243
start: rangeStart.position,
32443244
end: (i - 1) - difference,
32453245
marker: rangeStart.marker
@@ -3367,7 +3367,7 @@ ${code}
33673367
content: output,
33683368
fileOptions: {},
33693369
version: 0,
3370-
fileName: fileName
3370+
fileName,
33713371
};
33723372
}
33733373

@@ -4198,11 +4198,8 @@ namespace FourSlashInterface {
41984198
}
41994199

42004200
function getClassification(classificationType: ts.ClassificationTypeNames, text: string, position?: number): Classification {
4201-
return {
4202-
classificationType,
4203-
text: text,
4204-
textSpan: position === undefined ? undefined : { start: position, end: position + text.length }
4205-
};
4201+
const textSpan = position === undefined ? undefined : { start: position, end: position + text.length };
4202+
return { classificationType, text, textSpan };
42064203
}
42074204
}
42084205
}

src/harness/projectsRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ class ProjectRunner extends RunnerBase {
354354
ensureDirectoryStructure(ts.getDirectoryPath(ts.normalizePath(outputFilePath)));
355355
Harness.IO.writeFile(outputFilePath, data);
356356

357-
outputFiles.push({ emittedFileName: fileName, code: data, fileName: diskRelativeName, writeByteOrderMark: writeByteOrderMark });
357+
outputFiles.push({ emittedFileName: fileName, code: data, fileName: diskRelativeName, writeByteOrderMark });
358358
}
359359
}
360360

src/harness/sourceMapRecorder.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ namespace Harness.SourceMapRecorder {
259259
export function recordSourceMapSpan(sourceMapSpan: ts.SourceMapSpan) {
260260
// verify the decoded span is same as the new span
261261
const decodeResult = SourceMapDecoder.decodeNextEncodedSourceMapSpan();
262-
let decodedErrors: string[];
262+
let decodeErrors: string[];
263263
if (decodeResult.error
264264
|| decodeResult.sourceMapSpan.emittedLine !== sourceMapSpan.emittedLine
265265
|| decodeResult.sourceMapSpan.emittedColumn !== sourceMapSpan.emittedColumn
@@ -268,22 +268,20 @@ namespace Harness.SourceMapRecorder {
268268
|| decodeResult.sourceMapSpan.sourceIndex !== sourceMapSpan.sourceIndex
269269
|| decodeResult.sourceMapSpan.nameIndex !== sourceMapSpan.nameIndex) {
270270
if (decodeResult.error) {
271-
decodedErrors = ["!!^^ !!^^ There was decoding error in the sourcemap at this location: " + decodeResult.error];
271+
decodeErrors = ["!!^^ !!^^ There was decoding error in the sourcemap at this location: " + decodeResult.error];
272272
}
273273
else {
274-
decodedErrors = ["!!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span:"];
274+
decodeErrors = ["!!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span:"];
275275
}
276-
decodedErrors.push("!!^^ !!^^ Decoded span from sourcemap's mappings entry: " + getSourceMapSpanString(decodeResult.sourceMapSpan, /*getAbsentNameIndex*/ true) + " Span encoded by the emitter:" + getSourceMapSpanString(sourceMapSpan, /*getAbsentNameIndex*/ true));
276+
decodeErrors.push("!!^^ !!^^ Decoded span from sourcemap's mappings entry: " + getSourceMapSpanString(decodeResult.sourceMapSpan, /*getAbsentNameIndex*/ true) + " Span encoded by the emitter:" + getSourceMapSpanString(sourceMapSpan, /*getAbsentNameIndex*/ true));
277277
}
278278

279279
if (spansOnSingleLine.length && spansOnSingleLine[0].sourceMapSpan.emittedLine !== sourceMapSpan.emittedLine) {
280280
// On different line from the one that we have been recording till now,
281281
writeRecordedSpans();
282-
spansOnSingleLine = [{ sourceMapSpan: sourceMapSpan, decodeErrors: decodedErrors }];
283-
}
284-
else {
285-
spansOnSingleLine.push({ sourceMapSpan: sourceMapSpan, decodeErrors: decodedErrors });
282+
spansOnSingleLine = [];
286283
}
284+
spansOnSingleLine.push({ sourceMapSpan, decodeErrors });
287285
}
288286

289287
export function recordNewSourceFileSpan(sourceMapSpan: ts.SourceMapSpan, newSourceFileCode: string) {

src/harness/test262Runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Test262BaselineRunner extends RunnerBase {
4848
// Emit the results
4949
testState = {
5050
filename: testFilename,
51-
inputFiles: inputFiles,
51+
inputFiles,
5252
compilerResult: undefined,
5353
};
5454

src/harness/typeWriter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class TypeWriterWalker {
6868
this.results.push({
6969
line: lineAndCharacter.line,
7070
syntaxKind: node.kind,
71-
sourceText: sourceText,
71+
sourceText,
7272
type: typeString,
7373
symbol: symbolString
7474
});

src/harness/unittests/services/colorization.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,9 @@ describe("Colorization", function () {
3030
function identifier(text: string, position?: number) { return createClassification(text, ts.TokenClass.Identifier, position); }
3131
function numberLiteral(text: string, position?: number) { return createClassification(text, ts.TokenClass.NumberLiteral, position); }
3232
function stringLiteral(text: string, position?: number) { return createClassification(text, ts.TokenClass.StringLiteral, position); }
33-
function finalEndOfLineState(value: number): ClassificationEntry { return { value: value, classification: undefined, position: 0 }; }
34-
function createClassification(text: string, tokenClass: ts.TokenClass, position?: number): ClassificationEntry {
35-
return {
36-
value: text,
37-
classification: tokenClass,
38-
position: position,
39-
};
33+
function finalEndOfLineState(value: number): ClassificationEntry { return { value, classification: undefined, position: 0 }; }
34+
function createClassification(value: string, classification: ts.TokenClass, position?: number): ClassificationEntry {
35+
return { value, classification, position };
4036
}
4137

4238
function testLexicalClassification(text: string, initialEndOfLineState: ts.EndOfLineState, ...expectedEntries: ClassificationEntry[]): void {

src/harness/unittests/session.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ namespace ts.server {
389389
request_seq: 0,
390390
type: "response",
391391
command,
392-
body: body,
392+
body,
393393
success: true
394394
});
395395
});
@@ -436,7 +436,7 @@ namespace ts.server {
436436
request_seq: 0,
437437
type: "response",
438438
command,
439-
body: body,
439+
body,
440440
success: true
441441
});
442442
});

src/harness/unittests/telemetry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace ts.projectSystem {
7777
et.service.openExternalProject({
7878
rootFiles: toExternalFiles([file1.path]),
7979
options: compilerOptions,
80-
projectFileName: projectFileName,
80+
projectFileName,
8181
});
8282
checkNumberOfProjects(et.service, { externalProjects: 1 });
8383
}

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ namespace ts.projectSystem {
115115
for (const typing of installedTypings) {
116116
dependencies[typing] = "1.0.0";
117117
}
118-
return JSON.stringify({ dependencies: dependencies });
118+
return JSON.stringify({ dependencies });
119119
}
120120

121121
export function getExecutingFilePathFromLibFile(): string {

src/server/client.ts

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,7 @@ namespace ts.server {
184184
}
185185

186186
getProjectInfo(fileName: string, needFileNameList: boolean): protocol.ProjectInfo {
187-
const args: protocol.ProjectInfoRequestArgs = {
188-
file: fileName,
189-
needFileNameList: needFileNameList
190-
};
187+
const args: protocol.ProjectInfoRequestArgs = { file: fileName, needFileNameList };
191188

192189
const request = this.processRequest<protocol.ProjectInfoRequest>(CommandNames.ProjectInfo, args);
193190
const response = this.processResponse<protocol.ProjectInfoResponse>(request);
@@ -270,7 +267,7 @@ namespace ts.server {
270267
kindModifiers: entry.kindModifiers,
271268
matchKind: entry.matchKind,
272269
isCaseSensitive: entry.isCaseSensitive,
273-
fileName: fileName,
270+
fileName,
274271
textSpan: ts.createTextSpanFromBounds(start, end)
275272
};
276273
});
@@ -304,7 +301,7 @@ namespace ts.server {
304301
file: fileName,
305302
line: lineOffset.line,
306303
offset: lineOffset.offset,
307-
key: key
304+
key,
308305
};
309306

310307
// TODO: handle FormatCodeOptions
@@ -332,7 +329,7 @@ namespace ts.server {
332329
return {
333330
containerKind: ScriptElementKind.unknown,
334331
containerName: "",
335-
fileName: fileName,
332+
fileName,
336333
textSpan: ts.createTextSpanFromBounds(start, end),
337334
kind: ScriptElementKind.unknown,
338335
name: ""
@@ -358,7 +355,7 @@ namespace ts.server {
358355
return {
359356
containerKind: ScriptElementKind.unknown,
360357
containerName: "",
361-
fileName: fileName,
358+
fileName,
362359
textSpan: ts.createTextSpanFromBounds(start, end),
363360
kind: ScriptElementKind.unknown,
364361
name: ""
@@ -411,7 +408,7 @@ namespace ts.server {
411408
const start = this.lineOffsetToPosition(fileName, entry.start);
412409
const end = this.lineOffsetToPosition(fileName, entry.end);
413410
return {
414-
fileName: fileName,
411+
fileName,
415412
textSpan: ts.createTextSpanFromBounds(start, end),
416413
isWriteAccess: entry.isWriteAccess,
417414
isDefinition: entry.isDefinition,
@@ -456,7 +453,7 @@ namespace ts.server {
456453
start: entry.start,
457454
length: entry.length,
458455
messageText: entry.message,
459-
category: category,
456+
category,
460457
code: entry.code
461458
};
462459
}
@@ -483,10 +480,7 @@ namespace ts.server {
483480
entry.locs.map((loc: protocol.TextSpan) => {
484481
const start = this.lineOffsetToPosition(fileName, loc.start);
485482
const end = this.lineOffsetToPosition(fileName, loc.end);
486-
locations.push({
487-
textSpan: ts.createTextSpanFromBounds(start, end),
488-
fileName: fileName
489-
});
483+
locations.push({ textSpan: ts.createTextSpanFromBounds(start, end), fileName, });
490484
});
491485
});
492486
return this.lastRenameEntry = {
@@ -497,11 +491,11 @@ namespace ts.server {
497491
kindModifiers: response.body.info.kindModifiers,
498492
localizedErrorMessage: response.body.info.localizedErrorMessage,
499493
triggerSpan: ts.createTextSpanFromBounds(position, position),
500-
fileName: fileName,
501-
position: position,
502-
findInStrings: findInStrings,
503-
findInComments: findInComments,
504-
locations: locations
494+
fileName,
495+
position,
496+
findInStrings,
497+
findInComments,
498+
locations,
505499
};
506500
}
507501

@@ -596,10 +590,7 @@ namespace ts.server {
596590

597591
const result: SignatureHelpItems = {
598592
items: helpItems.items,
599-
applicableSpan: {
600-
start: start,
601-
length: end - start
602-
},
593+
applicableSpan: { start, length: end - start },
603594
selectedItemIndex: helpItems.selectedItemIndex,
604595
argumentIndex: helpItems.argumentIndex,
605596
argumentCount: helpItems.argumentCount,
@@ -686,7 +677,7 @@ namespace ts.server {
686677
startOffset: startLineOffset.offset,
687678
endLine: endLineOffset.line,
688679
endOffset: endLineOffset.offset,
689-
errorCodes: errorCodes,
680+
errorCodes,
690681
};
691682

692683
const request = this.processRequest<protocol.CodeFixRequest>(CommandNames.GetCodeFixes, args);
@@ -779,10 +770,7 @@ namespace ts.server {
779770
const end = this.lineOffsetToPosition(fileName, change.end);
780771

781772
return {
782-
span: {
783-
start: start,
784-
length: end - start
785-
},
773+
span: { start, length: end - start },
786774
newText: change.newText ? change.newText : ""
787775
};
788776
}
@@ -801,10 +789,7 @@ namespace ts.server {
801789
return response.body.map(entry => {
802790
const start = this.lineOffsetToPosition(fileName, entry.start);
803791
const end = this.lineOffsetToPosition(fileName, entry.end);
804-
return {
805-
start: start,
806-
length: end - start,
807-
};
792+
return { start, length: end - start };
808793
});
809794
}
810795

0 commit comments

Comments
 (0)