Skip to content

Commit 3765349

Browse files
Merge pull request #6279 from Microsoft/lintMoreServices
Lint more services code
2 parents 99b771c + 2032c6d commit 3765349

File tree

5 files changed

+259
-303
lines changed

5 files changed

+259
-303
lines changed

Jakefile.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,11 +921,19 @@ function lintFileAsync(options, path, cb) {
921921
});
922922
}
923923

924+
var servicesLintTargets = [
925+
"services.ts",
926+
"outliningElementsCollector.ts",
927+
"navigateTo.ts",
928+
"patternMatcher.ts",
929+
].map(function (s) {
930+
return path.join(servicesDirectory, s);
931+
});
924932
var lintTargets = compilerSources
925933
.concat(harnessCoreSources)
926934
.concat(serverCoreSources)
927935
.concat(scriptSources)
928-
.concat([path.join(servicesDirectory, "services.ts")]);
936+
.concat(servicesLintTargets);
929937

930938
desc("Runs tslint on the compiler sources");
931939
task("lint", ["build-rules"], function() {

scripts/tslint/booleanTriviaRule.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class BooleanTriviaWalker extends Lint.RuleWalker {
2626
for (let index = 0; index < targetParameters.length; index++) {
2727
const param = targetParameters[index];
2828
const arg = node.arguments[index];
29-
if (!(arg && param)) continue;
29+
if (!(arg && param)) {
30+
continue;
31+
}
3032

3133
const argType = this.checker.getContextualType(arg);
3234
if (argType && (argType.getFlags() & ts.TypeFlags.Boolean)) {
@@ -38,7 +40,9 @@ class BooleanTriviaWalker extends Lint.RuleWalker {
3840
if (ranges && ranges.length === 1 && ranges[0].kind === ts.SyntaxKind.MultiLineCommentTrivia) {
3941
triviaContent = arg.getFullText().slice(ranges[0].pos + 2, ranges[0].end - 2); // +/-2 to remove /**/
4042
}
41-
if (triviaContent !== param.getName()) {
43+
44+
const paramName = param.getName();
45+
if (triviaContent !== paramName && triviaContent !== paramName + ":") {
4246
this.addFailure(this.createFailure(arg.getStart(source), arg.getWidth(source), Rule.FAILURE_STRING_FACTORY(param.getName(), triviaContent)));
4347
}
4448
}

src/services/navigateTo.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ namespace ts.NavigateTo {
33
type RawNavigateToItem = { name: string; fileName: string; matchKind: PatternMatchKind; isCaseSensitive: boolean; declaration: Declaration };
44

55
export function getNavigateToItems(program: Program, cancellationToken: CancellationToken, searchValue: string, maxResultCount: number): NavigateToItem[] {
6-
let patternMatcher = createPatternMatcher(searchValue);
6+
const patternMatcher = createPatternMatcher(searchValue);
77
let rawItems: RawNavigateToItem[] = [];
88

99
// This means "compare in a case insensitive manner."
10-
let baseSensitivity: Intl.CollatorOptions = { sensitivity: "base" };
10+
const baseSensitivity: Intl.CollatorOptions = { sensitivity: "base" };
1111

1212
// Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[]
1313
forEach(program.getSourceFiles(), sourceFile => {
1414
cancellationToken.throwIfCancellationRequested();
1515

16-
let nameToDeclarations = sourceFile.getNamedDeclarations();
17-
for (let name in nameToDeclarations) {
18-
let declarations = getProperty(nameToDeclarations, name);
16+
const nameToDeclarations = sourceFile.getNamedDeclarations();
17+
for (const name in nameToDeclarations) {
18+
const declarations = getProperty(nameToDeclarations, name);
1919
if (declarations) {
2020
// First do a quick check to see if the name of the declaration matches the
2121
// last portion of the (possibly) dotted name they're searching for.
@@ -25,11 +25,11 @@ namespace ts.NavigateTo {
2525
continue;
2626
}
2727

28-
for (let declaration of declarations) {
28+
for (const declaration of declarations) {
2929
// It was a match! If the pattern has dots in it, then also see if the
3030
// declaration container matches as well.
3131
if (patternMatcher.patternContainsDots) {
32-
let containers = getContainers(declaration);
32+
const containers = getContainers(declaration);
3333
if (!containers) {
3434
return undefined;
3535
}
@@ -41,8 +41,8 @@ namespace ts.NavigateTo {
4141
}
4242
}
4343

44-
let fileName = sourceFile.fileName;
45-
let matchKind = bestMatchKind(matches);
44+
const fileName = sourceFile.fileName;
45+
const matchKind = bestMatchKind(matches);
4646
rawItems.push({ name, fileName, matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration });
4747
}
4848
}
@@ -54,15 +54,15 @@ namespace ts.NavigateTo {
5454
rawItems = rawItems.slice(0, maxResultCount);
5555
}
5656

57-
let items = map(rawItems, createNavigateToItem);
57+
const items = map(rawItems, createNavigateToItem);
5858

5959
return items;
6060

6161
function allMatchesAreCaseSensitive(matches: PatternMatch[]): boolean {
6262
Debug.assert(matches.length > 0);
6363

6464
// This is a case sensitive match, only if all the submatches were case sensitive.
65-
for (let match of matches) {
65+
for (const match of matches) {
6666
if (!match.isCaseSensitive) {
6767
return false;
6868
}
@@ -86,16 +86,16 @@ namespace ts.NavigateTo {
8686

8787
function tryAddSingleDeclarationName(declaration: Declaration, containers: string[]) {
8888
if (declaration && declaration.name) {
89-
let text = getTextOfIdentifierOrLiteral(declaration.name);
89+
const text = getTextOfIdentifierOrLiteral(declaration.name);
9090
if (text !== undefined) {
9191
containers.unshift(text);
9292
}
9393
else if (declaration.name.kind === SyntaxKind.ComputedPropertyName) {
94-
return tryAddComputedPropertyName((<ComputedPropertyName>declaration.name).expression, containers, /*includeLastPortion:*/ true);
94+
return tryAddComputedPropertyName((<ComputedPropertyName>declaration.name).expression, containers, /*includeLastPortion*/ true);
9595
}
9696
else {
9797
// Don't know how to add this.
98-
return false
98+
return false;
9999
}
100100
}
101101

@@ -106,7 +106,7 @@ namespace ts.NavigateTo {
106106
//
107107
// [X.Y.Z]() { }
108108
function tryAddComputedPropertyName(expression: Expression, containers: string[], includeLastPortion: boolean): boolean {
109-
let text = getTextOfIdentifierOrLiteral(expression);
109+
const text = getTextOfIdentifierOrLiteral(expression);
110110
if (text !== undefined) {
111111
if (includeLastPortion) {
112112
containers.unshift(text);
@@ -115,24 +115,24 @@ namespace ts.NavigateTo {
115115
}
116116

117117
if (expression.kind === SyntaxKind.PropertyAccessExpression) {
118-
let propertyAccess = <PropertyAccessExpression>expression;
118+
const propertyAccess = <PropertyAccessExpression>expression;
119119
if (includeLastPortion) {
120120
containers.unshift(propertyAccess.name.text);
121121
}
122122

123-
return tryAddComputedPropertyName(propertyAccess.expression, containers, /*includeLastPortion:*/ true);
123+
return tryAddComputedPropertyName(propertyAccess.expression, containers, /*includeLastPortion*/ true);
124124
}
125125

126126
return false;
127127
}
128128

129129
function getContainers(declaration: Declaration) {
130-
let containers: string[] = [];
130+
const containers: string[] = [];
131131

132132
// First, if we started with a computed property name, then add all but the last
133133
// portion into the container array.
134134
if (declaration.name.kind === SyntaxKind.ComputedPropertyName) {
135-
if (!tryAddComputedPropertyName((<ComputedPropertyName>declaration.name).expression, containers, /*includeLastPortion:*/ false)) {
135+
if (!tryAddComputedPropertyName((<ComputedPropertyName>declaration.name).expression, containers, /*includeLastPortion*/ false)) {
136136
return undefined;
137137
}
138138
}
@@ -155,8 +155,8 @@ namespace ts.NavigateTo {
155155
Debug.assert(matches.length > 0);
156156
let bestMatchKind = PatternMatchKind.camelCase;
157157

158-
for (let match of matches) {
159-
let kind = match.kind;
158+
for (const match of matches) {
159+
const kind = match.kind;
160160
if (kind < bestMatchKind) {
161161
bestMatchKind = kind;
162162
}
@@ -171,13 +171,13 @@ namespace ts.NavigateTo {
171171
// We first sort case insensitively. So "Aaa" will come before "bar".
172172
// Then we sort case sensitively, so "aaa" will come before "Aaa".
173173
return i1.matchKind - i2.matchKind ||
174-
i1.name.localeCompare(i2.name, undefined, baseSensitivity) ||
174+
i1.name.localeCompare(i2.name, undefined, baseSensitivity) ||
175175
i1.name.localeCompare(i2.name);
176176
}
177177

178178
function createNavigateToItem(rawItem: RawNavigateToItem): NavigateToItem {
179-
let declaration = rawItem.declaration;
180-
let container = <Declaration>getContainerNode(declaration);
179+
const declaration = rawItem.declaration;
180+
const container = <Declaration>getContainerNode(declaration);
181181
return {
182182
name: rawItem.name,
183183
kind: getNodeKind(declaration),

0 commit comments

Comments
 (0)