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

Possible bug with no-input-rename #374

Closed
dev054 opened this issue Jul 10, 2017 · 4 comments
Closed

Possible bug with no-input-rename #374

dev054 opened this issue Jul 10, 2017 · 4 comments

Comments

@dev054
Copy link

dev054 commented Jul 10, 2017

Consider the following use-case:

any-component.html

<my-cmp [myInput]="'xx'"></my-cmp>

my-component.ts

@Input('myInput')
myInput: any;

The no-input-rename rule doesn't shows warning in this case above.
So.. I'm just wondering if it's intentional or no... because in fact it doesn't make sense to write myInput inside the parentheses: @Input('myInput') instead of @Input()... besides writing more, it won't affect anything at all.

PS: the same is valid for no-output-rename.

@wKoza
Copy link
Collaborator

wKoza commented Jul 11, 2017

This rule seems to be intentional if we peek at the class test :

should succeed, when a directive input property rename is the same as the name of the property

Because the Style Guide indicates :

Two names for the same property (one private, one public) is inherently confusing.

In your case, it's the same name...

But, the style guide indicates also :

You should use an alias when the directive name is also an input property, and the directive name doesn't describe the property.

It's a bit confusing ! Maybe, we can improve the style guide. @wardbell, what do you think about this ?

I think we can change Codelyzer in this direction. Are you agree @mgechev ?

@mgechev
Copy link
Owner

mgechev commented Jul 11, 2017

@wKoza maybe different error messages depending on the value passed to @Input.

Regarding the style guide, yes, we can make the explanation more complete.

@wulfsberg
Copy link

wulfsberg commented Jul 27, 2017

I think this also warrants taking another look at #224.

The "Angular Fundamentals" specifically recommends aliasing an input variable to the directive selector
(https://angular.io/guide/attribute-directives#binding-to-an-input-property), so I really think Codelyzer should recognize this special case and not flag it as an error.

(I am aware that it can be selectively disabled, but it feels wrong to actively have to fight the linter to write idiomatic code).

ETA: The similar selector-name-postfixed-with-Changed for outputs should also be recognized.

@mgechev
Copy link
Owner

mgechev commented Sep 11, 2017

Lets move it to the next milestone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants