File tree 3 files changed +156
-0
lines changed
tests/rules/no-input-rename
3 files changed +156
-0
lines changed Original file line number Diff line number Diff line change @@ -655,6 +655,105 @@ class Test {}
655
655
656
656
#### ✅ Valid Code
657
657
658
+ ``` ts
659
+ @Component ({
660
+ selector: ' qx-menuitem' ,
661
+ hostDirectives: [{
662
+ directive: CdkMenuItem ,
663
+ inputs: [' cdkMenuItemDisabled: disabled' ],
664
+ }]
665
+ })
666
+ class Test {}
667
+ ```
668
+
669
+ <br >
670
+
671
+ ---
672
+
673
+ <br >
674
+
675
+ #### Default Config
676
+
677
+ ``` json
678
+ {
679
+ "rules" : {
680
+ "@angular-eslint/no-input-rename" : [
681
+ " error"
682
+ ]
683
+ }
684
+ }
685
+ ```
686
+
687
+ <br >
688
+
689
+ #### ✅ Valid Code
690
+
691
+ ``` ts
692
+ @Component ({
693
+ selector: ' qx-menuitem' ,
694
+ ' hostDirectives' : [{
695
+ directive: CdkMenuItem ,
696
+ inputs: [' cdkMenuItemDisabled: disabled' ],
697
+ }]
698
+ })
699
+ class Test {}
700
+ ```
701
+
702
+ <br >
703
+
704
+ ---
705
+
706
+ <br >
707
+
708
+ #### Default Config
709
+
710
+ ``` json
711
+ {
712
+ "rules" : {
713
+ "@angular-eslint/no-input-rename" : [
714
+ " error"
715
+ ]
716
+ }
717
+ }
718
+ ```
719
+
720
+ <br >
721
+
722
+ #### ✅ Valid Code
723
+
724
+ ``` ts
725
+ @Component ({
726
+ selector: ' qx-menuitem' ,
727
+ [' hostDirectives' ]: [{
728
+ directive: CdkMenuItem ,
729
+ inputs: [' cdkMenuItemDisabled: disabled' ],
730
+ }]
731
+ })
732
+ class Test {}
733
+ ```
734
+
735
+ <br >
736
+
737
+ ---
738
+
739
+ <br >
740
+
741
+ #### Default Config
742
+
743
+ ``` json
744
+ {
745
+ "rules" : {
746
+ "@angular-eslint/no-input-rename" : [
747
+ " error"
748
+ ]
749
+ }
750
+ }
751
+ ```
752
+
753
+ <br >
754
+
755
+ #### ✅ Valid Code
756
+
658
757
``` ts
659
758
@Component ({})
660
759
class Test {
Original file line number Diff line number Diff line change @@ -139,6 +139,28 @@ export default createESLintRule<Options, MessageIds>({
139
139
[ Selectors . INPUTS_METADATA_PROPERTY_LITERAL ] (
140
140
node : TSESTree . Literal | TSESTree . TemplateElement ,
141
141
) {
142
+ const ancestorMaybeHostDirectiveAPI =
143
+ node . parent ?. parent ?. parent ?. parent ?. parent ;
144
+ if (
145
+ ancestorMaybeHostDirectiveAPI &&
146
+ ASTUtils . isProperty ( ancestorMaybeHostDirectiveAPI )
147
+ ) {
148
+ /**
149
+ * Angular v15 introduced the directive composition API: https://angular.io/guide/directive-composition-api
150
+ * Renaming host directive inputs using this API is not a bad practice and should not be reported
151
+ */
152
+ const hostDirectiveAPIPropertyName = 'hostDirectives' ;
153
+ if (
154
+ ( ASTUtils . isLiteral ( ancestorMaybeHostDirectiveAPI . key ) &&
155
+ ancestorMaybeHostDirectiveAPI . key . value ===
156
+ hostDirectiveAPIPropertyName ) ||
157
+ ( TSESLintASTUtils . isIdentifier ( ancestorMaybeHostDirectiveAPI . key ) &&
158
+ ancestorMaybeHostDirectiveAPI . key . name ===
159
+ hostDirectiveAPIPropertyName )
160
+ ) {
161
+ return ;
162
+ }
163
+ }
142
164
const [ propertyName , aliasName ] = withoutBracketsAndWhitespaces (
143
165
ASTUtils . getRawText ( node ) ,
144
166
) . split ( ':' ) ;
Original file line number Diff line number Diff line change @@ -50,6 +50,41 @@ export const valid = [
50
50
})
51
51
class Test {}
52
52
` ,
53
+ /**
54
+ * Renaming inputs when using the directive composition API is not a bad practice
55
+ * https://angular.io/guide/directive-composition-api
56
+ * https://www.youtube.com/watch?v=EJJwyyjsRGs
57
+ */
58
+ `
59
+ @Component({
60
+ selector: 'qx-menuitem',
61
+ hostDirectives: [{
62
+ directive: CdkMenuItem,
63
+ inputs: ['cdkMenuItemDisabled: disabled'],
64
+ }]
65
+ })
66
+ class Test {}
67
+ ` ,
68
+ `
69
+ @Component({
70
+ selector: 'qx-menuitem',
71
+ 'hostDirectives': [{
72
+ directive: CdkMenuItem,
73
+ inputs: ['cdkMenuItemDisabled: disabled'],
74
+ }]
75
+ })
76
+ class Test {}
77
+ ` ,
78
+ `
79
+ @Component({
80
+ selector: 'qx-menuitem',
81
+ ['hostDirectives']: [{
82
+ directive: CdkMenuItem,
83
+ inputs: ['cdkMenuItemDisabled: disabled'],
84
+ }]
85
+ })
86
+ class Test {}
87
+ ` ,
53
88
`
54
89
@Component({})
55
90
class Test {
You can’t perform that action at this time.
0 commit comments