Skip to content

Commit

Permalink
fix(no-output-on-prefix): fix regular expression (#674)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
loktionov129 authored and mgechev committed Jun 24, 2018
1 parent 28bd75a commit adc974a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/noOutputOnPrefixRule.ts
Expand Up @@ -34,7 +34,7 @@ class OutputWalker extends NgWalker {
const className = getClassName(property);
const memberName = property.name.getText();

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

Expand Down
10 changes: 10 additions & 0 deletions test/noOutputOnPrefixRule.spec.ts
Expand Up @@ -68,5 +68,15 @@ describe('no-output-on-prefix', () => {
`;
assertSuccess('no-output-on-prefix', source);
});

it("should succeed, when an output property containing 'on' suffix", () => {
const source = `
@Component()
class SelectComponent {
@Output() selectionChanged = new EventEmitter<any>();
}
`;
assertSuccess('no-output-on-prefix', source);
});
});
});

0 comments on commit adc974a

Please sign in to comment.