Skip to content

Commit adc974a

Browse files
loktionov129mgechev
authored andcommittedJun 24, 2018
fix(no-output-on-prefix): fix regular expression (#674)
* fix(no-output-on-prefix): fix regular expression this commit fixes incorrect behavior when memberName contains 'on' suffix in the word, for example selectionChanged. ``` /on((?![a-z])|(?=$))/.test('selectionChanged'); // true /^on((?![a-z])|(?=$))/.test('selectionChanged'); // false ``` * test(no-output-on-prefix): add more test cases * style(no-output-on-prefix): fix misspellings
1 parent 28bd75a commit adc974a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed
 

‎src/noOutputOnPrefixRule.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class OutputWalker extends NgWalker {
3434
const className = getClassName(property);
3535
const memberName = property.name.getText();
3636

37-
if (!memberName || !/on((?![a-z])|(?=$))/.test(memberName)) {
37+
if (!memberName || !/^on((?![a-z])|(?=$))/.test(memberName)) {
3838
return;
3939
}
4040

‎test/noOutputOnPrefixRule.spec.ts

+10
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,15 @@ describe('no-output-on-prefix', () => {
6868
`;
6969
assertSuccess('no-output-on-prefix', source);
7070
});
71+
72+
it("should succeed, when an output property containing 'on' suffix", () => {
73+
const source = `
74+
@Component()
75+
class SelectComponent {
76+
@Output() selectionChanged = new EventEmitter<any>();
77+
}
78+
`;
79+
assertSuccess('no-output-on-prefix', source);
80+
});
7181
});
7282
});

0 commit comments

Comments
 (0)
Please sign in to comment.