Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on @Pipe decorator #399

Closed
leonadler opened this issue Aug 28, 2017 · 2 comments
Closed

Error on @Pipe decorator #399

leonadler opened this issue Aug 28, 2017 · 2 comments
Assignees
Labels

Comments

@leonadler
Copy link

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.


[email protected]
[email protected]
[email protected]


Thanks for your great work!

@leonadler
Copy link
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
Copy link
Owner

mgechev commented Aug 28, 2017

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

@mgechev mgechev closed this as completed Aug 28, 2017
@mgechev mgechev reopened this Aug 28, 2017
mgechev added a commit that referenced this issue Sep 8, 2017
@mgechev mgechev added this to the 3.2.0 - Grace Hopper milestone Sep 8, 2017
@mgechev mgechev self-assigned this Sep 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants