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

Commit

Permalink
Add back disabledIntervals, and deprecate it
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-hanson committed May 6, 2017
1 parent 91990ff commit 9cdbb18
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ export function convertRuleOptions(ruleConfiguration: Map<string, Partial<IOptio
const output: IOptions[] = [];
ruleConfiguration.forEach((partialOptions, ruleName) => {
const options: IOptions = {
disabledIntervals: [], // deprecated, so just provide an empty array.
ruleArguments: partialOptions.ruleArguments || [],
ruleName,
ruleSeverity: partialOptions.ruleSeverity || "error",
Expand Down
7 changes: 7 additions & 0 deletions src/language/rule/abstractRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,11 @@ export abstract class AbstractRule implements IRule {
walkFn(ctx);
return ctx.failures;
}

/**
* @deprecated
* Failures will be filtered based on `tslint:disable` comments by tslint.
* This method now does nothing.
*/
protected filterFailures(failures: RuleFailure[]) { return failures; }
}
17 changes: 17 additions & 0 deletions src/language/rule/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import * as ts from "typescript";

import {arrayify, flatMap} from "../../utils";
import {IWalker} from "../walker";

export interface RuleConstructor {
metadata: IRuleMetadata;
Expand Down Expand Up @@ -98,12 +99,28 @@ export interface IOptions {
ruleArguments: any[];
ruleSeverity: RuleSeverity;
ruleName: string;
/**
* @deprecated
* Tslint now handles disables itself.
* This will be empty.
*/
disabledIntervals: IDisabledInterval[]; // tslint:disable-line deprecation
}

/**
* @deprecated
* These are now handled internally.
*/
export interface IDisabledInterval {
startPosition: number;
endPosition: number;
}

export interface IRule {
getOptions(): IOptions;
isEnabled(): boolean;
apply(sourceFile: ts.SourceFile): RuleFailure[];
applyWithWalker(walker: IWalker): RuleFailure[];
}

export interface ITypedRule extends IRule {
Expand Down
6 changes: 3 additions & 3 deletions src/rules/maxFileLineCountRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export class Rule extends Lint.Rules.AbstractRule {
};
/* tslint:enable:object-literal-sort-keys */

public static FAILURE_STRING_FACTORY(lineCount: number, lineLimit: number) {
return `This file has ${lineCount} lines, which exceeds the maximum of ${lineLimit} lines allowed. `
+ `Consider breaking this file up into smaller parts`;
public static FAILURE_STRING(lineCount: number, lineLimit: number) {
return `This file has ${lineCount} lines, which exceeds the maximum of ${lineLimit} lines allowed. ` +
`Consider breaking this file up into smaller parts`;
}

public isEnabled(): boolean {
Expand Down
1 change: 0 additions & 1 deletion src/rules/whitespaceRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,5 @@ function walk(ctx: Lint.WalkContext<Options>) {
}
const fix = Lint.Replacement.appendText(position, " ");
ctx.addFailureAt(position, 1, Rule.FAILURE_STRING, fix);

}
}
1 change: 1 addition & 0 deletions test/configurationTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ describe("Configuration", () => {
const initial = getEmptyConfig();
initial.rules.set("s", { ruleArguments: undefined, ruleSeverity: undefined });
assert.deepEqual<IOptions>(convertRuleOptions(initial.rules)[0], {
disabledIntervals: [],
ruleArguments: [],
ruleName: "s",
ruleSeverity: "error",
Expand Down
36 changes: 18 additions & 18 deletions test/ruleLoaderTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ const testRulesDir = "test/rules";
describe("Rule Loader", () => {
it("loads core rules", () => {
const validConfiguration: IOptions[] = [
{ ruleName: "class-name", ruleArguments: [], ruleSeverity: "error" },
{ ruleName: "eofline", ruleArguments: [], ruleSeverity: "error" },
{ ruleName: "forin", ruleArguments: [], ruleSeverity: "error" },
{ ruleName: "no-debugger", ruleArguments: [], ruleSeverity: "error" },
{ ruleName: "quotemark", ruleArguments: ["double"], ruleSeverity: "error" },
{ ruleName: "class-name", ruleArguments: [], ruleSeverity: "error", disabledIntervals: [] },
{ ruleName: "eofline", ruleArguments: [], ruleSeverity: "error", disabledIntervals: [] },
{ ruleName: "forin", ruleArguments: [], ruleSeverity: "error", disabledIntervals: [] },
{ ruleName: "no-debugger", ruleArguments: [], ruleSeverity: "error", disabledIntervals: [] },
{ ruleName: "quotemark", ruleArguments: ["double"], ruleSeverity: "error", disabledIntervals: [] },
];

const rules = loadRules(validConfiguration, builtRulesDir);
Expand All @@ -44,17 +44,17 @@ describe("Rule Loader", () => {

it("ignores off rules", () => {
const validConfiguration: IOptions[] = [
{ ruleName: "forin", ruleArguments: [], ruleSeverity: "off" },
{ ruleName: "forin", ruleArguments: [], ruleSeverity: "off", disabledIntervals: [] },
];
const rules = loadRules(validConfiguration, builtRulesDir);
assert.equal(rules.length, 0);
});

it("ignores invalid rules", () => {
const invalidConfiguration: IOptions[] = [
{ ruleName: "class-name", ruleArguments: [], ruleSeverity: "error" },
{ ruleName: "invalidConfig1", ruleArguments: [], ruleSeverity: "error" },
{ ruleName: "invalidConfig2", ruleArguments: [], ruleSeverity: "off" },
{ ruleName: "class-name", ruleArguments: [], ruleSeverity: "error", disabledIntervals: [] },
{ ruleName: "invalidConfig1", ruleArguments: [], ruleSeverity: "error", disabledIntervals: [] },
{ ruleName: "invalidConfig2", ruleArguments: [], ruleSeverity: "off", disabledIntervals: [] },
];

const rules = loadRules(invalidConfiguration, [builtRulesDir]);
Expand All @@ -63,8 +63,8 @@ describe("Rule Loader", () => {

it("properly sets rule severity with options", () => {
const withOptions: IOptions[] = [
{ ruleName: "callable-types", ruleArguments: [], ruleSeverity: "error" },
{ ruleName: "max-line-length", ruleArguments: [140], ruleSeverity: "warning" },
{ ruleName: "callable-types", ruleArguments: [], ruleSeverity: "error", disabledIntervals: [] },
{ ruleName: "max-line-length", ruleArguments: [140], ruleSeverity: "warning", disabledIntervals: [] },
];

const rules = loadRules(withOptions, [builtRulesDir]);
Expand All @@ -75,11 +75,11 @@ describe("Rule Loader", () => {

it("works with rulesDirectory argument as an Array", () => {
const validConfiguration: IOptions[] = [
{ ruleName: "class-name", ruleArguments: [], ruleSeverity: "error" },
{ ruleName: "eofline", ruleArguments: [], ruleSeverity: "error" },
{ ruleName: "forin", ruleArguments: [], ruleSeverity: "error" },
{ ruleName: "no-debugger", ruleArguments: [], ruleSeverity: "error" },
{ ruleName: "quotemark", ruleArguments: ["double"], ruleSeverity: "error" },
{ ruleName: "class-name", ruleArguments: [], ruleSeverity: "error", disabledIntervals: [] },
{ ruleName: "eofline", ruleArguments: [], ruleSeverity: "error", disabledIntervals: [] },
{ ruleName: "forin", ruleArguments: [], ruleSeverity: "error", disabledIntervals: [] },
{ ruleName: "no-debugger", ruleArguments: [], ruleSeverity: "error", disabledIntervals: [] },
{ ruleName: "quotemark", ruleArguments: ["double"], ruleSeverity: "error", disabledIntervals: [] },
];

const rules = loadRules(validConfiguration, [builtRulesDir]);
Expand All @@ -88,8 +88,8 @@ describe("Rule Loader", () => {

it("loads js rules", () => {
const validConfiguration: IOptions[] = [
{ ruleName: "class-name", ruleArguments: [], ruleSeverity: "error" },
{ ruleName: "await-promise", ruleArguments: [], ruleSeverity: "error" },
{ ruleName: "class-name", ruleArguments: [], ruleSeverity: "error", disabledIntervals: [] },
{ ruleName: "await-promise", ruleArguments: [], ruleSeverity: "error", disabledIntervals: [] },
];

const rules = loadRules(validConfiguration, builtRulesDir, true);
Expand Down

0 comments on commit 9cdbb18

Please sign in to comment.