Skip to content

Commit

Permalink
fix(rules): fix ion-button-is-now-an-element for angular html syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
imhoffd committed Jun 25, 2018
1 parent 9122393 commit bb5f631
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ionButtonIsNowAnElementRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const ruleName = 'ion-button-is-now-an-element';
class IonButtonIsNowAnElementTemplateVisitor extends BasicTemplateAstVisitor {
visitElement(element: ast.ElementAst, context: any): any {
if (element.name) {
const InvalidSyntaxBoxRe = /<(\w+)(?:[a-zA-Z\"\=]|\s)*(ion-button)(?:[a-zA-Z\"\=]|\s)*>/gis;
const InvalidSyntaxBoxRe = /<\w+[\s\S]+?(ion-button)[\s\S]*?>/gi;

let error = 'Ion Button is now an Element instead of an attribute.';

Expand Down
38 changes: 37 additions & 1 deletion test/IonButtonIsNowAnElement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe(ruleName, () => {
});

describe('failure', () => {
it('should fail when ion-button-attribute is used', () => {
it('should fail when ion-button attribute is used on button', () => {
let source = `
@Component({
template: \`
Expand All @@ -31,5 +31,41 @@ describe(ruleName, () => {
source
});
});

it('should fail when ion-button attribute is used on anchor', () => {
let source = `
@Component({
template: \`
<a ion-button (click)="doSomething()"></a>\`
~~~~~~~~~~
})
class Bar{}
`;

assertAnnotated({
ruleName,
message: 'Ion Button is now an Element instead of an attribute.',
source
});
});

it('should fail when ion-button attribute is used with multiline', () => {
let source = `
@Component({
template: \`
<a
ion-button
~~~~~~~~~~
(click)="doSomething()">Click Me</a>\`
})
class Bar{}
`;

assertAnnotated({
ruleName,
message: 'Ion Button is now an Element instead of an attribute.',
source
});
});
});
});

0 comments on commit bb5f631

Please sign in to comment.