Skip to content

Commit

Permalink
Fix lint and other small tweaks to recent PRs (palantir#4536)
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya authored Feb 23, 2019
1 parent bd4a048 commit 03a3bdd
Show file tree
Hide file tree
Showing 23 changed files with 41 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/language/rule/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export interface IRuleMetadata {
codeExamples?: ICodeExample[];
}

export type RuleType = "functionality" | "maintainability" | "style" | "typescript" | "format";
export type RuleType = "functionality" | "maintainability" | "style" | "typescript" | "formatting";

export type RuleSeverity = "warning" | "error" | "off";

Expand Down
3 changes: 2 additions & 1 deletion src/language/walker/programAwareRuleWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import { RuleWalker } from "./ruleWalker";
* so it's generally preferable to use applyWithFunction instead of applyWithWalker.
* @see https://github.com/palantir/tslint/issues/2522
*/
export class ProgramAwareRuleWalker extends RuleWalker { // tslint:disable-line deprecation
// tslint:disable-next-line deprecation
export class ProgramAwareRuleWalker extends RuleWalker {
private readonly typeChecker: ts.TypeChecker;

constructor(
Expand Down
3 changes: 2 additions & 1 deletion src/language/walker/scopeAwareRuleWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ import { RuleWalker } from "./ruleWalker";
* });
* }
*/
export abstract class ScopeAwareRuleWalker<T> extends RuleWalker { // tslint:disable-line deprecation
// tslint:disable-next-line deprecation
export abstract class ScopeAwareRuleWalker<T> extends RuleWalker {
private readonly scopeStack: T[];

constructor(sourceFile: ts.SourceFile, options: IOptions) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/alignRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class Rule extends Lint.Rules.AbstractRule {
maxLength: 5,
},
optionExamples: [[true, "parameters", "statements"]],
type: "format",
type: "formatting",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Expand Down
2 changes: 1 addition & 1 deletion src/rules/arrowParensRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class Rule extends Lint.Rules.AbstractRule {
enum: [BAN_SINGLE_ARG_PARENS],
},
optionExamples: [true, [true, BAN_SINGLE_ARG_PARENS]],
type: "format",
type: "formatting",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Expand Down
2 changes: 1 addition & 1 deletion src/rules/eoflineRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class Rule extends Lint.Rules.AbstractRule {
options: null,
optionExamples: [true],
hasFix: true,
type: "format",
type: "formatting",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Expand Down
2 changes: 1 addition & 1 deletion src/rules/importSpacingRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class Rule extends Lint.Rules.AbstractRule {
optionsDescription: "Not configurable.",
options: null,
optionExamples: [true],
type: "format",
type: "formatting",
typescriptOnly: false,
};

Expand Down
2 changes: 1 addition & 1 deletion src/rules/indentRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class Rule extends Lint.Rules.AbstractRule {
[true, OPTION_USE_TABS, OPTION_INDENT_SIZE_2],
],
hasFix: true,
type: "format",
type: "formatting",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Expand Down
2 changes: 1 addition & 1 deletion src/rules/jsdocFormatRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class Rule extends Lint.Rules.AbstractRule {
},
},
optionExamples: [true, [true, OPTION_CHECK_MULTILINE_START]],
type: "format",
type: "formatting",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Expand Down
2 changes: 1 addition & 1 deletion src/rules/linebreakStyleRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class Rule extends Lint.Rules.AbstractRule {
enum: [OPTION_LINEBREAK_STYLE_LF, OPTION_LINEBREAK_STYLE_CRLF],
},
optionExamples: [[true, OPTION_LINEBREAK_STYLE_LF], [true, OPTION_LINEBREAK_STYLE_CRLF]],
type: "format",
type: "formatting",
typescriptOnly: false,
hasFix: true,
};
Expand Down
2 changes: 1 addition & 1 deletion src/rules/maxLineLengthRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class Rule extends Lint.Rules.AbstractRule {
},
],
],
type: "format",
type: "formatting",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Expand Down
2 changes: 1 addition & 1 deletion src/rules/newParensRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Rule extends Lint.Rules.AbstractRule {
optionsDescription: "Not configurable.",
options: null,
optionExamples: [true],
type: "format",
type: "formatting",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Expand Down
2 changes: 1 addition & 1 deletion src/rules/newlineBeforeReturnRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class Rule extends Lint.Rules.AbstractRule {
optionsDescription: "Not configurable.",
options: {},
optionExamples: [true],
type: "format",
type: "formatting",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noConsecutiveBlankLinesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Rule extends Lint.Rules.AbstractRule {
minimum: "1",
},
optionExamples: [true, [true, 2]],
type: "format",
type: "formatting",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noIrregularWhitespaceRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Rule extends Lint.Rules.AbstractRule {
optionsDescription: "Not configurable.",
options: null,
optionExamples: [true],
type: "format",
type: "formatting",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Expand Down
29 changes: 17 additions & 12 deletions src/rules/noRestrictedGlobalsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@
* limitations under the License.
*/

import { isBindingElement, isComputedPropertyName, isIdentifier, isPropertyAccessExpression } from "tsutils";
import {
isBindingElement,
isComputedPropertyName,
isIdentifier,
isPropertyAccessExpression,
} from "tsutils";
import * as ts from "typescript";

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

export class Rule extends Lint.Rules.TypedRule {
Expand Down Expand Up @@ -50,14 +56,7 @@ export class Rule extends Lint.Rules.TypedRule {
type: "list",
items: { type: "string" },
},
optionExamples: [
[
true,
"name",
"length",
"event",
],
],
optionExamples: [[true, "name", "length", "event"]],
type: "functionality",
typescriptOnly: false,
requiresTypeInfo: true,
Expand All @@ -69,12 +68,18 @@ export class Rule extends Lint.Rules.TypedRule {
}

public applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[] {
const bannedList = this.ruleArguments.length > 0 ? this.ruleArguments : ["event", "name", "length"];
const bannedList =
this.ruleArguments.length > 0 ? this.ruleArguments : ["event", "name", "length"];
const bannedGlobals = new Set(bannedList);
if (sourceFile.isDeclarationFile) {
return [];
} else {
return this.applyWithFunction(sourceFile, walk, bannedGlobals, program.getTypeChecker());
return this.applyWithFunction(
sourceFile,
walk,
bannedGlobals,
program.getTypeChecker(),
);
}
}
}
Expand Down Expand Up @@ -113,7 +118,7 @@ function walk(ctx: Lint.WalkContext<Set<string>>, checker: ts.TypeChecker): void
return;
}

const isAmbientGlobal = declarations.some((decl) => decl.getSourceFile().isDeclarationFile);
const isAmbientGlobal = declarations.some(decl => decl.getSourceFile().isDeclarationFile);

if (isAmbientGlobal) {
ctx.addFailureAtNode(node, Rule.FAILURE_STRING(node.text));
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noTrailingWhitespaceRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class Rule extends Lint.Rules.AbstractRule {
},
},
optionExamples: [true, [true, OPTION_IGNORE_COMMENTS], [true, OPTION_IGNORE_JSDOC]],
type: "format",
type: "formatting",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Expand Down
2 changes: 1 addition & 1 deletion src/rules/numberLiteralFormatRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Rule extends Lint.Rules.AbstractRule {
Helps keep a consistent style with numeric literals.
Non-standard literals are more difficult to scan through and can be a symptom of typos.
`,
type: "format",
type: "formatting",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Expand Down
2 changes: 1 addition & 1 deletion src/rules/quotemarkRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class Rule extends Lint.Rules.AbstractRule {
[true, OPTION_SINGLE, OPTION_AVOID_ESCAPE, OPTION_AVOID_TEMPLATE],
[true, OPTION_SINGLE, OPTION_JSX_DOUBLE],
],
type: "format",
type: "formatting",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Expand Down
2 changes: 1 addition & 1 deletion src/rules/semicolonRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class Rule extends Lint.Rules.AbstractRule {
[true, OPTION_ALWAYS, OPTION_IGNORE_INTERFACES],
[true, OPTION_ALWAYS, OPTION_IGNORE_BOUND_CLASS_METHODS],
],
type: "format",
type: "formatting",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Expand Down
2 changes: 1 addition & 1 deletion src/rules/trailingCommaRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class Rule extends Lint.Rules.AbstractRule {
},
],
],
type: "format",
type: "formatting",
typescriptOnly: false,
};
/* tslint:enable:object-literal-sort-keys */
Expand Down
2 changes: 1 addition & 1 deletion src/rules/typedefWhitespaceRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class Rule extends Lint.Rules.AbstractRule {
},
],
],
type: "format",
type: "formatting",
typescriptOnly: true,
hasFix: true,
};
Expand Down
2 changes: 1 addition & 1 deletion src/rules/whitespaceRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class Rule extends Lint.Rules.AbstractRule {
maxLength: 11,
},
optionExamples: [[true, "check-branch", "check-operator", "check-typecast"]],
type: "format",
type: "formatting",
typescriptOnly: false,
hasFix: true,
};
Expand Down

0 comments on commit 03a3bdd

Please sign in to comment.