Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Fix linting errors introduced in latest tslint releases
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya committed Nov 19, 2016
1 parent 9e3ccd9 commit 11e50fb
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/configs/recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ export const rules = {
"interface-name": [true, "always-prefix"],
"jsdoc-format": true,
"label-position": true,
"max-classes-per-file": [true, 1],
"max-line-length": [true, 120],
"member-access": true,
"member-ordering": [true,
{ "order": "statics-first" },
],
"new-parens": true,
"max-classes-per-file": [true, 1],
"no-any": false,
"no-arg": true,
"no-bitwise": true,
Expand Down
2 changes: 1 addition & 1 deletion src/enableDisableRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class EnableDisableRulesWalker extends SkippableTokenAwareRuleWalker {

private getStartOfLinePosition(node: ts.SourceFile, position: number, lineOffset = 0) {
return node.getPositionOfLineAndCharacter(
node.getLineAndCharacterOfPosition(position).line + lineOffset, 0
node.getLineAndCharacterOfPosition(position).line + lineOffset, 0,
);
}

Expand Down
4 changes: 3 additions & 1 deletion src/rules/adjacentOverloadSignaturesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export class Rule extends Lint.Rules.AbstractRule {
};
/* tslint:enable:object-literal-sort-keys */

public static FAILURE_STRING_FACTORY = (name: string) => `All '${name}' signatures should be adjacent`;
public static FAILURE_STRING_FACTORY = (name: string) => {
return `All '${name}' signatures should be adjacent`;
}

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new AdjacentOverloadSignaturesWalker(sourceFile, this.getOptions()));
Expand Down
2 changes: 1 addition & 1 deletion src/rules/banRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Rule extends Lint.Rules.AbstractRule {

public static FAILURE_STRING_FACTORY = (expression: string, messageAddition?: string) => {
return `Calls to '${expression}' are not allowed.${messageAddition ? " " + messageAddition : ""}`;
};
}

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
const options = this.getOptions();
Expand Down
11 changes: 7 additions & 4 deletions src/rules/cyclomaticComplexityRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ export class Rule extends Lint.Rules.AbstractRule {
};
/* tslint:enable:object-literal-sort-keys */

public static ANONYMOUS_FAILURE_STRING = (expected: number, actual: number) =>
`The function has a cyclomatic complexity of ${actual} which is higher than the threshold of ${expected}`;
public static NAMED_FAILURE_STRING = (expected: number, actual: number, name: string) =>
`The function ${name} has a cyclomatic complexity of ${actual} which is higher than the threshold of ${expected}`;
public static ANONYMOUS_FAILURE_STRING = (expected: number, actual: number) => {
return `The function has a cyclomatic complexity of ${actual} which is higher than the threshold of ${expected}`;
}

public static NAMED_FAILURE_STRING = (expected: number, actual: number, name: string) => {
return `The function ${name} has a cyclomatic complexity of ${actual} which is higher than the threshold of ${expected}`;
}

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new CyclomaticComplexityWalker(sourceFile, this.getOptions(), this.threshold));
Expand Down
2 changes: 1 addition & 1 deletion src/rules/maxFileLineCountRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Rule extends Lint.Rules.AbstractRule {
let msg = `This file has ${lineCount} lines, which exceeds the maximum of ${lineLimit} lines allowed. `;
msg += `Consider breaking this file up into smaller parts`;
return msg;
};
}

public isEnabled(): boolean {
if (super.isEnabled()) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/maxLineLengthRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class Rule extends Lint.Rules.AbstractRule {

public static FAILURE_STRING_FACTORY = (lineLimit: number) => {
return `Exceeds maximum line length of ${lineLimit}`;
};
}

public isEnabled(): boolean {
if (super.isEnabled()) {
Expand Down
4 changes: 3 additions & 1 deletion src/rules/noDuplicateVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export class Rule extends Lint.Rules.AbstractRule {
};
/* tslint:enable:object-literal-sort-keys */

public static FAILURE_STRING_FACTORY = (name: string) => `Duplicate variable: '${name}'`;
public static FAILURE_STRING_FACTORY = (name: string) => {
return `Duplicate variable: '${name}'`;
}

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new NoDuplicateVariableWalker(sourceFile, this.getOptions()));
Expand Down
4 changes: 3 additions & 1 deletion src/rules/noInferrableTypesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export class Rule extends Lint.Rules.AbstractRule {
};
/* tslint:enable:object-literal-sort-keys */

public static FAILURE_STRING_FACTORY = (type: string) => `LHS type (${type}) inferred by RHS expression, remove type annotation`;
public static FAILURE_STRING_FACTORY = (type: string) => {
return `LHS type (${type}) inferred by RHS expression, remove type annotation`;
}

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new NoInferrableTypesWalker(sourceFile, this.getOptions()));
Expand Down
4 changes: 3 additions & 1 deletion src/rules/noParameterPropertiesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export class Rule extends Lint.Rules.AbstractRule {
};
/* tslint:enable:object-literal-sort-keys */

public static FAILURE_STRING_FACTORY = (ident: string) => `Property '${ident}' cannot be declared in the constructor`;
public static FAILURE_STRING_FACTORY = (ident: string) => {
return `Property '${ident}' cannot be declared in the constructor`;
}

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new NoParameterPropertiesWalker(sourceFile, this.getOptions()));
Expand Down
4 changes: 3 additions & 1 deletion src/rules/noShadowedVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export class Rule extends Lint.Rules.AbstractRule {
};
/* tslint:enable:object-literal-sort-keys */

public static FAILURE_STRING_FACTORY = (name: string) => `Shadowed variable: '${name}'`;
public static FAILURE_STRING_FACTORY = (name: string) => {
return `Shadowed variable: '${name}'`;
}

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new NoShadowedVariableWalker(sourceFile, this.getOptions()));
Expand Down
8 changes: 3 additions & 5 deletions src/rules/noUnsafeFinallyRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ export class Rule extends Lint.Rules.AbstractRule {
/* tslint:enable:object-literal-sort-keys */

public static FAILURE_TYPE_BREAK = "break";

public static FAILURE_TYPE_CONTINUE = "continue";

public static FAILURE_TYPE_RETURN = "return";

public static FAILURE_TYPE_THROW = "throw";

public static FAILURE_STRING_FACTORY = (name: string) => `${name} statements in finally blocks are forbidden.`;
public static FAILURE_STRING_FACTORY = (name: string) => {
return `${name} statements in finally blocks are forbidden.`;
}

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new NoReturnInFinallyScopeAwareWalker(sourceFile, this.getOptions()));
Expand Down
5 changes: 3 additions & 2 deletions src/rules/noUnusedVariableRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ export class Rule extends Lint.Rules.AbstractRule {
public static FAILURE_TYPE_PARAM = "parameter";
public static FAILURE_TYPE_PROP = "property";
public static FAILURE_TYPE_VAR = "variable";

public static FAILURE_STRING_FACTORY = (type: string, name: string) => `Unused ${type}: '${name}'`;
public static FAILURE_STRING_FACTORY = (type: string, name: string) => {
return `Unused ${type}: '${name}'`;
}

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
const languageService = Lint.createLanguageService(sourceFile.fileName, sourceFile.getFullText());
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noVarKeywordRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ class NoVarKeywordWalker extends Lint.RuleWalker {
private fix = (node: ts.Node) => new Lint.Fix(Rule.metadata.ruleName, [
this.deleteText(node.getStart(), "var".length),
this.appendText(node.getStart(), "let"),
]);
])
}
27 changes: 23 additions & 4 deletions src/rules/objectLiteralKeyQuotesRule.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/**
* @license
* Copyright 2016 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as Lint from "../index";
import * as ts from "typescript";

Expand Down Expand Up @@ -46,8 +63,12 @@ export class Rule extends Lint.Rules.AbstractRule {
/* tslint:enable:object-literal-sort-keys */

public static INCONSISTENT_PROPERTY = `All property names in this object literal must be consistently quoted or unquoted.`;
public static UNNEEDED_QUOTES = (name: string) => `Unnecessarily quoted property '${name}' found.`;
public static UNQUOTED_PROPERTY = (name: string) => `Unquoted property '${name}' found.`;
public static UNNEEDED_QUOTES = (name: string) => {
return `Unnecessarily quoted property '${name}' found.`;
}
public static UNQUOTED_PROPERTY = (name: string) => {
return `Unquoted property '${name}' found.`;
}

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
const objectLiteralKeyQuotesWalker = new ObjectLiteralKeyQuotesWalker(sourceFile, this.getOptions());
Expand All @@ -57,9 +78,7 @@ export class Rule extends Lint.Rules.AbstractRule {

// This is simplistic. See https://mothereff.in/js-properties for the gorey details.
const IDENTIFIER_NAME_REGEX = /^(?:[\$A-Z_a-z])*$/;

const NUMBER_REGEX = /^[0-9]+$/;

type QuotesMode = "always" | "as-needed" | "consistent" | "consistent-as-needed";

interface IObjectLiteralState {
Expand Down
4 changes: 3 additions & 1 deletion src/rules/objectLiteralSortKeysRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export class Rule extends Lint.Rules.AbstractRule {
};
/* tslint:enable:object-literal-sort-keys */

public static FAILURE_STRING_FACTORY = (name: string) => `The key '${name}' is not sorted alphabetically`;
public static FAILURE_STRING_FACTORY = (name: string) => {
return `The key '${name}' is not sorted alphabetically`;
}

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new ObjectLiteralSortKeysWalker(sourceFile, this.getOptions()));
Expand Down
4 changes: 3 additions & 1 deletion src/rules/restrictPlusOperandsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export class Rule extends Lint.Rules.TypedRule {
/* tslint:enable:object-literal-sort-keys */

public static MISMATCHED_TYPES_FAILURE = "Types of values used in '+' operation must match";
public static UNSUPPORTED_TYPE_FAILURE_FACTORY = (type: string) => `cannot add type ${type}`;
public static UNSUPPORTED_TYPE_FAILURE_FACTORY = (type: string) => {
return `cannot add type ${type}`;
}

public applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[] {
return this.applyWithWalker(new RestrictPlusOperandsWalker(sourceFile, this.getOptions(), program));
Expand Down
2 changes: 1 addition & 1 deletion test/ruleLoaderTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe("Rule Loader", () => {

assert.throws(
() => loadRules(invalidConfiguration, {}, RULES_DIRECTORY, true),
/array-type/
/array-type/,
);
});
});

0 comments on commit 11e50fb

Please sign in to comment.