Merge pull request #5087 from weswigham/tslint-update
tslint had a new release and added the no inferrable types rule
This commit is contained in:
commit
ff3d0f9211
3 changed files with 2 additions and 52 deletions
|
@ -813,7 +813,6 @@ task("update-sublime", ["local", serverFile], function() {
|
|||
var tslintRuleDir = "scripts/tslint";
|
||||
var tslintRules = ([
|
||||
"nextLineRule",
|
||||
"noInferrableTypesRule",
|
||||
"noNullRule",
|
||||
"booleanTriviaRule"
|
||||
]);
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
/// <reference path="../../node_modules/tslint/typings/typescriptServices.d.ts" />
|
||||
/// <reference path="../../node_modules/tslint/lib/tslint.d.ts" />
|
||||
|
||||
|
||||
export class Rule extends Lint.Rules.AbstractRule {
|
||||
public static FAILURE_STRING_FACTORY = (type: string) => `LHS type (${type}) inferred by RHS expression, remove type annotation`;
|
||||
|
||||
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
|
||||
return this.applyWithWalker(new InferrableTypeWalker(sourceFile, this.getOptions()));
|
||||
}
|
||||
}
|
||||
|
||||
class InferrableTypeWalker extends Lint.RuleWalker {
|
||||
visitVariableStatement(node: ts.VariableStatement) {
|
||||
node.declarationList.declarations.forEach(e => {
|
||||
if ((!!e.type) && (!!e.initializer)) {
|
||||
let failure: string;
|
||||
switch (e.type.kind) {
|
||||
case ts.SyntaxKind.BooleanKeyword:
|
||||
if (e.initializer.kind === ts.SyntaxKind.TrueKeyword || e.initializer.kind === ts.SyntaxKind.FalseKeyword) {
|
||||
failure = 'boolean';
|
||||
}
|
||||
break;
|
||||
case ts.SyntaxKind.NumberKeyword:
|
||||
if (e.initializer.kind === ts.SyntaxKind.NumericLiteral) {
|
||||
failure = 'number';
|
||||
}
|
||||
break;
|
||||
case ts.SyntaxKind.StringKeyword:
|
||||
switch (e.initializer.kind) {
|
||||
case ts.SyntaxKind.StringLiteral:
|
||||
case ts.SyntaxKind.NoSubstitutionTemplateLiteral:
|
||||
case ts.SyntaxKind.TemplateExpression:
|
||||
failure = 'string';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (failure) {
|
||||
this.addFailure(this.createFailure(e.type.getStart(), e.type.getWidth(), Rule.FAILURE_STRING_FACTORY(failure)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
super.visitVariableStatement(node);
|
||||
}
|
||||
}
|
|
@ -157,7 +157,7 @@ namespace FourSlash {
|
|||
return true;
|
||||
}
|
||||
|
||||
public setCancelled(numberOfCalls: number = 0): void {
|
||||
public setCancelled(numberOfCalls = 0): void {
|
||||
ts.Debug.assert(numberOfCalls >= 0);
|
||||
this.numberOfCallsBeforeCancellation = numberOfCalls;
|
||||
}
|
||||
|
@ -761,7 +761,7 @@ namespace FourSlash {
|
|||
this.raiseError(`verifyReferencesAtPositionListContains failed - could not find the item: ${JSON.stringify(missingItem)} in the returned list: (${JSON.stringify(references)})`);
|
||||
}
|
||||
|
||||
public verifyReferencesCountIs(count: number, localFilesOnly: boolean = true) {
|
||||
public verifyReferencesCountIs(count: number, localFilesOnly = true) {
|
||||
this.taoInvalidReason = "verifyReferences NYI";
|
||||
|
||||
let references = this.getReferencesAtCaret();
|
||||
|
|
Loading…
Reference in a new issue