diff --git a/src/configuration.ts b/src/configuration.ts index 7de34217649..0f2ffc96f70 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -480,6 +480,7 @@ export function convertRuleOptions(ruleConfiguration: Map { const options: IOptions = { + disabledIntervals: [], // deprecated, so just provide an empty array. ruleArguments: partialOptions.ruleArguments || [], ruleName, ruleSeverity: partialOptions.ruleSeverity || "error", diff --git a/src/language/rule/abstractRule.ts b/src/language/rule/abstractRule.ts index 741b66fe2cb..058d6ab31b6 100644 --- a/src/language/rule/abstractRule.ts +++ b/src/language/rule/abstractRule.ts @@ -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; } } diff --git a/src/language/rule/rule.ts b/src/language/rule/rule.ts index 6726d830217..947d682c13a 100644 --- a/src/language/rule/rule.ts +++ b/src/language/rule/rule.ts @@ -18,6 +18,7 @@ import * as ts from "typescript"; import {arrayify, flatMap} from "../../utils"; +import {IWalker} from "../walker"; export interface RuleConstructor { metadata: IRuleMetadata; @@ -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 { diff --git a/src/rules/maxFileLineCountRule.ts b/src/rules/maxFileLineCountRule.ts index 9ecc15072ec..33a00a978e5 100644 --- a/src/rules/maxFileLineCountRule.ts +++ b/src/rules/maxFileLineCountRule.ts @@ -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 { diff --git a/src/rules/whitespaceRule.ts b/src/rules/whitespaceRule.ts index bfada6493e2..fa8a679f6ea 100644 --- a/src/rules/whitespaceRule.ts +++ b/src/rules/whitespaceRule.ts @@ -263,6 +263,5 @@ function walk(ctx: Lint.WalkContext) { } const fix = Lint.Replacement.appendText(position, " "); ctx.addFailureAt(position, 1, Rule.FAILURE_STRING, fix); - } } diff --git a/test/configurationTests.ts b/test/configurationTests.ts index ae39fd7ee11..1b6cbd603b4 100644 --- a/test/configurationTests.ts +++ b/test/configurationTests.ts @@ -98,6 +98,7 @@ describe("Configuration", () => { const initial = getEmptyConfig(); initial.rules.set("s", { ruleArguments: undefined, ruleSeverity: undefined }); assert.deepEqual(convertRuleOptions(initial.rules)[0], { + disabledIntervals: [], ruleArguments: [], ruleName: "s", ruleSeverity: "error", diff --git a/test/ruleLoaderTests.ts b/test/ruleLoaderTests.ts index 149c485bc7f..614e302567a 100644 --- a/test/ruleLoaderTests.ts +++ b/test/ruleLoaderTests.ts @@ -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); @@ -44,7 +44,7 @@ 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); @@ -52,9 +52,9 @@ describe("Rule Loader", () => { 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]); @@ -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]); @@ -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]); @@ -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);