@@ -14,7 +14,7 @@ type MessageIds = ESLintUtils.InferMessageIdsTypeFromRule<typeof rule>;
14
14
type Options = readonly ESLintUtils . InferOptionsTypeFromRule < typeof rule > [ 0 ] [ ] ;
15
15
type RunTests = TSESLint . RunTests < MessageIds , Options > ;
16
16
17
- const valid : ( ) => RunTests [ 'valid' ] = ( ) => [
17
+ const validConstructor : ( ) => RunTests [ 'valid' ] = ( ) => [
18
18
`
19
19
class Ok {}` ,
20
20
`
@@ -34,7 +34,29 @@ class Ok2 {
34
34
} ,
35
35
] ;
36
36
37
- const invalid : ( ) => RunTests [ 'invalid' ] = ( ) => [
37
+ const validInject : ( ) => RunTests [ 'valid' ] = ( ) => [
38
+ `
39
+ class Ok3 {}` ,
40
+ `
41
+ import { Store } from '@ngrx/store'
42
+ import { inject } from '@angular/core'
43
+
44
+ class Ok4 {
45
+ readonly store = inject(Store)
46
+ }` ,
47
+ {
48
+ code : `
49
+ import { Store } from '@ngrx/store'
50
+ import { inject } from '@angular/core'
51
+
52
+ class Ok5 {
53
+ readonly customName = inject(Store)
54
+ }` ,
55
+ options : [ 'customName' ] ,
56
+ } ,
57
+ ] ;
58
+
59
+ const invalidConstructor : ( ) => RunTests [ 'invalid' ] = ( ) => [
38
60
fromFixture (
39
61
`
40
62
import { Store } from '@ngrx/store'
@@ -151,7 +173,138 @@ class NotOk3 {
151
173
) ,
152
174
] ;
153
175
176
+ const invalidInject : ( ) => RunTests [ 'invalid' ] = ( ) => [
177
+ fromFixture (
178
+ `
179
+ import { Store } from '@ngrx/store'
180
+ import { inject } from '@angular/core'
181
+
182
+ class NotOk4 {
183
+ readonly somethingElse$: Store = inject(Store)
184
+ ~~~~~~~~~~~~~~ [${ useConsistentGlobalStoreName } { "storeName": "store" } suggest]
185
+ }` ,
186
+ {
187
+ suggestions : [
188
+ {
189
+ messageId : useConsistentGlobalStoreNameSuggest ,
190
+ data : {
191
+ storeName : 'store' ,
192
+ } ,
193
+ output : `
194
+ import { Store } from '@ngrx/store'
195
+ import { inject } from '@angular/core'
196
+
197
+ class NotOk4 {
198
+ readonly store: Store = inject(Store)
199
+ }` ,
200
+ } ,
201
+ ] ,
202
+ }
203
+ ) ,
204
+ fromFixture (
205
+ `
206
+ import { Store } from '@ngrx/store'
207
+ import { inject } from '@angular/core'
208
+
209
+ class NotOk5 {
210
+ private readonly store1 = inject(Store)
211
+ ~~~~~~ [${ useConsistentGlobalStoreName } { "storeName": "store" } suggest]
212
+ private readonly store = inject(Store)
213
+ }` ,
214
+ {
215
+ suggestions : [
216
+ {
217
+ messageId : useConsistentGlobalStoreNameSuggest ,
218
+ data : {
219
+ storeName : 'store' ,
220
+ } ,
221
+ output : `
222
+ import { Store } from '@ngrx/store'
223
+ import { inject } from '@angular/core'
224
+
225
+ class NotOk5 {
226
+ private readonly store = inject(Store)
227
+ private readonly store = inject(Store)
228
+ }` ,
229
+ } ,
230
+ ] ,
231
+ }
232
+ ) ,
233
+ fromFixture (
234
+ `
235
+ import { Store } from '@ngrx/store'
236
+ import { inject } from '@angular/core'
237
+
238
+ class NotOk6 {
239
+ private readonly store1 = inject(Store)
240
+ ~~~~~~ [${ useConsistentGlobalStoreName } { "storeName": "store" } suggest 0]
241
+ private readonly store2 = inject(Store)
242
+ ~~~~~~ [${ useConsistentGlobalStoreName } { "storeName": "store" } suggest 1]
243
+ }` ,
244
+ {
245
+ suggestions : [
246
+ {
247
+ messageId : useConsistentGlobalStoreNameSuggest ,
248
+ data : {
249
+ storeName : 'store' ,
250
+ } ,
251
+ output : `
252
+ import { Store } from '@ngrx/store'
253
+ import { inject } from '@angular/core'
254
+
255
+ class NotOk6 {
256
+ private readonly store = inject(Store)
257
+ private readonly store2 = inject(Store)
258
+ }` ,
259
+ } ,
260
+ {
261
+ messageId : useConsistentGlobalStoreNameSuggest ,
262
+ data : {
263
+ storeName : 'store' ,
264
+ } ,
265
+ output : `
266
+ import { Store } from '@ngrx/store'
267
+ import { inject } from '@angular/core'
268
+
269
+ class NotOk6 {
270
+ private readonly store1 = inject(Store)
271
+ private readonly store = inject(Store)
272
+ }` ,
273
+ } ,
274
+ ] ,
275
+ }
276
+ ) ,
277
+ fromFixture (
278
+ `
279
+ import { Store } from '@ngrx/store'
280
+ import { inject } from '@angular/core'
281
+
282
+ class NotOk7 {
283
+ private store = inject(Store)
284
+ ~~~~~ [${ useConsistentGlobalStoreName } { "storeName": "customName" } suggest]
285
+ }` ,
286
+ {
287
+ options : [ 'customName' ] ,
288
+ suggestions : [
289
+ {
290
+ messageId : useConsistentGlobalStoreNameSuggest ,
291
+ data : {
292
+ storeName : 'customName' ,
293
+ } ,
294
+ output : `
295
+ import { Store } from '@ngrx/store'
296
+ import { inject } from '@angular/core'
297
+
298
+ class NotOk7 {
299
+ private customName = inject(Store)
300
+ }` ,
301
+ } ,
302
+ ] ,
303
+ }
304
+ ) ,
305
+ ] ;
306
+
154
307
ruleTester ( ) . run ( path . parse ( __filename ) . name , rule , {
155
- valid : valid ( ) ,
156
- invalid : invalid ( ) ,
308
+ valid : [ ... validConstructor ( ) , ... validInject ( ) ] ,
309
+ invalid : [ ... invalidConstructor ( ) , ... invalidInject ( ) ] ,
157
310
} ) ;
0 commit comments