-
Notifications
You must be signed in to change notification settings - Fork 236
Closed
Description
Follow-up on #111, this code we use for mocking pipes in unit tests throws TypeError: Cannot read property 'text' of undefined at node_modules/codelyzer/pipeNamingRule.js:98:44
:
export function mockPipe(name: string): any {
@Pipe({ name })
class MockPipe implements PipeTransform {
transform(input: any): any {
return input;
}
}
return MockPipe;
}
Instead of throwing, maybe the rule can ignore variables in the decorator?
// could be ignored by codelyzer
@Pipe({ name }) class DynamicPipe { ... }
// could be ignored by codelyzer
@Pipe({ name: variableName }) class DynamicPipe { ... }
// should be checked by codelyzer
@Pipe({ name: 'some-name' }) class RegularPipe { ... }
Alternatively, a meaningful error message (like in #111) mentioning the file in question would be better than throwing.
codelyzer@3.1.2
npm@5.3.0
node@8.1.4
Thanks for your great work!
Metadata
Metadata
Assignees
Projects
Relationships
Development
Select code repository
Activity
leonadler commentedon Aug 28, 2017
To clarify: The same code works and does not break codelyzer when rewritten like this:
However, knowing that this file is the culprit instead of getting a 'property of undefined' error thrown would be preferrable.
This is the method that throws since it is called with a
property
without aninitializer
.mgechev commentedon Aug 28, 2017
Yes, codelyzer should ignore variables. Thanks for reporting the issue, I'll be on it.
fix: error accessing invalid property