Skip to content

Commit c960b5f

Browse files
committed
Merge pull request #5 from mgechev/input-output-directive
Input output directive
2 parents b01926c + 1ec10f9 commit c960b5f

5 files changed

+26
-6
lines changed

src/inputPropertyDirectiveRule.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import {decoratorValidator} from './util/decoratorValidator';
66
const FAILURE_STRING = 'In the class "%s", the directive input property "%s" should not be renamed.' +
77
'Please, consider the following use "@Input() %s: string"';
88

9-
const renameInputCondition = (name, arg)=> {
10-
return (name === 'Input' && arg);
9+
const renameInputCondition = (name, arg, element)=> {
10+
let memberName = element.name.text;
11+
return (name === 'Input' && arg && memberName != arg.text);
1112
};
1213

1314
export class Rule extends ClassParameterRule {

src/outputPropertyDirectiveRule.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import {decoratorValidator} from './util/decoratorValidator';
66
const FAILURE_STRING = 'In the class "%s", the directive output property "%s" should not be renamed.' +
77
'Please, consider the following use "@Output() %s = new EventEmitter();"';
88

9-
const renameOutputCondition = (name, arg)=> {
10-
return (name === 'Output' && arg);
9+
const renameOutputCondition = (name, arg, element)=> {
10+
let memberName = element.name.text;
11+
return (name === 'Output' && arg && memberName !== arg.text);
1112
};
1213

1314
export class Rule extends ClassParameterRule {

src/util/decoratorValidator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const decoratorValidator = (condition)=> {
88
let name = expr.text;
99
let args = baseExpr.arguments || [];
1010
let arg = args[0];
11-
if (condition(name, arg)) {
11+
if (condition(name, arg,element)) {
1212
isValid = false;
1313
}
1414
})

test/inputPropertyDirectiveRule.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,13 @@ describe('input-property-directive', () => {
3030
assertSuccess('input-property-directive', source);
3131
});
3232
});
33+
describe('valid directive input property', () => {
34+
it('should succeed, when a directive input property rename is the same as the name of the property', () => {
35+
let source = `
36+
class ButtonComponent {
37+
@Input('label') label: string;
38+
}`;
39+
assertSuccess('input-property-directive', source);
40+
});
41+
});
3342
});

test/outputPropertyDirectiveRule.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('output-property-directive', () => {
2121
});
2222
});
2323
});
24-
describe('valid directive input property', () => {
24+
describe('valid directive output property', () => {
2525
it('should succeed, when a directive output property is properly used', () => {
2626
let source = `
2727
class ButtonComponent {
@@ -30,4 +30,13 @@ describe('output-property-directive', () => {
3030
assertSuccess('output-property-directive', source);
3131
});
3232
});
33+
describe('valid directive output property', () => {
34+
it('should succeed, when a directive output property rename is the same as the property name', () => {
35+
let source = `
36+
class ButtonComponent {
37+
@Output('change') change = new EventEmitter<any>();
38+
}`;
39+
assertSuccess('output-property-directive', source);
40+
});
41+
});
3342
});

0 commit comments

Comments
 (0)