Skip to content

Commit c38d2a1

Browse files
author
Andy
authored
Merge pull request #15077 from Microsoft/null-trivia
boolean-trivia lint rule: Lint for null/undefined too
2 parents 2ca90b7 + 7320891 commit c38d2a1

24 files changed

+92
-68
lines changed

Gulpfile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ gulp.task("browserify", "Runs browserify on run.js to produce a file suitable fo
775775
});
776776
const finalMap = chain.apply();
777777
file.sourceMap = finalMap;
778-
next(undefined, file);
778+
next(/*err*/ undefined, file);
779779
});
780780
}))
781781
.pipe(sourcemaps.write(".", { includeContent: false }))

scripts/tslint/booleanTriviaRule.ts

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,63 @@ export class Rule extends Lint.Rules.AbstractRule {
88
}
99

1010
function walk(ctx: Lint.WalkContext<void>): void {
11-
ts.forEachChild(ctx.sourceFile, recur);
12-
function recur(node: ts.Node): void {
11+
ts.forEachChild(ctx.sourceFile, function recur(node: ts.Node): void {
1312
if (node.kind === ts.SyntaxKind.CallExpression) {
1413
checkCall(node as ts.CallExpression);
1514
}
1615
ts.forEachChild(node, recur);
17-
}
16+
});
1817

1918
function checkCall(node: ts.CallExpression): void {
2019
for (const arg of node.arguments) {
21-
if (arg.kind !== ts.SyntaxKind.TrueKeyword && arg.kind !== ts.SyntaxKind.FalseKeyword) {
22-
continue;
20+
switch (arg.kind) {
21+
case ts.SyntaxKind.TrueKeyword:
22+
case ts.SyntaxKind.FalseKeyword:
23+
case ts.SyntaxKind.NullKeyword:
24+
break;
25+
case ts.SyntaxKind.Identifier:
26+
if ((arg as ts.Identifier).originalKeywordKind !== ts.SyntaxKind.UndefinedKeyword) {
27+
continue;
28+
}
29+
break;
30+
default:
31+
continue;
2332
}
2433

2534
if (node.expression.kind === ts.SyntaxKind.PropertyAccessExpression) {
26-
const methodName = (node.expression as ts.PropertyAccessExpression).name.text
35+
const methodName = (node.expression as ts.PropertyAccessExpression).name.text;
2736
// Skip certain method names whose parameter names are not informative
28-
if (methodName === 'set' ||
29-
methodName === 'equal' ||
30-
methodName === 'fail' ||
31-
methodName === 'isTrue' ||
32-
methodName === 'assert') {
37+
if (methodName.indexOf("set") === 0) {
3338
continue;
3439
}
40+
switch (methodName) {
41+
case "apply":
42+
case "assert":
43+
case "call":
44+
case "equal":
45+
case "fail":
46+
case "isTrue":
47+
case "output":
48+
case "stringify":
49+
continue;
50+
}
3551
}
3652
else if (node.expression.kind === ts.SyntaxKind.Identifier) {
3753
const functionName = (node.expression as ts.Identifier).text;
3854
// Skip certain function names whose parameter names are not informative
39-
if (functionName === 'assert') {
55+
if (functionName.indexOf("set") === 0) {
4056
continue;
4157
}
58+
switch (functionName) {
59+
case "assert":
60+
case "contains":
61+
case "createAnonymousType":
62+
case "createImportSpecifier":
63+
case "createProperty":
64+
case "createSignature":
65+
case "resolveName":
66+
continue;
67+
}
4268
}
4369

4470
const ranges = ts.getLeadingCommentRanges(arg.getFullText(), 0);

src/compiler/binder.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ namespace ts {
418418
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
419419
}
420420
else {
421-
return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
421+
return declareSymbol(container.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes);
422422
}
423423
}
424424
else {
@@ -447,13 +447,13 @@ namespace ts {
447447
(symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0) |
448448
(symbolFlags & SymbolFlags.Type ? SymbolFlags.ExportType : 0) |
449449
(symbolFlags & SymbolFlags.Namespace ? SymbolFlags.ExportNamespace : 0);
450-
const local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes);
450+
const local = declareSymbol(container.locals, /*parent*/ undefined, node, exportKind, symbolExcludes);
451451
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
452452
node.localSymbol = local;
453453
return local;
454454
}
455455
else {
456-
return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
456+
return declareSymbol(container.locals, /*parent*/undefined, node, symbolFlags, symbolExcludes);
457457
}
458458
}
459459
}
@@ -1545,7 +1545,7 @@ namespace ts {
15451545
function declareSourceFileMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) {
15461546
return isExternalModule(file)
15471547
? declareModuleMember(node, symbolFlags, symbolExcludes)
1548-
: declareSymbol(file.locals, undefined, node, symbolFlags, symbolExcludes);
1548+
: declareSymbol(file.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes);
15491549
}
15501550

15511551
function hasExportDeclarations(node: ModuleDeclaration | SourceFile): boolean {
@@ -1721,7 +1721,7 @@ namespace ts {
17211721
blockScopeContainer.locals = createMap<Symbol>();
17221722
addToContainerChain(blockScopeContainer);
17231723
}
1724-
declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes);
1724+
declareSymbol(blockScopeContainer.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes);
17251725
}
17261726
}
17271727

src/compiler/checker.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4564,7 +4564,7 @@ namespace ts {
45644564
// The outer type parameters are those defined by enclosing generic classes, methods, or functions.
45654565
function getOuterTypeParametersOfClassOrInterface(symbol: Symbol): TypeParameter[] {
45664566
const declaration = symbol.flags & SymbolFlags.Class ? symbol.valueDeclaration : getDeclarationOfKind(symbol, SyntaxKind.InterfaceDeclaration);
4567-
return appendOuterTypeParameters(undefined, declaration);
4567+
return appendOuterTypeParameters(/*typeParameters*/ undefined, declaration);
45684568
}
45694569

45704570
// The local type parameters are the combined set of type parameters from all declarations of the class,
@@ -7702,7 +7702,7 @@ namespace ts {
77027702
}
77037703

77047704
function createTypeEraser(sources: Type[]): TypeMapper {
7705-
return createTypeMapper(sources, undefined);
7705+
return createTypeMapper(sources, /*targets*/ undefined);
77067706
}
77077707

77087708
/**
@@ -8418,7 +8418,7 @@ namespace ts {
84188418
}
84198419
}
84208420
if (source.flags & TypeFlags.StructuredOrTypeVariable || target.flags & TypeFlags.StructuredOrTypeVariable) {
8421-
return checkTypeRelatedTo(source, target, relation, undefined, undefined, undefined);
8421+
return checkTypeRelatedTo(source, target, relation, /*errorNode*/ undefined);
84228422
}
84238423
return false;
84248424
}
@@ -13665,7 +13665,7 @@ namespace ts {
1366513665
const links = getNodeLinks(node);
1366613666
if (!links.resolvedJsxElementAttributesType) {
1366713667
const elemClassType = getJsxGlobalElementClassType();
13668-
return links.resolvedJsxElementAttributesType = resolveCustomJsxElementAttributesType(node, shouldIncludeAllStatelessAttributesType, undefined, elemClassType);
13668+
return links.resolvedJsxElementAttributesType = resolveCustomJsxElementAttributesType(node, shouldIncludeAllStatelessAttributesType, /*elementType*/ undefined, elemClassType);
1366913669
}
1367013670
return links.resolvedJsxElementAttributesType;
1367113671
}
@@ -15717,7 +15717,7 @@ namespace ts {
1571715717
const parameter = signature.thisParameter;
1571815718
if (!parameter || parameter.valueDeclaration && !(<ParameterDeclaration>parameter.valueDeclaration).type) {
1571915719
if (!parameter) {
15720-
signature.thisParameter = createSymbolWithType(context.thisParameter, undefined);
15720+
signature.thisParameter = createSymbolWithType(context.thisParameter, /*type*/ undefined);
1572115721
}
1572215722
assignTypeToParameterAndFixTypeParameters(signature.thisParameter, getTypeOfSymbol(context.thisParameter), mapper, checkMode);
1572315723
}
@@ -17300,7 +17300,7 @@ namespace ts {
1730017300
Diagnostics.A_type_predicate_cannot_reference_a_rest_parameter);
1730117301
}
1730217302
else {
17303-
const leadingError = chainDiagnosticMessages(undefined, Diagnostics.A_type_predicate_s_type_must_be_assignable_to_its_parameter_s_type);
17303+
const leadingError = chainDiagnosticMessages(/*details*/ undefined, Diagnostics.A_type_predicate_s_type_must_be_assignable_to_its_parameter_s_type);
1730417304
checkTypeAssignableTo(typePredicate.type,
1730517305
getTypeOfNode(parent.parameters[typePredicate.parameterIndex]),
1730617306
node.type,
@@ -20507,7 +20507,7 @@ namespace ts {
2050720507
const typeName1 = typeToString(existing.containingType);
2050820508
const typeName2 = typeToString(base);
2050920509

20510-
let errorInfo = chainDiagnosticMessages(undefined, Diagnostics.Named_property_0_of_types_1_and_2_are_not_identical, symbolToString(prop), typeName1, typeName2);
20510+
let errorInfo = chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Named_property_0_of_types_1_and_2_are_not_identical, symbolToString(prop), typeName1, typeName2);
2051120511
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Interface_0_cannot_simultaneously_extend_types_1_and_2, typeToString(type), typeName1, typeName2);
2051220512
diagnostics.add(createDiagnosticForNodeFromMessageChain(typeNode, errorInfo));
2051320513
}

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace ts {
3030

3131
/** Create a MapLike with good performance. */
3232
function createDictionaryObject<T>(): MapLike<T> {
33-
const map = Object.create(null); // tslint:disable-line:no-null-keyword
33+
const map = Object.create(/*prototype*/ null); // tslint:disable-line:no-null-keyword
3434

3535
// Using 'delete' on an object causes V8 to put the object in dictionary mode.
3636
// This disables creation of hidden classes, which are expensive when an object is

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,7 @@ namespace ts {
21302130
function parseParameter(): ParameterDeclaration {
21312131
const node = <ParameterDeclaration>createNode(SyntaxKind.Parameter);
21322132
if (token() === SyntaxKind.ThisKeyword) {
2133-
node.name = createIdentifier(/*isIdentifier*/true, undefined);
2133+
node.name = createIdentifier(/*isIdentifier*/ true);
21342134
node.type = parseParameterType();
21352135
return finishNode(node);
21362136
}

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ namespace ts {
12181218
&& !file.isDeclarationFile) {
12191219
// synthesize 'import "tslib"' declaration
12201220
const externalHelpersModuleReference = createLiteral(externalHelpersModuleNameText);
1221-
const importDecl = createImportDeclaration(undefined, undefined, undefined);
1221+
const importDecl = createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, /*importClause*/ undefined);
12221222
externalHelpersModuleReference.parent = importDecl;
12231223
importDecl.parent = file;
12241224
imports = [externalHelpersModuleReference];

src/compiler/scanner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,11 +735,11 @@ namespace ts {
735735
}
736736

737737
export function getLeadingCommentRanges(text: string, pos: number): CommentRange[] | undefined {
738-
return reduceEachLeadingCommentRange(text, pos, appendCommentRange, undefined, undefined);
738+
return reduceEachLeadingCommentRange(text, pos, appendCommentRange, /*state*/ undefined, /*initial*/ undefined);
739739
}
740740

741741
export function getTrailingCommentRanges(text: string, pos: number): CommentRange[] | undefined {
742-
return reduceEachTrailingCommentRange(text, pos, appendCommentRange, undefined, undefined);
742+
return reduceEachTrailingCommentRange(text, pos, appendCommentRange, /*state*/ undefined, /*initial*/ undefined);
743743
}
744744

745745
/** Optionally, get the shebang */

src/compiler/sys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ namespace ts {
232232

233233
try {
234234
fd = _fs.openSync(fileName, "w");
235-
_fs.writeSync(fd, data, undefined, "utf8");
235+
_fs.writeSync(fd, data, /*position*/ undefined, "utf8");
236236
}
237237
finally {
238238
if (fd !== undefined) {

src/compiler/transformers/destructuring.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ namespace ts {
518518
}
519519
return createCall(
520520
getHelperName("__rest"),
521-
undefined,
521+
/*typeArguments*/ undefined,
522522
[
523523
value,
524524
setTextRange(

0 commit comments

Comments
 (0)