Skip to content

Commit f0a00ac

Browse files
117616: Added support to alias-import to disallow aliasing certain imports
1 parent aed0460 commit f0a00ac

13 files changed

Lines changed: 383 additions & 51 deletions

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@
270270
{
271271
"package": "rxjs",
272272
"imported": "of",
273-
"local": "observableOf"
273+
"local": "of"
274274
}
275275
]
276276
}

docs/lint/html/rules/no-disabled-attribute-on-button.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,28 @@ _______
2121
```html
2222
<button [dsBtnDisabled]="true">Submit</button>
2323
```
24+
2425

2526
##### disabled attribute is still valid on non-button elements
2627
2728
```html
2829
<input disabled>
2930
```
31+
3032

3133
##### [disabled] attribute is still valid on non-button elements
3234
3335
```html
3436
<input [disabled]="true">
3537
```
38+
3639

3740
##### angular dynamic attributes that use disabled are still valid
3841
3942
```html
4043
<button [class.disabled]="isDisabled">Submit</button>
4144
```
45+
4246

4347

4448

@@ -49,6 +53,9 @@ _______
4953
5054
```html
5155
<button disabled>Submit</button>
56+
57+
58+
5259
```
5360
Will produce the following error(s):
5461
```
@@ -65,6 +72,9 @@ Result of `yarn lint --fix`:
6572
6673
```html
6774
<button [disabled]="true">Submit</button>
75+
76+
77+
6878
```
6979
Will produce the following error(s):
7080
```

docs/lint/html/rules/themed-component-usages.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ _______
2525
<ds-test-themeable></ds-test-themeable>
2626
<ds-test-themeable [test]="something"></ds-test-themeable>
2727
```
28+
2829

2930
##### use no-prefix selectors in TypeScript templates
3031
@@ -35,6 +36,7 @@ _______
3536
class Test {
3637
}
3738
```
39+
3840

3941
##### use no-prefix selectors in TypeScript test templates
4042
@@ -47,6 +49,7 @@ Filename: `lint/test/fixture/src/test.spec.ts`
4749
class Test {
4850
}
4951
```
52+
5053

5154
##### base selectors are also allowed in TypeScript test templates
5255
@@ -59,6 +62,7 @@ Filename: `lint/test/fixture/src/test.spec.ts`
5962
class Test {
6063
}
6164
```
65+
6266

6367

6468

@@ -71,6 +75,9 @@ class Test {
7175
<ds-themed-test-themeable/>
7276
<ds-themed-test-themeable></ds-themed-test-themeable>
7377
<ds-themed-test-themeable [test]="something"></ds-themed-test-themeable>
78+
79+
80+
7481
```
7582
Will produce the following error(s):
7683
```
@@ -93,6 +100,9 @@ Result of `yarn lint --fix`:
93100
<ds-base-test-themeable/>
94101
<ds-base-test-themeable></ds-base-test-themeable>
95102
<ds-base-test-themeable [test]="something"></ds-base-test-themeable>
103+
104+
105+
96106
```
97107
Will produce the following error(s):
98108
```

docs/lint/ts/rules/alias-imports.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,42 @@ A list of all the imports that you want to alias for clarity. Every alias should
3232
```typescript
3333
import { of as observableOf } from 'rxjs';
3434
```
35+
36+
With options:
37+
38+
```json
39+
{
40+
"aliases": [
41+
{
42+
"package": "rxjs",
43+
"imported": "of",
44+
"local": "observableOf"
45+
}
46+
]
47+
}
48+
```
49+
50+
51+
##### enforce unaliased import
52+
53+
```typescript
54+
import { combineLatest } from 'rxjs';
55+
```
56+
57+
With options:
58+
59+
```json
60+
{
61+
"aliases": [
62+
{
63+
"package": "rxjs",
64+
"imported": "combineLatest",
65+
"local": "combineLatest"
66+
}
67+
]
68+
}
69+
```
70+
3571

3672

3773

@@ -42,6 +78,9 @@ import { of as observableOf } from 'rxjs';
4278
4379
```typescript
4480
import { of } from 'rxjs';
81+
82+
83+
4584
```
4685
Will produce the following error(s):
4786
```
@@ -58,6 +97,9 @@ import { of as observableOf } from 'rxjs';
5897
5998
```typescript
6099
import { of as ofSomething } from 'rxjs';
100+
101+
102+
61103
```
62104
Will produce the following error(s):
63105
```
@@ -70,4 +112,37 @@ import { of as observableOf } from 'rxjs';
70112
```
71113
72114

115+
##### disallow aliasing import
116+
117+
```typescript
118+
import { combineLatest as observableCombineLatest } from 'rxjs';
119+
120+
121+
With options:
122+
123+
```json
124+
{
125+
"aliases": [
126+
{
127+
"package": "rxjs",
128+
"imported": "combineLatest",
129+
"local": "combineLatest"
130+
}
131+
]
132+
}
133+
```
134+
135+
136+
```
137+
Will produce the following error(s):
138+
```
139+
This import should not use an alias
140+
```
141+
142+
Result of `yarn lint --fix`:
143+
```typescript
144+
import { combineLatest } from 'rxjs';
145+
```
146+
147+
73148

docs/lint/ts/rules/sort-standalone-imports.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Whether the last import should have a trailing comma (only applicable for multil
4444
})
4545
export class AppComponent {}
4646
```
47+
4748

4849
##### should not inlines singular imports when maxItems is 0
4950
@@ -59,6 +60,7 @@ export class AppComponent {}
5960
})
6061
export class AppComponent {}
6162
```
63+
6264

6365
##### should inline singular imports when maxItems is 1
6466
@@ -72,6 +74,15 @@ export class AppComponent {}
7274
})
7375
export class AppComponent {}
7476
```
77+
78+
With options:
79+
80+
```json
81+
{
82+
"maxItems": 1
83+
}
84+
```
85+
7586

7687

7788

@@ -92,6 +103,9 @@ export class AppComponent {}
92103
],
93104
})
94105
export class AppComponent {}
106+
107+
108+
95109
```
96110
Will produce the following error(s):
97111
```
@@ -125,6 +139,9 @@ export class AppComponent {}
125139
imports: [RootComponent],
126140
})
127141
export class AppComponent {}
142+
143+
144+
128145
```
129146
Will produce the following error(s):
130147
```
@@ -159,6 +176,17 @@ export class AppComponent {}
159176
],
160177
})
161178
export class AppComponent {}
179+
180+
181+
With options:
182+
183+
```json
184+
{
185+
"maxItems": 1
186+
}
187+
```
188+
189+
162190
```
163191
Will produce the following error(s):
164192
```
@@ -189,6 +217,9 @@ export class AppComponent {}
189217
imports: [AsyncPipe, RootComponent],
190218
})
191219
export class AppComponent {}
220+
221+
222+
192223
```
193224
Will produce the following error(s):
194225
```

docs/lint/ts/rules/themed-component-classes.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ _______
2828
class Something {
2929
}
3030
```
31+
3132

3233
##### Base component
3334
@@ -39,6 +40,7 @@ class Something {
3940
class TestThemeableComponent {
4041
}
4142
```
43+
4244

4345
##### Wrapper component
4446
@@ -55,6 +57,7 @@ Filename: `lint/test/fixture/src/app/test/themed-test-themeable.component.ts`
5557
class ThemedTestThemeableComponent extends ThemedComponent<TestThemeableComponent> {
5658
}
5759
```
60+
5861

5962
##### Override component
6063
@@ -68,6 +71,7 @@ Filename: `lint/test/fixture/src/themes/test/app/test/test-themeable.component.t
6871
class Override extends BaseComponent {
6972
}
7073
```
74+
7175

7276

7377

@@ -82,6 +86,9 @@ class Override extends BaseComponent {
8286
})
8387
class TestThemeableComponent {
8488
}
89+
90+
91+
8592
```
8693
Will produce the following error(s):
8794
```
@@ -109,6 +116,9 @@ Filename: `lint/test/fixture/src/app/test/themed-test-themeable.component.ts`
109116
})
110117
class ThemedTestThemeableComponent extends ThemedComponent<TestThemeableComponent> {
111118
}
119+
120+
121+
112122
```
113123
Will produce the following error(s):
114124
```
@@ -139,6 +149,9 @@ Filename: `lint/test/fixture/src/app/test/themed-test-themeable.component.ts`
139149
})
140150
class ThemedTestThemeableComponent extends ThemedComponent<TestThemeableComponent> {
141151
}
152+
153+
154+
142155
```
143156
Will produce the following error(s):
144157
```
@@ -173,6 +186,9 @@ import { SomethingElse } from './somewhere-else';
173186
})
174187
class ThemedTestThemeableComponent extends ThemedComponent<TestThemeableComponent> {
175188
}
189+
190+
191+
176192
```
177193
Will produce the following error(s):
178194
```
@@ -209,6 +225,9 @@ import { Something, SomethingElse } from './somewhere-else';
209225
})
210226
class ThemedTestThemeableComponent extends ThemedComponent<TestThemeableComponent> {
211227
}
228+
229+
230+
212231
```
213232
Will produce the following error(s):
214233
```
@@ -239,6 +258,9 @@ Filename: `lint/test/fixture/src/themes/test/app/test/test-themeable.component.t
239258
})
240259
class Override extends BaseComponent {
241260
}
261+
262+
263+
242264
```
243265
Will produce the following error(s):
244266
```

0 commit comments

Comments
 (0)