Skip to content

Commit

Permalink
fix(rules): angularWhitespace check-pipe in directives
Browse files Browse the repository at this point in the history
Fix #346
  • Loading branch information
mgechev committed Jul 1, 2017
1 parent 25667f9 commit fa08a3b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/angular/templates/basicTemplateAstVisitor.ts
Expand Up @@ -14,7 +14,9 @@ const getExpressionDisplacement = (binding: any) => {
let valLen = 0;
let totalLength = 0;
let result = 0;
if (binding instanceof ast.BoundEventAst || binding instanceof ast.BoundElementPropertyAst) {
if (binding instanceof ast.BoundEventAst ||
binding instanceof ast.BoundElementPropertyAst ||
binding instanceof ast.BoundDirectivePropertyAst) {
// subBindingLen is for [class.foo], [style.foo], the length of
// the binding type. For event it is 0. (+1 because of the ".")
let subBindingLen = 0;
Expand All @@ -40,7 +42,9 @@ const getExpressionDisplacement = (binding: any) => {
// - Add the name of the binding (binding.name.length).
// - 4 characters because of []=" (we already have the "." from above).
// - subBindingLen is from above and applies only for elements.
attrLen = binding.name.length + 4 + subBindingLen;
if (!(binding instanceof ast.BoundDirectivePropertyAst)) {
attrLen = binding.name.length + 4 + subBindingLen;
}
// Total length of the attribute value
if (binding instanceof ast.BoundEventAst) {
valLen = binding.handler.span.end;
Expand Down
15 changes: 15 additions & 0 deletions test/angularWhitespaceRule.spec.ts
Expand Up @@ -55,6 +55,21 @@ describe('angular-whitespace', () => {
assertSuccess('angular-whitespace', source, ['check-pipe']);
});

it.only('should succeed with in structural directives with proper style', () => {
let source = `
@Component({
selector: 'foo',
template: \`
<div *ngIf="foo | async"></div>
\`
})
class Bar {
foo: any;
}
`;
assertSuccess('angular-whitespace', source, ['check-pipe']);
});

it('should succeed with proper style', () => {
let source = `
@Component({
Expand Down

0 comments on commit fa08a3b

Please sign in to comment.