Codelyzer: Possible bug with no-input-rename

Created on 10 Jul 2017  路  4Comments  路  Source: mgechev/codelyzer

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.

enhancement P2 first timers

Most helpful comment

I think this also warrants taking another look at https://github.com/mgechev/codelyzer/issues/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.

All 4 comments

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 ?

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

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

I think this also warrants taking another look at https://github.com/mgechev/codelyzer/issues/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.

Lets move it to the next milestone.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rolandjitsu picture rolandjitsu  路  5Comments

lazarljubenovic picture lazarljubenovic  路  4Comments

wKoza picture wKoza  路  6Comments

marbug picture marbug  路  3Comments

artaommahe picture artaommahe  路  3Comments