Skip to content

Error on @Pipe decorator #399

@leonadler

Description

@leonadler

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!

Activity

leonadler

leonadler commented on Aug 28, 2017

@leonadler
Author

To clarify: The same code works and does not break codelyzer when rewritten like this:

export function mockPipe(name: string): any {
    return Pipe({ name })(
        class MockPipe {
            transform(input: any): any {
                return input;
            }
        }
    );
}

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 an initializer.

mgechev

mgechev commented on Aug 28, 2017

@mgechev
Owner

Yes, codelyzer should ignore variables. Thanks for reporting the issue, I'll be on it.

added a commit that references this issue on Sep 8, 2017
8e3fafb
added this to the 3.2.0 - Grace Hopper milestone on Sep 8, 2017
self-assigned this
on Sep 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @mgechev@leonadler

      Issue actions

        Error on @Pipe decorator · Issue #399 · mgechev/codelyzer