From bce0026dd259a38d12293c2c3fdba494da58f1b6 Mon Sep 17 00:00:00 2001 From: Rafael Santana Date: Thu, 10 May 2018 04:58:55 -0300 Subject: [PATCH] fix: some rules not considering options correctly (#617) --- src/maxInlineDeclarationsRule.ts | 159 +++++++++----- src/noInputPrefixRule.ts | 2 +- src/preferInlineDecoratorRule.ts | 10 +- test/inlineTemplateMaxLinesRule.spec.ts | 265 ------------------------ test/maxInlineDeclarationsRule.spec.ts | 234 +++++++++++++++++++++ test/noInputPrefixRule.spec.ts | 18 +- test/preferInlineDecoratorRule.spec.ts | 16 +- 7 files changed, 359 insertions(+), 345 deletions(-) delete mode 100644 test/inlineTemplateMaxLinesRule.spec.ts create mode 100644 test/maxInlineDeclarationsRule.spec.ts diff --git a/src/maxInlineDeclarationsRule.ts b/src/maxInlineDeclarationsRule.ts index 03f0a9730..ea5888898 100644 --- a/src/maxInlineDeclarationsRule.ts +++ b/src/maxInlineDeclarationsRule.ts @@ -1,53 +1,82 @@ -import * as Lint from 'tslint'; -import * as ts from 'typescript'; -import { ComponentMetadata } from './angular/metadata'; +import { sprintf } from 'sprintf-js'; +import { IOptions, IRuleMetadata, RuleFailure, Rules, Utils } from 'tslint/lib'; +import { SourceFile } from 'typescript/lib/typescript'; +import { CodeWithSourceMap, ComponentMetadata } from './angular/metadata'; import { NgWalker } from './angular/ngWalker'; -export class Rule extends Lint.Rules.AbstractRule { - public static metadata: Lint.IRuleMetadata = { - ruleName: 'max-inline-declarations', - type: 'maintainability', - description: 'Disallows having too many lines in inline template or styles. Forces separate template or styles file creation.', - descriptionDetails: 'See more at https://angular.io/guide/styleguide#style-05-04', +const DEFAULT_STYLES_LIMIT: number = 3; +const DEFAULT_TEMPLATE_LIMIT: number = 3; +const OPTION_STYLES = 'styles'; +const OPTION_TEMPLATE = 'template'; + +export class Rule extends Rules.AbstractRule { + static readonly metadata: IRuleMetadata = { + description: 'Disallows having too many lines in inline template and styles. Forces separate template or styles file creation.', + descriptionDetails: 'See more at https://angular.io/guide/styleguide#style-05-04.', + optionExamples: [true, [true, { [OPTION_STYLES]: 8, [OPTION_TEMPLATE]: 5 }]], options: { - type: 'array', items: { + properties: { + [OPTION_STYLES]: { + type: 'number' + }, + [OPTION_TEMPLATE]: { + type: 'number' + } + }, type: 'object' - } + }, + maxLength: 1, + minLength: 0, + type: 'array' }, - optionsDescription: 'Define inline template and styles lines limit.', - optionExamples: ['[{template: 5, styles: 8}]'], + optionsDescription: Utils.dedent` + It can take an optional object with the properties '${OPTION_STYLES}' and '${OPTION_TEMPLATE}': + * \`${OPTION_STYLES}\` - number > 0 defining the maximum allowed inline lines for styles. Defaults to ${DEFAULT_STYLES_LIMIT}. + * \`${OPTION_TEMPLATE}\` - number > 0 defining the maximum allowed inline lines for template. Defaults to ${DEFAULT_TEMPLATE_LIMIT}. + `, + rationale: + "Large, inline templates and styles obscure the component's purpose and implementation, reducing readability and maintainability.", + ruleName: 'max-inline-declarations', + type: 'maintainability', typescriptOnly: true }; - private readonly templateLinesLimit: number = 3; - private readonly stylesLinesLimit: number = 3; + static readonly FAILURE_STRING = 'Exceeds the maximum allowed inline lines for %s. Defined limit: %s / total lines: %s'; - constructor(options: Lint.IOptions) { - super(options); - if (options.ruleArguments.length > 1) { - const args = options.ruleArguments[1]; - if (args.template > -1) { - this.templateLinesLimit = args.template; - } - if (args.styles > -1) { - this.stylesLinesLimit = args.styles; - } - } - } - - public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - return this.applyWithWalker( - new MaxInlineDeclarationsValidator(sourceFile, this.getOptions(), this.templateLinesLimit, this.stylesLinesLimit) - ); + apply(sourceFile: SourceFile): RuleFailure[] { + return this.applyWithWalker(new MaxInlineDeclarationsValidator(sourceFile, this.getOptions())); } } +type PropertyType = 'styles' | 'template'; + +export type PropertyPair = { [key in PropertyType]?: number }; + +const generateFailure = (type: PropertyType, limit: number, value: number): string => { + return sprintf(Rule.FAILURE_STRING, type, limit, value); +}; + +export const getStylesFailure = (value: number, limit = DEFAULT_STYLES_LIMIT): string => { + return generateFailure(OPTION_STYLES, limit, value); +}; + +export const getTemplateFailure = (value: number, limit = DEFAULT_TEMPLATE_LIMIT): string => { + return generateFailure(OPTION_TEMPLATE, limit, value); +}; + export class MaxInlineDeclarationsValidator extends NgWalker { - private newLineRegExp = /\r\n|\r|\n/; + private readonly stylesLinesLimit = DEFAULT_STYLES_LIMIT; + private readonly templateLinesLimit = DEFAULT_TEMPLATE_LIMIT; + private readonly newLineRegExp = /\r\n|\r|\n/; - constructor(sourceFile: ts.SourceFile, options: Lint.IOptions, private templateLinesLimit: number, private stylesLinesLimit: number) { + constructor(sourceFile: SourceFile, options: IOptions) { super(sourceFile, options); + + const { styles, template } = (options.ruleArguments[0] || []) as PropertyPair; + + this.stylesLinesLimit = styles > -1 ? styles : this.stylesLinesLimit; + this.templateLinesLimit = template > -1 ? template : this.templateLinesLimit; } protected visitNgComponent(metadata: ComponentMetadata): void { @@ -56,30 +85,44 @@ export class MaxInlineDeclarationsValidator extends NgWalker { super.visitNgComponent(metadata); } - private validateInlineTemplate(metadata: ComponentMetadata): void { - if (this.hasInlineTemplate(metadata) && this.getTemplateLinesCount(metadata) > this.templateLinesLimit) { - const templateLinesCount = this.getTemplateLinesCount(metadata); - const msg = `Inline template lines limit exceeded. Defined limit: ${this.templateLinesLimit} / template lines: ${templateLinesCount}`; - this.addFailureAtNode(metadata.template.node, msg); - } + private getTotalLines(source: CodeWithSourceMap['source']): number { + return source.trim().split(this.newLineRegExp).length; + } + + private getTemplateLinesCount(metadata: ComponentMetadata): number { + return this.hasInlineTemplate(metadata) ? this.getTotalLines(metadata.template.template.source) : 0; } private hasInlineTemplate(metadata: ComponentMetadata): boolean { - return !!metadata.template && !metadata.template.url && !!metadata.template.template && !!metadata.template.template.source; + return !!(metadata.template && !metadata.template.url && metadata.template.template && metadata.template.template.source); } - private getTemplateLinesCount(metadata: ComponentMetadata): number { - return metadata.template.template.source.split(this.newLineRegExp).length; + private validateInlineTemplate(metadata: ComponentMetadata): void { + const templateLinesCount = this.getTemplateLinesCount(metadata); + + if (templateLinesCount <= this.templateLinesLimit) { + return; + } + + const failureMessage = getTemplateFailure(templateLinesCount, this.templateLinesLimit); + + this.addFailureAtNode(metadata.template.node, failureMessage); } - private validateInlineStyles(metadata: ComponentMetadata): void { - if (this.hasInlineStyles(metadata) && this.getInlineStylesLinesCount(metadata) > this.stylesLinesLimit) { - const stylesLinesCount = this.getInlineStylesLinesCount(metadata); - const msg = `Inline styles lines limit exceeded. Defined limit: ${this.stylesLinesLimit} / styles lines: ${stylesLinesCount}`; - for (let i = 0; i < metadata.styles.length; i++) { - this.addFailureAtNode(metadata.styles[i].node, msg); + private getInlineStylesLinesCount(metadata: ComponentMetadata): number { + let result = 0; + + if (!this.hasInlineStyles(metadata)) { + return result; + } + + for (let i = 0; i < metadata.styles.length; i++) { + if (!metadata.styles[i].url) { + result += this.getTotalLines(metadata.styles[i].style.source); } } + + return result; } private hasInlineStyles(metadata: ComponentMetadata): boolean { @@ -89,6 +132,7 @@ export class MaxInlineDeclarationsValidator extends NgWalker { for (let i = 0; i < metadata.styles.length; i++) { const style = metadata.styles[i]; + if (!style.url && style.style && style.style.source) { return true; } @@ -97,14 +141,17 @@ export class MaxInlineDeclarationsValidator extends NgWalker { return false; } - private getInlineStylesLinesCount(metadata: ComponentMetadata) { - let result = 0; - for (let i = 0; i < metadata.styles.length; i++) { - if (!metadata.styles[i].url) { - result += metadata.styles[i].style.source.split(this.newLineRegExp).length; - } + private validateInlineStyles(metadata: ComponentMetadata): void { + const stylesLinesCount = this.getInlineStylesLinesCount(metadata); + + if (stylesLinesCount <= this.stylesLinesLimit) { + return; } - return result; + const failureMessage = getStylesFailure(stylesLinesCount, this.stylesLinesLimit); + + for (let i = 0; i < metadata.styles.length; i++) { + this.addFailureAtNode(metadata.styles[i].node, failureMessage); + } } } diff --git a/src/noInputPrefixRule.ts b/src/noInputPrefixRule.ts index 266c44557..8e8e455de 100644 --- a/src/noInputPrefixRule.ts +++ b/src/noInputPrefixRule.ts @@ -50,7 +50,7 @@ class NoInputPrefixWalker extends NgWalker { constructor(source: SourceFile, options: IOptions) { super(source, options); - this.blacklistedPrefixes = options.ruleArguments.slice(1); + this.blacklistedPrefixes = options.ruleArguments; } protected visitNgInput(property: PropertyDeclaration, input: Decorator, args: string[]) { diff --git a/src/preferInlineDecoratorRule.ts b/src/preferInlineDecoratorRule.ts index a0b5bf501..415bd1394 100644 --- a/src/preferInlineDecoratorRule.ts +++ b/src/preferInlineDecoratorRule.ts @@ -41,7 +41,7 @@ type DecoratorKeys = | 'ViewChild' | 'ViewChildren'; -export const decoratorKeys = new Set([ +export const decoratorKeys: ReadonlySet = new Set([ 'ContentChild', 'ContentChildren', 'HostBinding', @@ -52,12 +52,16 @@ export const decoratorKeys = new Set([ 'ViewChildren' ]); +export const getFailureMessage = (): string => { + return Rule.FAILURE_STRING; +}; + export class PreferInlineDecoratorWalker extends NgWalker { private readonly blacklistedDecorators: typeof decoratorKeys; constructor(source: SourceFile, options: IOptions) { super(source, options); - this.blacklistedDecorators = new Set(options.ruleArguments.slice(1)); + this.blacklistedDecorators = new Set(options.ruleArguments); } protected visitMethodDecorator(decorator: Decorator) { @@ -86,6 +90,6 @@ export class PreferInlineDecoratorWalker extends NgWalker { } const fix = Replacement.deleteFromTo(decorator.getEnd(), propertyStartPos - 1); - this.addFailureAt(decoratorStartPos, property.getWidth(), Rule.FAILURE_STRING, fix); + this.addFailureAt(decoratorStartPos, property.getWidth(), getFailureMessage(), fix); } } diff --git a/test/inlineTemplateMaxLinesRule.spec.ts b/test/inlineTemplateMaxLinesRule.spec.ts deleted file mode 100644 index 827431677..000000000 --- a/test/inlineTemplateMaxLinesRule.spec.ts +++ /dev/null @@ -1,265 +0,0 @@ -import * as ts from 'typescript'; - -import { assertFailure, assertSuccess } from './testHelper'; - -const getAst = (code: string, file = 'file.ts') => { - return ts.createSourceFile(file, code, ts.ScriptTarget.ES5, true); -}; - -describe('max-inline-declarations', () => { - describe('template', () => { - describe('component has inline template', () => { - it('should succeed when lines limit not exceeded', () => { - const source = ` - @Component({ - selector: 'foobar', - template:
just one line template
' - }) - class Test {} - `; - assertSuccess('max-inline-declarations', source); - }); - - it('should fail when lines limit exceeded default 3 lines limit', () => { - const source = ` - @Component({ - selector: 'foobar', - template: \` -
first line
-
second line
-
third line
-
fourth line
- \` - }) - class Test {} - `; - assertFailure('max-inline-declarations', source, { - message: 'Inline template lines limit exceeded. Defined limit: 3 / template lines: 6', - startPosition: { character: 22, line: 3 }, - endPosition: { character: 13, line: 8 } - }); - }); - - it('should fail when lines limit exceeded custom defined limit', () => { - const source = ` - @Component({ - selector: 'foobar', - template: '
first line
' - }) - class Test {} - `; - - const options = [true, { template: 0 }]; - assertFailure( - 'max-inline-declarations', - source, - { - message: 'Inline template lines limit exceeded. Defined limit: 0 / template lines: 1', - startPosition: { character: 22, line: 3 }, - endPosition: { character: 45, line: 3 } - }, - options - ); - }); - - it('should use default limit if incorrect has been passed', () => { - const source = ` - @Component({ - selector: 'foobar', - template:
first line
' - }) - class Test {} - `; - - const options = [true, { template: -5 }]; - assertSuccess('max-inline-declarations', source, options); - }); - }); - - describe("component hasn't inline template", () => { - it('should not report any failure', () => { - const source = ` - @Component({ - selector: 'foobar', - }) - class Test {} - `; - assertSuccess('max-inline-declarations', source); - }); - }); - - describe('component has template url defined', () => { - it('should not report any failure', () => { - const source = ` - @Component({ - selector: 'foobar', - templateUrl: './foo.html' - }) - class Test {} - `; - - const ast = getAst(source, __dirname + '/../../test/fixtures/inlineTemplateMaxLines/foo.ts'); - assertSuccess('max-inline-declarations', ast); - }); - }); - - describe('component template file exceeded inline template line limit', () => { - it('should not report any failure', () => { - const source = ` - @Component({ - selector: 'foobar', - templateUrl: './large.html' - }) - class Test {} - `; - - const ast = getAst(source, __dirname + '/../../test/fixtures/inlineTemplateMaxLines/foo.ts'); - assertSuccess('max-inline-declarations', ast); - }); - }); - }); - - describe('styles', () => { - describe('component has inline styles', () => { - it('should succeed when lines limit not exceeded', () => { - const source = ` - @Component({ - selector: 'foobar', - styles: ['display: none;'] - }) - class Test {} - `; - assertSuccess('max-inline-declarations', source); - }); - }); - - it('should fail when lines limit exceeded default 3 lines limit', () => { - const source = ` - @Component({ - selector: 'foobar', - styles: [ - \` - display: block; - width: 30px; - height: 40px; - float: left; - \` - ] - }) - class Test {} - `; - assertFailure('max-inline-declarations', source, { - message: 'Inline styles lines limit exceeded. Defined limit: 3 / styles lines: 6', - startPosition: { character: 12, line: 4 }, - endPosition: { character: 13, line: 9 } - }); - }); - - it('should fail when sum of lines (from separate inline styles) limit exceeded default 3 lines limit', () => { - const source = ` - @Component({ - selector: 'foobar', - styles: [\`display: block; - width: 30px;\`, - \`height: 40px; - float: left;\`] - }) - class Test {} - `; - assertFailure('max-inline-declarations', source, { - message: 'Inline styles lines limit exceeded. Defined limit: 3 / styles lines: 4', - startPosition: { character: 19, line: 3 }, - endPosition: { character: 34, line: 4 } - }); - - assertFailure( - 'max-inline-declarations', - source, - { - message: 'Inline styles lines limit exceeded. Defined limit: 3 / styles lines: 4', - startPosition: { character: 21, line: 5 }, - endPosition: { character: 34, line: 6 } - }, - null, - 1 - ); - }); - - it('should fail when lines limit exceeded custom defined limit', () => { - const source = ` - @Component({ - selector: 'foobar', - styles: ['display: none;'] - }) - class Test {} - `; - - const options = [true, { styles: 0 }]; - assertFailure( - 'max-inline-declarations', - source, - { - message: 'Inline styles lines limit exceeded. Defined limit: 0 / styles lines: 1', - startPosition: { character: 19, line: 3 }, - endPosition: { character: 35, line: 3 } - }, - options - ); - }); - - it('should use default limit if incorrect has been passed', () => { - const source = ` - @Component({ - selector: 'foobar', - styles: ['display: none;] - }) - class Test {} - `; - - const options = [true, { styles: -5 }]; - assertSuccess('max-inline-declarations', source, options); - }); - - describe("component hasn't inline styles", () => { - it('should not report any failure', () => { - const source = ` - @Component({ - selector: 'foobar', - }) - class Test {} - `; - assertSuccess('max-inline-declarations', source); - }); - }); - - describe('component has styles url defined', () => { - it('should not report any failure', () => { - const source = ` - @Component({ - selector: 'foobar', - styleUrls: ['./foo.css'] - }) - class Test {} - `; - - const ast = getAst(source, __dirname + '/../../test/fixtures/inlineTemplateMaxLines/foo.ts'); - assertSuccess('max-inline-declarations', ast); - }); - }); - - describe('component styles file exceeded inline styles line limit', () => { - it('should not report any failure', () => { - const source = ` - @Component({ - selector: 'foobar', - styleUrls: ['./large.css'] - }) - class Test {} - `; - - const ast = getAst(source, __dirname + '/../../test/fixtures/inlineTemplateMaxLines/foo.ts'); - assertSuccess('max-inline-declarations', ast); - }); - }); - }); -}); diff --git a/test/maxInlineDeclarationsRule.spec.ts b/test/maxInlineDeclarationsRule.spec.ts new file mode 100644 index 000000000..117b6e9bd --- /dev/null +++ b/test/maxInlineDeclarationsRule.spec.ts @@ -0,0 +1,234 @@ +import { createSourceFile, ScriptTarget, SourceFile } from 'typescript/lib/typescript'; +import { getStylesFailure, getTemplateFailure, PropertyPair, Rule } from '../src/maxInlineDeclarationsRule'; +import { assertFailure, assertFailures, assertSuccess } from './testHelper'; + +type PropertyPairArray = ReadonlyArray; + +const { + metadata: { ruleName } +} = Rule; +const filePath = `${__dirname}/../../test/fixtures/inlineTemplateMaxLines/foo.ts`; + +const getSourceFile = (code: string): SourceFile => { + return createSourceFile(filePath, code, ScriptTarget.ES5, true); +}; + +describe.only(ruleName, () => { + describe('template', () => { + describe('failure', () => { + it('should fail when the number of lines exceeds the default lines limit', () => { + const source = ` + @Component({ + selector: 'foobar', + template: \` +
first line
+
second line
+
third line
+
fourth line
+ \` + }) + class Test {} + `; + assertFailure(ruleName, source, { + endPosition: { character: 13, line: 8 }, + message: getTemplateFailure(4), + startPosition: { character: 22, line: 3 } + }); + }); + + it('should fail when the number of lines exceeds a custom lines limit', () => { + const source = ` + @Component({ + selector: 'foobar', + template: '
first line
' + }) + class Test {} + `; + const options: PropertyPairArray = [{ template: 0 }]; + assertFailure( + ruleName, + source, + { + endPosition: { character: 45, line: 3 }, + message: getTemplateFailure(1, options[0].template), + startPosition: { character: 22, line: 3 } + }, + options + ); + }); + }); + + describe('success', () => { + it('should succeed when the number of lines does not exceeds the default lines limit', () => { + const source = ` + @Component({ + selector: 'foobar', + template: '
just one line template
' + }) + class Test {} + `; + assertSuccess(ruleName, source); + }); + + it('should succeed when a negative limit is used and the number of lines does not exceeds the default lines limit', () => { + const source = ` + @Component({ + selector: 'foobar', + template: '
first line
' + }) + class Test {} + `; + const options: PropertyPairArray = [{ template: -5 }]; + assertSuccess(ruleName, source, options); + }); + }); + }); + + describe('templateUrl', () => { + it('should succeed when the number of lines of a template file exceeds the default lines limit', () => { + const source = ` + @Component({ + selector: 'foobar', + templateUrl: './foobar.html' + }) + class Test {} + `; + assertSuccess(ruleName, getSourceFile(source)); + }); + }); + + describe('styles', () => { + describe('failure', () => { + it('should fail when the number of lines exceeds the default lines limit', () => { + const source = ` + @Component({ + selector: 'foobar', + styles: [ + \` + div { + display: block; + height: 40px; + } + \` + ] + }) + class Test {} + `; + assertFailure(ruleName, source, { + endPosition: { character: 15, line: 9 }, + message: getStylesFailure(4), + startPosition: { character: 14, line: 4 } + }); + }); + + it('should fail when the sum of lines (from separate inline styles) exceeds the default lines limit', () => { + const source = ` + @Component({ + selector: 'foobar', + styles: [ + \` + div { + display: block; + height: 40px; + } + \`, + \` + span { + float: left; + width: 30px; + } + \` + ] + }) + class Test {} + `; + const message = getStylesFailure(8); + assertFailures(ruleName, source, [ + { + endPosition: { character: 15, line: 9 }, + message, + startPosition: { character: 14, line: 4 } + }, + { + endPosition: { character: 15, line: 15 }, + message, + startPosition: { character: 14, line: 10 } + } + ]); + }); + + it('should fail when the number of lines exceeds a custom lines limit', () => { + const source = ` + @Component({ + selector: 'foobar', + styles: ['div { display: none; }'] + }) + class Test {} + `; + const options: PropertyPairArray = [{ styles: 0 }]; + assertFailure( + ruleName, + source, + { + endPosition: { character: 45, line: 3 }, + message: getStylesFailure(1, options[0].styles), + startPosition: { character: 21, line: 3 } + }, + options + ); + }); + }); + + describe('success', () => { + it('should succeed when the number of lines does not exceeds the default lines limit', () => { + const source = ` + @Component({ + selector: 'foobar', + styles: ['div { display: none; }'] + }) + class Test {} + `; + assertSuccess(ruleName, source); + }); + + it('should succeed when a negative limit is used and the number of lines does not exceeds the default lines limit', () => { + const source = ` + @Component({ + selector: 'foobar', + styles: ['div { display: none; }'] + }) + class Test {} + `; + const options: PropertyPairArray = [{ styles: -5 }]; + assertSuccess(ruleName, source, options); + }); + }); + }); + + describe('styleUrls', () => { + it('should succeed when the number of lines of a styles file exceeds the default lines limit', () => { + const source = ` + @Component({ + selector: 'foobar', + styleUrls: ['./foobar.css'] + }) + class Test {} + `; + assertSuccess(ruleName, getSourceFile(source)); + }); + }); + + describe('special cases', () => { + it('should succeed when neither the styles nor the template are present', () => { + const source = ` + @Component({ + selector: 'foobar', + styleUrls: ['./foobar.scss'], + templateUrl: './foobar.html' + }) + class Test {} + `; + assertSuccess(ruleName, getSourceFile(source)); + }); + }); +}); diff --git a/test/noInputPrefixRule.spec.ts b/test/noInputPrefixRule.spec.ts index d26e2c6fd..8ad4f241c 100644 --- a/test/noInputPrefixRule.spec.ts +++ b/test/noInputPrefixRule.spec.ts @@ -6,10 +6,6 @@ const { metadata: { ruleName } } = Rule; -const getComposedOptions = (blacklistedPrefixes: string[]): (boolean | string)[] => { - return [true, ...blacklistedPrefixes]; -}; - describe(ruleName, () => { describe('failure', () => { it('should fail when an input property is prefixed by a blacklisted prefix and blacklist is composed by one prefix', () => { @@ -23,7 +19,7 @@ describe(ruleName, () => { `; assertAnnotated({ message: getFailureMessage(blacklistedPrefixes), - options: getComposedOptions(blacklistedPrefixes), + options: blacklistedPrefixes, ruleName, source }); @@ -40,7 +36,7 @@ describe(ruleName, () => { `; assertAnnotated({ message: getFailureMessage(blacklistedPrefixes), - options: getComposedOptions(blacklistedPrefixes), + options: blacklistedPrefixes, ruleName, source }); @@ -57,7 +53,7 @@ describe(ruleName, () => { `; assertAnnotated({ message: getFailureMessage(blacklistedPrefixes), - options: getComposedOptions(blacklistedPrefixes), + options: blacklistedPrefixes, ruleName, source }); @@ -74,7 +70,7 @@ describe(ruleName, () => { `; assertAnnotated({ message: getFailureMessage(blacklistedPrefixes), - options: getComposedOptions(blacklistedPrefixes), + options: blacklistedPrefixes, ruleName, source }); @@ -91,7 +87,7 @@ describe(ruleName, () => { `; assertAnnotated({ message: getFailureMessage(blacklistedPrefixes), - options: getComposedOptions(blacklistedPrefixes), + options: blacklistedPrefixes, ruleName, source }); @@ -107,7 +103,7 @@ describe(ruleName, () => { @Input() mustmust = true; } `; - assertSuccess(ruleName, source, getComposedOptions(blacklistedPrefixes)); + assertSuccess(ruleName, source, blacklistedPrefixes); }); it('should succeed when multiple input properties are prefixed by something not present in the blacklist', () => { @@ -121,7 +117,7 @@ describe(ruleName, () => { @Input() shoulddoit: boolean; } `; - assertSuccess(ruleName, source, getComposedOptions(blacklistedPrefixes)); + assertSuccess(ruleName, source, blacklistedPrefixes); }); }); }); diff --git a/test/preferInlineDecoratorRule.spec.ts b/test/preferInlineDecoratorRule.spec.ts index 6f5a1a1e9..239db20f3 100644 --- a/test/preferInlineDecoratorRule.spec.ts +++ b/test/preferInlineDecoratorRule.spec.ts @@ -1,11 +1,9 @@ import { expect } from 'chai'; import { Replacement } from 'tslint/lib'; - -import { decoratorKeys, Rule } from '../src/preferInlineDecoratorRule'; +import { decoratorKeys, getFailureMessage, Rule } from '../src/preferInlineDecoratorRule'; import { assertFailure, assertFailures, assertSuccess, IExpectedFailure } from './testHelper'; const { - FAILURE_STRING, metadata: { ruleName } } = Rule; const className = 'Test'; @@ -17,7 +15,7 @@ describe(ruleName, () => { character: 35, line: 3 }, - message: FAILURE_STRING, + message: getFailureMessage(), startPosition: { character: 14, line: 2 @@ -72,13 +70,13 @@ describe(ruleName, () => { character: 44, line: 3 }, - message: FAILURE_STRING, + message: getFailureMessage(), startPosition: { character: 12, line: 2 } }, - [true, restDecorators] + restDecorators ); }); }); @@ -98,7 +96,7 @@ describe(ruleName, () => { character: 31, line: 3 }, - message: FAILURE_STRING, + message: getFailureMessage(), startPosition: { character: 10, line: 2 @@ -109,7 +107,7 @@ describe(ruleName, () => { character: 19, line: 5 }, - message: FAILURE_STRING, + message: getFailureMessage(), startPosition: { character: 10, line: 4 @@ -152,7 +150,7 @@ describe(ruleName, () => { test = new EventEmitter(); } `; - assertSuccess(ruleName, source, [true, firstDecorator]); + assertSuccess(ruleName, source, [firstDecorator]); }); });