From 44d76574d99dbff2ec951d520af665d663be09ba Mon Sep 17 00:00:00 2001 From: Rafael Santana Date: Fri, 8 Mar 2019 00:22:00 -0300 Subject: [PATCH] fix(rule): 'prefer-inline-decorator' limiting the number of options --- src/preferInlineDecoratorRule.ts | 24 ++++++++---------------- test/preferInlineDecoratorRule.spec.ts | 6 +++--- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/preferInlineDecoratorRule.ts b/src/preferInlineDecoratorRule.ts index de76eebb2..6efe16346 100644 --- a/src/preferInlineDecoratorRule.ts +++ b/src/preferInlineDecoratorRule.ts @@ -2,21 +2,20 @@ import { IOptions, IRuleMetadata, Replacement, RuleFailure } from 'tslint/lib'; import { AbstractRule } from 'tslint/lib/rules'; import { Decorator, isPropertyDeclaration, SourceFile } from 'typescript'; import { NgWalker } from './angular/ngWalker'; -import { decoratorKeys, Decorators, DECORATORS, getDecoratorName, isSameLine } from './util/utils'; +import { Decorators, getDecoratorName, isSameLine } from './util/utils'; export class Rule extends AbstractRule { static readonly metadata: IRuleMetadata = { description: 'Ensures that decorators are on the same line as the property/method it decorates.', descriptionDetails: 'See more at https://angular.io/guide/styleguide#style-05-12.', hasFix: true, - optionExamples: [true, [true, Decorators.HostListener]], + optionExamples: [true, [true, Decorators.HostListener], [true, Decorators.Input, 'MyCustomDecorator']], options: { - items: { - enum: decoratorKeys, - type: 'string' - }, - maxLength: DECORATORS.size, - minLength: 0, + items: [ + { + type: 'string' + } + ], type: 'array' }, optionsDescription: 'A list of blacklisted decorators.', @@ -33,14 +32,7 @@ export class Rule extends AbstractRule { } isEnabled(): boolean { - const { - metadata: { - options: { maxLength, minLength } - } - } = Rule; - const { length } = this.ruleArguments; - - return super.isEnabled() && length >= minLength && length <= maxLength; + return super.isEnabled() && this.ruleArguments.every(ruleArgument => !!(typeof ruleArgument === 'string' && ruleArgument.trim())); } } diff --git a/test/preferInlineDecoratorRule.spec.ts b/test/preferInlineDecoratorRule.spec.ts index 2d6dcb884..df3d48da3 100644 --- a/test/preferInlineDecoratorRule.spec.ts +++ b/test/preferInlineDecoratorRule.spec.ts @@ -33,7 +33,7 @@ describe(ruleName, () => { class Test { @Input('test1') testVar1: string; - @Input('test2') + @MyCustomDecorator() testVar2: string; } `; @@ -99,7 +99,7 @@ describe(ruleName, () => { const source = ` class Test { @Input('test1') testVar1: string; - @Input('test2') testVar2: string; + @MyCustomDecorator() testVar2: string; } `; assertSuccess(ruleName, source); @@ -172,7 +172,7 @@ describe(ruleName, () => { }); describe('replacements', () => { - it('should fail if a property is not on the same line as its decorator', () => { + it('should fail and apply proper replacements if a property is not on the same line as its decorator', () => { const source = ` class Test { @Output()