Skip to content

Commit 31b2b6a

Browse files
rafaelss95mgechev
authored andcommitted
fix(rule): 'prefer-inline-decorator' limiting the number of options (#787)
1 parent c023c75 commit 31b2b6a

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

src/preferInlineDecoratorRule.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@ import { IOptions, IRuleMetadata, Replacement, RuleFailure } from 'tslint/lib';
22
import { AbstractRule } from 'tslint/lib/rules';
33
import { Decorator, isPropertyDeclaration, SourceFile } from 'typescript';
44
import { NgWalker } from './angular/ngWalker';
5-
import { decoratorKeys, Decorators, DECORATORS, getDecoratorName, isSameLine } from './util/utils';
5+
import { Decorators, getDecoratorName, isSameLine } from './util/utils';
66

77
export class Rule extends AbstractRule {
88
static readonly metadata: IRuleMetadata = {
99
description: 'Ensures that decorators are on the same line as the property/method it decorates.',
1010
descriptionDetails: 'See more at https://angular.io/guide/styleguide#style-05-12.',
1111
hasFix: true,
12-
optionExamples: [true, [true, Decorators.HostListener]],
12+
optionExamples: [true, [true, Decorators.HostListener], [true, Decorators.Input, 'MyCustomDecorator']],
1313
options: {
14-
items: {
15-
enum: decoratorKeys,
16-
type: 'string'
17-
},
18-
maxLength: DECORATORS.size,
19-
minLength: 0,
14+
items: [
15+
{
16+
type: 'string'
17+
}
18+
],
2019
type: 'array'
2120
},
2221
optionsDescription: 'A list of blacklisted decorators.',
@@ -33,14 +32,7 @@ export class Rule extends AbstractRule {
3332
}
3433

3534
isEnabled(): boolean {
36-
const {
37-
metadata: {
38-
options: { maxLength, minLength }
39-
}
40-
} = Rule;
41-
const { length } = this.ruleArguments;
42-
43-
return super.isEnabled() && length >= minLength && length <= maxLength;
35+
return super.isEnabled() && this.ruleArguments.every(ruleArgument => !!(typeof ruleArgument === 'string' && ruleArgument.trim()));
4436
}
4537
}
4638

test/preferInlineDecoratorRule.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe(ruleName, () => {
3333
class Test {
3434
@Input('test1')
3535
testVar1: string;
36-
@Input('test2')
36+
@MyCustomDecorator()
3737
testVar2: string;
3838
}
3939
`;
@@ -99,7 +99,7 @@ describe(ruleName, () => {
9999
const source = `
100100
class Test {
101101
@Input('test1') testVar1: string;
102-
@Input('test2') testVar2: string;
102+
@MyCustomDecorator() testVar2: string;
103103
}
104104
`;
105105
assertSuccess(ruleName, source);
@@ -172,7 +172,7 @@ describe(ruleName, () => {
172172
});
173173

174174
describe('replacements', () => {
175-
it('should fail if a property is not on the same line as its decorator', () => {
175+
it('should fail and apply proper replacements if a property is not on the same line as its decorator', () => {
176176
const source = `
177177
class Test {
178178
@Output()

0 commit comments

Comments
 (0)