Skip to content

Commit

Permalink
fix(rule): detect trackBy function when ngFor spans multiple lines (#813
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mattlewis92 authored and wKoza committed Apr 22, 2019
1 parent 1fb5d8a commit 2260dfd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/templateUseTrackByFunctionRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { SourceFile } from 'typescript/lib/typescript';
import { NgWalker, NgWalkerConfig } from './angular/ngWalker';
import { BasicTemplateAstVisitor } from './angular/templates/basicTemplateAstVisitor';

const PATTERN = /\s*ngFor.*\s*trackBy\s*:|\[ngForTrackBy\]\s*=\s*['"].*['"]/;
const PATTERN = /trackBy\s*:|\[ngForTrackBy\]\s*=\s*['"].*['"]/;
// current offset into the template
let currentOffset = 0;

Expand Down
18 changes: 18 additions & 0 deletions test/templateUseTrackByFunctionRule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,23 @@ describe(ruleName, () => {
`;
assertSuccess(ruleName, source);
});

it('should succeed when trackBy function is on a different line', () => {
const source = `
@Component({
template: \`
<div *ngFor="
let item of [1, 2, 3];
let i = index;
trackBy : trackByFn
">
{{ item }}
</div>
\`
})
class Bar {}
`;
assertSuccess(ruleName, source);
});
});
});

0 comments on commit 2260dfd

Please sign in to comment.