Skip to content

Commit 2260dfd

Browse files
mattlewis92wKoza
authored andcommitted
fix(rule): detect trackBy function when ngFor spans multiple lines (#813)
1 parent 1fb5d8a commit 2260dfd

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/templateUseTrackByFunctionRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { SourceFile } from 'typescript/lib/typescript';
55
import { NgWalker, NgWalkerConfig } from './angular/ngWalker';
66
import { BasicTemplateAstVisitor } from './angular/templates/basicTemplateAstVisitor';
77

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

test/templateUseTrackByFunctionRule.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,23 @@ describe(ruleName, () => {
213213
`;
214214
assertSuccess(ruleName, source);
215215
});
216+
217+
it('should succeed when trackBy function is on a different line', () => {
218+
const source = `
219+
@Component({
220+
template: \`
221+
<div *ngFor="
222+
let item of [1, 2, 3];
223+
let i = index;
224+
trackBy : trackByFn
225+
">
226+
{{ item }}
227+
</div>
228+
\`
229+
})
230+
class Bar {}
231+
`;
232+
assertSuccess(ruleName, source);
233+
});
216234
});
217235
});

0 commit comments

Comments
 (0)