Skip to content

Commit

Permalink
Fix linting errors (palantir#1744)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchen63 authored Nov 19, 2016
1 parent 7c5f3a4 commit 104bba2
Show file tree
Hide file tree
Showing 54 changed files with 171 additions and 109 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Change Log
===

v4.0.0-dev.2
---
* Include latest v4.0.0 changes

v4.0.0
---
* **BREAKING CHANGES**
Expand Down Expand Up @@ -193,6 +197,10 @@ Thanks to our contributors!
* @janaagaard75
* @mprobst

v3.12.0-dev.2
---
* [enhancement] Support TypeScript v2.0.0-dev builds

v3.12.1
---
* Stable release containing changes from the last dev release (v3.12.0-dev.1)
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ tsc --noImplicitAny noImportsRule.ts

Then, if using the CLI, provide the directory that contains this rule as an option to `--rules-dir`. If using TSLint as a library or via `grunt-tslint`, the `options` hash must contain `"rulesDirectory": "..."`. If you run the linter, you'll see that we have now successfully banned all import statements via TSLint!

Finally, enable each custom rule in your [`tslint.json` config file][0] config file.
Finally, enable each custom rule in your [`tslint.json` config file](https://palantir.github.io/tslint/usage/tslint-json/) config file.

Final notes:

Expand All @@ -370,7 +370,7 @@ Just like rules, additional formatters can also be supplied to TSLint via `--for

```typescript
import * as ts from "typescript";
import * as Lint from "tslint/lib/lint";
import * as Lint from "tslint";

export class Formatter extends Lint.Formatters.AbstractFormatter {
public format(failures: Lint.RuleFailure[]): string {
Expand Down Expand Up @@ -412,5 +412,3 @@ Creating a new release
4. Commit with message `Prepare release <version>`
5. Run `npm publish`
6. Create a git tag for the new release and push it ([see existing tags here](https://github.com/palantir/tslint/tags))

[0]: {{site.baseurl | append: "/usage/tslint-json/"}}
2 changes: 1 addition & 1 deletion docs/develop/custom-formatters/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Just like [custom rules][0], additional formatters can also be supplied to TSLin

```ts
import * as ts from "typescript";
import * as Lint from "tslint/lib/lint";
import * as Lint from "tslint";

export class Formatter extends Lint.Formatters.AbstractFormatter {
public format(failures: Lint.RuleFailure[]): string {
Expand Down
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
4 changes: 2 additions & 2 deletions 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 All @@ -73,7 +73,7 @@ export class EnableDisableRulesWalker extends SkippableTokenAwareRuleWalker {
rulesList = commentTextParts[1].split(/\s+/).slice(1);

// remove empty items and potential comment end.
rulesList = rulesList.filter(item => !!item && item.indexOf("*/") === -1);
rulesList = rulesList.filter((item) => !!item && item.indexOf("*/") === -1);

// potentially there were no items, so default to `all`.
rulesList = rulesList.length > 0 ? rulesList : ["all"];
Expand Down
4 changes: 2 additions & 2 deletions src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import * as ts from "typescript";

import {
DEFAULT_CONFIG,
IConfigurationFile,
findConfiguration,
findConfigurationPath,
getRelativePath,
getRulesDirectories,
IConfigurationFile,
loadConfigurationFromPath,
} from "./configuration";
import { EnableDisableRulesWalker } from "./enableDisableRules";
Expand All @@ -41,7 +41,7 @@ import { arrayify, dedent } from "./utils";
* Linter that can lint multiple files in consecutive runs.
*/
class Linter {
public static VERSION = "4.0.0";
public static VERSION = "4.0.0-dev.2";

public static findConfiguration = findConfiguration;
public static findConfigurationPath = findConfigurationPath;
Expand Down
12 changes: 7 additions & 5 deletions 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 All @@ -56,7 +58,7 @@ class AdjacentOverloadSignaturesWalker extends Lint.RuleWalker {
}

public visitInterfaceDeclaration(node: ts.InterfaceDeclaration): void {
this.checkOverloadsAdjacent(node.members, member => member.name && getTextOfPropertyName(member.name));
this.checkOverloadsAdjacent(node.members, (member) => member.name && getTextOfPropertyName(member.name));
super.visitInterfaceDeclaration(node);
}

Expand All @@ -71,7 +73,7 @@ class AdjacentOverloadSignaturesWalker extends Lint.RuleWalker {
}

private visitStatements(statements: ts.Statement[]) {
this.checkOverloadsAdjacent(statements, statement => {
this.checkOverloadsAdjacent(statements, (statement) => {
if (statement.kind === ts.SyntaxKind.FunctionDeclaration) {
const name = (statement as ts.FunctionDeclaration).name;
return name && name.text;
Expand All @@ -81,8 +83,8 @@ class AdjacentOverloadSignaturesWalker extends Lint.RuleWalker {
});
}

private visitMembers(members: (ts.TypeElement | ts.ClassElement)[]) {
this.checkOverloadsAdjacent(members, member => member.name && getTextOfPropertyName(member.name));
private visitMembers(members: Array<ts.TypeElement | ts.ClassElement>) {
this.checkOverloadsAdjacent(members, (member) => member.name && getTextOfPropertyName(member.name));
}

/** 'getOverloadName' may return undefined for nodes that cannot be overloads, e.g. a `const` declaration. */
Expand Down
2 changes: 1 addition & 1 deletion src/rules/alignRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Rule extends Lint.Rules.AbstractRule {
type SourcePosition = {
line: number;
character: number;
}
};

class AlignWalker extends Lint.RuleWalker {
public visitConstructorDeclaration(node: ts.ConstructorDeclaration) {
Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -102,7 +102,7 @@ export class BanFunctionWalker extends Lint.RuleWalker {
const failure = this.createFailure(
expression.getStart(),
expression.getWidth(),
Rule.FAILURE_STRING_FACTORY(`${leftSideExpression}.${rightSideExpression}`, bannedFunction[2])
Rule.FAILURE_STRING_FACTORY(`${leftSideExpression}.${rightSideExpression}`, bannedFunction[2]),
);
this.addFailure(failure);
}
Expand Down
4 changes: 2 additions & 2 deletions src/rules/commentFormatRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ function startsWith(commentText: string, changeCase: (str: string) => string) {
}

function startsWithLowercase(commentText: string) {
return startsWith(commentText, c => c.toLowerCase());
return startsWith(commentText, (c) => c.toLowerCase());
}

function startsWithUppercase(commentText: string) {
return startsWith(commentText, c => c.toUpperCase());
return startsWith(commentText, (c) => c.toUpperCase());
}

function startsWithSpace(commentText: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/completedDocsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class CompletedDocsWalker extends Lint.ProgramAwareRuleWalker {

const comments = this.getTypeChecker().getSymbolAtLocation(node.name).getDocumentationComment();

if (comments.map(comment => comment.text).join("").trim() === "") {
if (comments.map((comment) => comment.text).join("").trim() === "") {
this.addFailure(this.createDocumentationFailure(node, nodeToCheck));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/rules/curlyRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class CurlyWalker extends Lint.RuleWalker {
this.addFailure(this.createFailure(
node.getStart(),
node.thenStatement.getEnd() - node.getStart(),
Rule.IF_FAILURE_STRING
Rule.IF_FAILURE_STRING,
));
}

Expand All @@ -97,7 +97,7 @@ class CurlyWalker extends Lint.RuleWalker {
this.addFailure(this.createFailure(
elseKeywordNode.getStart(),
node.elseStatement.getEnd() - elseKeywordNode.getStart(),
Rule.ELSE_FAILURE_STRING
Rule.ELSE_FAILURE_STRING,
));
}

Expand Down
13 changes: 8 additions & 5 deletions src/rules/cyclomaticComplexityRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/

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

export class Rule extends Lint.Rules.AbstractRule {

Expand Down 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/linebreakStyleRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class Rule extends Lint.Rules.AbstractRule {
sourceFile.languageVersion,
false,
sourceFile.languageVariant,
sourceFile.getFullText()
sourceFile.getFullText(),
);

const linebreakStyle = this.getOptions().ruleArguments[0] || OPTION_LINEBREAK_STYLE_LF;
Expand Down
4 changes: 2 additions & 2 deletions src/rules/maxClassesPerFileRule.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Lint from "../index";
import * as ts from "typescript";
import * as ts from "typescript";
import * as Lint from "../index";

export class Rule extends Lint.Rules.AbstractRule {

Expand Down
4 changes: 2 additions & 2 deletions src/rules/maxFileLineCountRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as Lint from "../index";
import * as ts from "typescript";
import * as Lint from "../index";

export class Rule extends Lint.Rules.AbstractRule {
/* tslint:disable:object-literal-sort-keys */
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/rules/memberAccessRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class MemberAccessWalker extends Lint.RuleWalker {
node.modifiers,
ts.SyntaxKind.PublicKeyword,
ts.SyntaxKind.PrivateKeyword,
ts.SyntaxKind.ProtectedKeyword
ts.SyntaxKind.ProtectedKeyword,
);

if (!hasAnyVisibilityModifiers) {
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
2 changes: 1 addition & 1 deletion src/rules/noEmptyRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class BlockWalker extends Lint.RuleWalker {
ts.SyntaxKind.PrivateKeyword,
ts.SyntaxKind.ProtectedKeyword,
ts.SyntaxKind.PublicKeyword,
ts.SyntaxKind.ReadonlyKeyword
ts.SyntaxKind.ReadonlyKeyword,
);

if (hasPropertyAccessModifier) {
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
2 changes: 1 addition & 1 deletion src/rules/noSwitchCaseFallThroughRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class NoSwitchCaseFallThroughWalker extends Lint.RuleWalker {
this.addFailure(this.createFailure(
switchClauses[i + 1].getStart(),
"case".length,
`${Rule.FAILURE_STRING_PART}'case'`
`${Rule.FAILURE_STRING_PART}'case'`,
));
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/rules/noUnsafeFinallyRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/

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

export class Rule extends Lint.Rules.AbstractRule {
/* tslint:disable:object-literal-sort-keys */
Expand All @@ -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 Expand Up @@ -81,7 +79,7 @@ interface IFinallyScope {
/**
* A collection of `break` or `continue` labels in this scope.
*/
labels: Array<string>;
labels: string[];
}

/**
Expand Down
Loading

0 comments on commit 104bba2

Please sign in to comment.