@hero-design/eslint-plugin 7.27.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js ADDED
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ root: true,
5
+ extends: [
6
+ 'eslint:recommended',
7
+ 'plugin:eslint-plugin/recommended',
8
+ 'plugin:node/recommended',
9
+ ],
10
+ env: {
11
+ node: true,
12
+ },
13
+ overrides: [
14
+ {
15
+ files: ['tests/**/*.js'],
16
+ env: { jest: true },
17
+ },
18
+ ],
19
+ };
@@ -0,0 +1,2 @@
1
+ @hero-design/eslint-plugin:lint: cache hit, replaying output 0000ee444f6d82b6
2
+ @hero-design/eslint-plugin:lint: $ eslint .
@@ -0,0 +1,10 @@
1
+ @hero-design/eslint-plugin:test:ci: cache hit, replaying output a90258f7b0211480
2
+ @hero-design/eslint-plugin:test:ci: $ jest --runInBand --logHeapUsage
3
+ @hero-design/eslint-plugin:test:ci: PASS tests/lib/rules/no-deprecated-component-prop-value.js (58 MB heap size)
4
+ @hero-design/eslint-plugin:test:ci: PASS tests/lib/rules/no-deprecated-component-prop.js (71 MB heap size)
5
+ @hero-design/eslint-plugin:test:ci: 
6
+ @hero-design/eslint-plugin:test:ci: Test Suites: 2 passed, 2 total
7
+ @hero-design/eslint-plugin:test:ci: Tests: 30 passed, 30 total
8
+ @hero-design/eslint-plugin:test:ci: Snapshots: 0 total
9
+ @hero-design/eslint-plugin:test:ci: Time: 1.672 s, estimated 3 s
10
+ @hero-design/eslint-plugin:test:ci: Ran all test suites.
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # @hero-design/eslint-plugin
2
+
3
+ Hero Design's eslint plugin
4
+
5
+ ## Installation
6
+
7
+ You'll first need to install [ESLint](https://eslint.org/):
8
+
9
+ ```sh
10
+ yarn add -D eslint
11
+ ```
12
+
13
+ Next, install `@hero-design/eslint-plugin`:
14
+
15
+ ```sh
16
+ yarn add -D @hero-design/eslint-plugin
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Add `@hero-design` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin` postfix:
22
+
23
+ ```json
24
+ {
25
+ "plugins": ["@hero-design"]
26
+ }
27
+ ```
28
+
29
+ Then configure the rules you want to use under the rules section.
30
+
31
+ ```json
32
+ {
33
+ "rules": {
34
+ "@hero-design/rule-name": 2
35
+ }
36
+ }
37
+ ```
38
+
39
+ ## Supported Rules
40
+
41
+ | Rule | Description |
42
+ | ----------------------------------------------- | ------------------------------------------- |
43
+ | @hero-design/no-deprecated-component-prop | Disallow deprecated component props |
44
+ | @hero-design/no-deprecated-component-prop-value | Disallow deprecated component prop's values |
45
+ | @hero-design/no-deprecated-theme-key | Disallow deprecated theme keys |
46
+ | @hero-design/not-recommended-import | Disallow not recommended imports |
@@ -0,0 +1,63 @@
1
+ # Disallow deprecated component prop's values (no-deprecated-component-prop-value)
2
+
3
+ ## Rule Details
4
+
5
+ This rule aims to disallow deprecated component prop's values.
6
+
7
+ Examples of **incorrect** code for this rule:
8
+
9
+ ```js
10
+ <Card prop="deprecatedVariant" />
11
+ ```
12
+
13
+ Examples of **correct** code for this rule:
14
+
15
+ ```js
16
+ <Card prop="newVariant" />
17
+ ```
18
+
19
+ ### Options
20
+
21
+ This rule receives option including package name and component prop's values that are deprecated. For example:
22
+
23
+ ```json
24
+ {
25
+ "package": "@hero-design/rn",
26
+ "components": [
27
+ {
28
+ "name": "Tag",
29
+ "props": [{ "name": "intent", "values": ["default"] }]
30
+ },
31
+ {
32
+ "name": "Alert",
33
+ "props": [{ "name": "variant", "values": ["default"] }]
34
+ },
35
+ {
36
+ "name": "Button",
37
+ "props": [{ "name": "variant", "values": ["basic-transparent"] }]
38
+ },
39
+ {
40
+ "name": "Button.Icon",
41
+ "props": [
42
+ {
43
+ "name": "icon",
44
+ "values": [
45
+ "carat-down-small",
46
+ "carat-down",
47
+ "carat-left-small",
48
+ "carat-left",
49
+ "carat-right-small",
50
+ "carat-right",
51
+ "carat-up-small",
52
+ "carat-up"
53
+ ]
54
+ }
55
+ ]
56
+ }
57
+ ]
58
+ }
59
+ ```
60
+
61
+ ## When To Use It
62
+
63
+ Use this rule when you want to disallow deprecated component prop's values.
@@ -0,0 +1,37 @@
1
+ # Disallow deprecated component props (no-deprecated-component-prop)
2
+
3
+ ## Rule Details
4
+
5
+ This rule aims to disallow deprecated component props.
6
+
7
+ Examples of **incorrect** code for this rule:
8
+
9
+ ```js
10
+ <Card deprecatedProp="any" />
11
+ ```
12
+
13
+ Examples of **correct** code for this rule:
14
+
15
+ ```js
16
+ <Card newProp="any" />
17
+ ```
18
+
19
+ ### Options
20
+
21
+ This rule receives option including package name and component props that are deprecated. For example:
22
+
23
+ ```json
24
+ {
25
+ "package": "@hero-design/rn",
26
+ "components": [
27
+ { "name": "Card", "props": ["variant"] },
28
+ { "name": "Switch", "props": ["size"] },
29
+ { "name": "Select", "props": ["onDimiss", "numberOfLines"] },
30
+ { "name": "Select.Multi", "props": ["onDimiss", "numberOfLines"] },
31
+ ],
32
+ },
33
+ ```
34
+
35
+ ## When To Use It
36
+
37
+ Use this rule when you want to disallow deprecated component props.
@@ -0,0 +1,38 @@
1
+ # Disallow deprecated theme keys (no-deprecated-theme-key)
2
+
3
+ ## Rule Details
4
+
5
+ This rule aims to disallow deprecated theme keys.
6
+
7
+ Examples of **incorrect** code for this rule:
8
+
9
+ ```js
10
+ <Card style={{ backgroundColor: theme.colors.deprecatedColor }} />
11
+ ```
12
+
13
+ Examples of **correct** code for this rule:
14
+
15
+ ```js
16
+ <Card style={{ backgroundColor: theme.colors."new"Color }} />
17
+ ```
18
+
19
+ ### Options
20
+
21
+ This rule receives option including old keys and "new" keys to replace them. For example:
22
+
23
+ ```json
24
+ {
25
+ "keys": [
26
+ { "old": "deprecatedKey", "new": "newKey" },
27
+ { "old": "colors.globalPrimary", "new": "colors.onDefaultGlobalSurface" },
28
+ {
29
+ "old": "colors.globalPrimaryBackground",
30
+ "new": "colors.defaultGlobalSurface"
31
+ }
32
+ ]
33
+ }
34
+ ```
35
+
36
+ ## When To Use It
37
+
38
+ Use this rule when you want to disallow deprecated theme keys.
@@ -0,0 +1,53 @@
1
+ # Disallow not recommended imports (not-recommended-import)
2
+
3
+ ## Rule Details
4
+
5
+ This rule aims to disallow not recommended import.
6
+
7
+ Examples of **incorrect** code for this rule:
8
+
9
+ ```js
10
+ import { notRecommendedUtility, DeprecatedComponent } from '@hero-design/rn';
11
+ ```
12
+
13
+ Examples of **correct** code for this rule:
14
+
15
+ ```js
16
+ import { recommendedUtility, Component } from '@hero-design/rn';
17
+ ```
18
+
19
+ ### Options
20
+
21
+ This rule receives option as an array of configs. Each config includes package name, not recommended imports and the corresponding linter messages.
22
+ Use `"name": "default"` to disallow default import. For example:
23
+
24
+ ```json
25
+ [
26
+ {
27
+ "package": "@hero-design/rn",
28
+ "imports": [
29
+ {
30
+ "name": "swagSystemPalette",
31
+ "message": "Please use colors from useTheme hook instead."
32
+ }
33
+ ]
34
+ },
35
+ {
36
+ "package": "@hero-design/colors",
37
+ "imports": [
38
+ {
39
+ "name": "default",
40
+ "message": "Please use colors from useTheme hook instead."
41
+ },
42
+ {
43
+ "name": "colorScales",
44
+ "message": "Please use colors from useTheme hook instead."
45
+ }
46
+ ]
47
+ }
48
+ ]
49
+ ```
50
+
51
+ ## When To Use It
52
+
53
+ Use it when you want to disallow not recommended import.
package/jest.config.js ADDED
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ testRegex: '(/tests/.*)\\.(ts|tsx|js|jsx)$',
3
+ };
package/lib/index.js ADDED
@@ -0,0 +1,387 @@
1
+ /**
2
+ * @fileoverview Hero Design's eslint plugin
3
+ * @author Thong Quach
4
+ */
5
+ 'use strict';
6
+
7
+ //------------------------------------------------------------------------------
8
+ // Requirements
9
+ //------------------------------------------------------------------------------
10
+
11
+ const requireIndex = require('requireindex');
12
+
13
+ //------------------------------------------------------------------------------
14
+ // Plugin Definition
15
+ //------------------------------------------------------------------------------
16
+
17
+ // import all rules in lib/rules
18
+ module.exports = {
19
+ rules: requireIndex(__dirname + '/rules'),
20
+ configs: {
21
+ internalRn: {
22
+ plugins: ['@hero-design'],
23
+ rules: {
24
+ '@hero-design/no-deprecated-theme-key': [
25
+ 'warn',
26
+ {
27
+ keys: [
28
+ {
29
+ old: 'colors.globalPrimary',
30
+ new: 'colors.onDefaultGlobalSurface',
31
+ },
32
+ {
33
+ old: 'colors.globalPrimaryLight',
34
+ new: 'colors.globalPrimaryLight',
35
+ },
36
+ {
37
+ old: 'colors.globalPrimaryBackground',
38
+ new: 'colors.defaultGlobalSurface',
39
+ },
40
+ {
41
+ old: 'colors.primaryLight',
42
+ new: 'colors.secondary',
43
+ },
44
+ {
45
+ old: 'colors.primaryDark',
46
+ new: 'colors.primary',
47
+ },
48
+ {
49
+ old: 'colors.primaryBackground',
50
+ new: 'colors.highlightedSurface',
51
+ },
52
+ {
53
+ old: 'colors.primaryBackgroundDark',
54
+ new: 'colors.mutedOnDefaultGlobalSurface',
55
+ },
56
+ {
57
+ old: 'colors.secondaryLight',
58
+ new: 'colors.secondaryLight',
59
+ },
60
+ {
61
+ old: 'colors.secondaryBackground',
62
+ new: 'colors.secondaryBackground',
63
+ },
64
+ {
65
+ old: 'colors.infoMediumLight',
66
+ new: 'colors.mutedInfo',
67
+ },
68
+ {
69
+ old: 'colors.infoLight',
70
+ new: 'colors.mutedInfo',
71
+ },
72
+ {
73
+ old: 'colors.infoBackground',
74
+ new: 'colors.infoSurface',
75
+ },
76
+ {
77
+ old: 'colors.successLight',
78
+ new: 'colors.mutedSuccess',
79
+ },
80
+ {
81
+ old: 'colors.successDark',
82
+ new: 'colors.success',
83
+ },
84
+ {
85
+ old: 'colors.successBackground',
86
+ new: 'colors.successSurface',
87
+ },
88
+ {
89
+ old: 'colors.danger',
90
+ new: 'colors.error',
91
+ },
92
+ {
93
+ old: 'colors.dangerMediumLight',
94
+ new: 'colors.mutedError',
95
+ },
96
+ {
97
+ old: 'colors.dangerLight',
98
+ new: 'colors.mutedError',
99
+ },
100
+ {
101
+ old: 'colors.dangerBackground',
102
+ new: 'colors.errorSurface',
103
+ },
104
+ {
105
+ old: 'colors.warningLight',
106
+ new: 'colors.mutedWarning',
107
+ },
108
+ {
109
+ old: 'colors.warningDark',
110
+ new: 'colors.warning',
111
+ },
112
+ {
113
+ old: 'colors.warningBackground',
114
+ new: 'colors.warningSurface',
115
+ },
116
+ {
117
+ old: 'colors.platformBackground',
118
+ new: 'colors.defaultGlobalSurface',
119
+ },
120
+ {
121
+ old: 'colors.backgroundLight',
122
+ new: 'colors.neutralGlobalSurface',
123
+ },
124
+ {
125
+ old: 'colors.backgroundDark',
126
+ new: 'colors.darkGlobalSurface',
127
+ },
128
+ {
129
+ old: 'colors.text',
130
+ new: 'colors.onDefaultGlobalSurface',
131
+ },
132
+ {
133
+ old: 'colors.subduedText',
134
+ new: 'colors.mutedOnDefaultGlobalSurface',
135
+ },
136
+ {
137
+ old: 'colors.disabledText',
138
+ new: 'colors.inactiveOnDefaultGlobalSurface',
139
+ },
140
+ {
141
+ old: 'colors.disabledLightText',
142
+ new: 'colors.disabledOnDefaultGlobalSurface',
143
+ },
144
+ {
145
+ old: 'colors.invertedText',
146
+ new: 'colors.onDarkGlobalSurface',
147
+ },
148
+ {
149
+ old: 'colors.outline',
150
+ new: 'colors.secondaryOutline',
151
+ },
152
+ {
153
+ old: 'colors.archivedLight',
154
+ new: 'colors.disabledOnDefaultGlobalSurface',
155
+ },
156
+ {
157
+ old: 'colors.archivedDark',
158
+ new: 'colors.archived',
159
+ },
160
+ {
161
+ old: 'colors.archivedBackground',
162
+ new: 'colors.archivedSurface',
163
+ },
164
+ {
165
+ old: 'colors.black',
166
+ new: 'colors.onDefaultGlobalSurface',
167
+ },
168
+ {
169
+ old: 'colors.inactiveBackground',
170
+ new: 'colors.inactiveOnDefaultGlobalSurface',
171
+ },
172
+ {
173
+ old: 'colors.shadow',
174
+ new: 'colors.secondaryOutline',
175
+ },
176
+ {
177
+ old: 'colors.mutedGlobalPrimary',
178
+ new: 'colors.mutedOnDefaultGlobalSurface',
179
+ },
180
+ {
181
+ old: 'colors.onGlobalPrimary',
182
+ new: 'colors.onDefaultGlobalSurface',
183
+ },
184
+ {
185
+ old: 'colors.globalSecondary',
186
+ new: 'colors.secondary',
187
+ },
188
+ {
189
+ old: 'colors.globalPrimaryOutline',
190
+ new: 'colors.primaryOutline',
191
+ },
192
+ {
193
+ old: 'colors.globalSecondaryOutline',
194
+ new: 'colors.secondaryOutline',
195
+ },
196
+ {
197
+ old: 'colors.mutedPrimary',
198
+ new: 'colors.mutedPrimary',
199
+ },
200
+ {
201
+ old: 'colors.highlightedSecondarySurface',
202
+ new: 'colors.highlightedSecondarySurface',
203
+ },
204
+ {
205
+ old: 'colors.mutedSecondary',
206
+ new: 'colors.mutedSecondary',
207
+ },
208
+ {
209
+ old: 'colors.disabledSecondary',
210
+ new: 'colors.disabledSecondary',
211
+ },
212
+ {
213
+ old: 'colors.lightHighlightedSurface',
214
+ new: 'colors.highlightedSurface',
215
+ },
216
+ ],
217
+ },
218
+ ],
219
+ '@hero-design/no-deprecated-component-prop': [
220
+ 'warn',
221
+ {
222
+ package: '@hero-design/rn',
223
+ components: [
224
+ { name: 'Card', props: ['variant'] },
225
+ { name: 'Switch', props: ['size'] },
226
+ { name: 'Select', props: ['onDimiss', 'numberOfLines'] },
227
+ { name: 'Select.Multi', props: ['onDimiss', 'numberOfLines'] },
228
+ ],
229
+ },
230
+ ],
231
+ '@hero-design/no-deprecated-component-prop-value': [
232
+ 'warn',
233
+ {
234
+ package: '@hero-design/rn',
235
+ components: [
236
+ {
237
+ name: 'Tag',
238
+ props: [{ name: 'intent', values: ['default'] }],
239
+ },
240
+ {
241
+ name: 'Alert',
242
+ props: [{ name: 'variant', values: ['default'] }],
243
+ },
244
+ {
245
+ name: 'Button',
246
+ props: [{ name: 'variant', values: ['basic-transparent'] }],
247
+ },
248
+ {
249
+ name: 'Button.Icon',
250
+ props: [
251
+ {
252
+ name: 'icon',
253
+ values: [
254
+ 'carat-down-small',
255
+ 'carat-down',
256
+ 'carat-left-small',
257
+ 'carat-left',
258
+ 'carat-right-small',
259
+ 'carat-right',
260
+ 'carat-up-small',
261
+ 'carat-up',
262
+ ],
263
+ },
264
+ ],
265
+ },
266
+ {
267
+ name: 'Button.Utility',
268
+ props: [
269
+ {
270
+ name: 'icon',
271
+ values: [
272
+ 'carat-down-small',
273
+ 'carat-down',
274
+ 'carat-left-small',
275
+ 'carat-left',
276
+ 'carat-right-small',
277
+ 'carat-right',
278
+ 'carat-up-small',
279
+ 'carat-up',
280
+ ],
281
+ },
282
+ ],
283
+ },
284
+ {
285
+ name: 'Icon',
286
+ props: [
287
+ {
288
+ name: 'icon',
289
+ values: [
290
+ 'carat-down-small',
291
+ 'carat-down',
292
+ 'carat-left-small',
293
+ 'carat-left',
294
+ 'carat-right-small',
295
+ 'carat-right',
296
+ 'carat-up-small',
297
+ 'carat-up',
298
+ ],
299
+ },
300
+ ],
301
+ },
302
+ ],
303
+ },
304
+ ],
305
+ },
306
+ },
307
+ recommendedRn: {
308
+ plugins: ['@hero-design'],
309
+ extends: ['plugin:@hero-design/internalRn'],
310
+ rules: {
311
+ '@hero-design/not-recommended-import': [
312
+ 'warn',
313
+ {
314
+ package: '@hero-design/rn',
315
+ imports: [
316
+ {
317
+ name: 'swagSystemPalette',
318
+ message: 'Please use colors from useTheme hook instead.',
319
+ },
320
+ {
321
+ name: 'workSystemPalette',
322
+ message: 'Please use colors from useTheme hook instead.',
323
+ },
324
+ {
325
+ name: 'jobsSystemPalette',
326
+ message: 'Please use colors from useTheme hook instead.',
327
+ },
328
+ {
329
+ name: 'walletSystemPalette',
330
+ message: 'Please use colors from useTheme hook instead.',
331
+ },
332
+ {
333
+ name: 'eBensSystemPalette',
334
+ message: 'Please use colors from useTheme hook instead.',
335
+ },
336
+ ],
337
+ },
338
+ {
339
+ package: '@hero-design/colors',
340
+ imports: [
341
+ {
342
+ name: 'default',
343
+ message: 'Please use colors from useTheme hook instead.',
344
+ },
345
+ {
346
+ name: 'defaultWebPalette',
347
+ message: 'Please use colors from useTheme hook instead.',
348
+ },
349
+ {
350
+ name: 'defaultMobilePalette',
351
+ message: 'Please use colors from useTheme hook instead.',
352
+ },
353
+ {
354
+ name: 'mixColor',
355
+ message: 'Please use colors from useTheme hook instead.',
356
+ },
357
+ {
358
+ name: 'colorScales',
359
+ message: 'Please use colors from useTheme hook instead.',
360
+ },
361
+ {
362
+ name: 'eBensPalette',
363
+ message: 'Please use colors from useTheme hook instead.',
364
+ },
365
+ {
366
+ name: 'jobsPalette',
367
+ message: 'Please use colors from useTheme hook instead.',
368
+ },
369
+ {
370
+ name: 'swagPalette',
371
+ message: 'Please use colors from useTheme hook instead.',
372
+ },
373
+ {
374
+ name: 'walletPalette',
375
+ message: 'Please use colors from useTheme hook instead.',
376
+ },
377
+ {
378
+ name: 'workPalette',
379
+ message: 'Please use colors from useTheme hook instead.',
380
+ },
381
+ ],
382
+ },
383
+ ],
384
+ },
385
+ },
386
+ },
387
+ };