@hero-design/eslint-plugin 9.2.0-rc.1 → 9.3.0-rc.0

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/lib/index.js CHANGED
@@ -14,213 +14,6 @@ const requireIndex = require('requireindex');
14
14
  // Plugin Definition
15
15
  //------------------------------------------------------------------------------
16
16
 
17
- const themeKeysMap = [
18
- {
19
- old: 'colors.globalPrimary',
20
- new: 'colors.onDefaultGlobalSurface',
21
- },
22
- {
23
- old: 'colors.globalPrimaryLight',
24
- new: 'colors.globalPrimaryLight',
25
- },
26
- {
27
- old: 'colors.globalPrimaryBackground',
28
- new: 'colors.defaultGlobalSurface',
29
- },
30
- {
31
- old: 'colors.primaryLight',
32
- new: 'colors.secondary',
33
- },
34
- {
35
- old: 'colors.primaryDark',
36
- new: 'colors.primary',
37
- },
38
- {
39
- old: 'colors.primaryBackground',
40
- new: 'colors.highlightedSurface',
41
- },
42
- {
43
- old: 'colors.primaryBackgroundDark',
44
- new: 'colors.mutedOnDefaultGlobalSurface',
45
- },
46
- {
47
- old: 'colors.secondaryLight',
48
- new: 'colors.secondaryLight',
49
- },
50
- {
51
- old: 'colors.secondaryBackground',
52
- new: 'colors.secondaryBackground',
53
- },
54
- {
55
- old: 'colors.infoMediumLight',
56
- new: 'colors.mutedInfo',
57
- },
58
- {
59
- old: 'colors.infoLight',
60
- new: 'colors.mutedInfo',
61
- },
62
- {
63
- old: 'colors.infoBackground',
64
- new: 'colors.infoSurface',
65
- },
66
- {
67
- old: 'colors.successLight',
68
- new: 'colors.mutedSuccess',
69
- },
70
- {
71
- old: 'colors.successDark',
72
- new: 'colors.success',
73
- },
74
- {
75
- old: 'colors.successBackground',
76
- new: 'colors.successSurface',
77
- },
78
- {
79
- old: 'colors.danger',
80
- new: 'colors.error',
81
- },
82
- {
83
- old: 'colors.dangerMediumLight',
84
- new: 'colors.mutedError',
85
- },
86
- {
87
- old: 'colors.dangerLight',
88
- new: 'colors.mutedError',
89
- },
90
- {
91
- old: 'colors.dangerBackground',
92
- new: 'colors.errorSurface',
93
- },
94
- {
95
- old: 'colors.warningLight',
96
- new: 'colors.mutedWarning',
97
- },
98
- {
99
- old: 'colors.warningDark',
100
- new: 'colors.warning',
101
- },
102
- {
103
- old: 'colors.warningBackground',
104
- new: 'colors.warningSurface',
105
- },
106
- {
107
- old: 'colors.platformBackground',
108
- new: 'colors.defaultGlobalSurface',
109
- },
110
- {
111
- old: 'colors.backgroundLight',
112
- new: 'colors.neutralGlobalSurface',
113
- },
114
- {
115
- old: 'colors.backgroundDark',
116
- new: 'colors.darkGlobalSurface',
117
- },
118
- {
119
- old: 'colors.text',
120
- new: 'colors.onDefaultGlobalSurface',
121
- },
122
- {
123
- old: 'colors.subduedText',
124
- new: 'colors.mutedOnDefaultGlobalSurface',
125
- },
126
- {
127
- old: 'colors.disabledText',
128
- new: 'colors.inactiveOnDefaultGlobalSurface',
129
- },
130
- {
131
- old: 'colors.disabledLightText',
132
- new: 'colors.disabledOnDefaultGlobalSurface',
133
- },
134
- {
135
- old: 'colors.invertedText',
136
- new: 'colors.onDarkGlobalSurface',
137
- },
138
- {
139
- old: 'colors.outline',
140
- new: 'colors.secondaryOutline',
141
- },
142
- {
143
- old: 'colors.archivedLight',
144
- new: 'colors.disabledOnDefaultGlobalSurface',
145
- },
146
- {
147
- old: 'colors.archivedDark',
148
- new: 'colors.archived',
149
- },
150
- {
151
- old: 'colors.archivedBackground',
152
- new: 'colors.archivedSurface',
153
- },
154
- {
155
- old: 'colors.black',
156
- new: 'colors.onDefaultGlobalSurface',
157
- },
158
- {
159
- old: 'colors.inactiveBackground',
160
- new: 'colors.inactiveOnDefaultGlobalSurface',
161
- },
162
- {
163
- old: 'colors.shadow',
164
- new: 'colors.secondaryOutline',
165
- },
166
- {
167
- old: 'colors.mutedGlobalPrimary',
168
- new: 'colors.mutedOnDefaultGlobalSurface',
169
- },
170
- {
171
- old: 'colors.onGlobalPrimary',
172
- new: 'colors.onDefaultGlobalSurface',
173
- },
174
- {
175
- old: 'colors.globalSecondary',
176
- new: 'colors.secondary',
177
- },
178
- {
179
- old: 'colors.globalPrimaryOutline',
180
- new: 'colors.primaryOutline',
181
- },
182
- {
183
- old: 'colors.globalSecondaryOutline',
184
- new: 'colors.secondaryOutline',
185
- },
186
- {
187
- old: 'colors.mutedPrimary',
188
- new: 'colors.mutedPrimary',
189
- },
190
- {
191
- old: 'colors.highlightedSecondarySurface',
192
- new: 'colors.highlightedSecondarySurface',
193
- },
194
- {
195
- old: 'colors.mutedSecondary',
196
- new: 'colors.mutedSecondary',
197
- },
198
- {
199
- old: 'colors.disabledSecondary',
200
- new: 'colors.disabledSecondary',
201
- },
202
- {
203
- old: 'colors.lightHighlightedSurface',
204
- new: 'colors.highlightedSurface',
205
- },
206
- ];
207
- const deprecatedThemeColors = themeKeysMap.map((c) => c.old.split('.')[1]);
208
- const boxColorProps = [
209
- 'backgroundColor',
210
- 'bgColor',
211
- 'borderColor',
212
- 'borderTopColor',
213
- 'borderBottomColor',
214
- 'borderStartColor',
215
- 'borderEndColor',
216
- 'borderLeftColor',
217
- 'borderRightColor',
218
- ];
219
- const deprecatedBoxPropValues = boxColorProps.map((prop) => ({
220
- name: prop,
221
- values: deprecatedThemeColors,
222
- }));
223
-
224
17
  // import all rules in lib/rules
225
18
  module.exports = {
226
19
  rules: requireIndex(__dirname + '/rules'),
@@ -228,102 +21,18 @@ module.exports = {
228
21
  internalRn: {
229
22
  plugins: ['@hero-design'],
230
23
  rules: {
231
- '@hero-design/no-deprecated-theme-key': [
232
- 'error',
233
- {
234
- keys: themeKeysMap,
235
- },
236
- ],
24
+ // Rules for the current version
237
25
  '@hero-design/no-deprecated-component-prop': [
238
26
  'error',
239
27
  {
240
28
  package: '@hero-design/rn',
241
29
  components: [
242
- { name: 'Card', props: ['variant'] },
243
- { name: 'Switch', props: ['size'] },
244
- {
245
- name: 'Select',
246
- props: ['onDimiss', 'numberOfLines', 'inputProps.required'],
247
- },
248
- {
249
- name: 'Select.Multi',
250
- props: ['onDimiss', 'numberOfLines', 'inputProps.required'],
251
- },
252
- { name: 'Toast.Provider', props: ['position'] },
253
- ],
254
- },
255
- ],
256
- '@hero-design/no-deprecated-component-prop-value': [
257
- 'error',
258
- {
259
- package: '@hero-design/rn',
260
- components: [
261
- {
262
- name: 'Tag',
263
- props: [{ name: 'intent', values: ['default'] }],
264
- },
265
- {
266
- name: 'Button',
267
- props: [{ name: 'variant', values: ['basic-transparent'] }],
268
- },
269
- {
270
- name: 'Button.Icon',
271
- props: [
272
- {
273
- name: 'icon',
274
- values: [
275
- 'carat-down-small',
276
- 'carat-down',
277
- 'carat-left-small',
278
- 'carat-left',
279
- 'carat-right-small',
280
- 'carat-right',
281
- 'carat-up-small',
282
- 'carat-up',
283
- ],
284
- },
285
- ],
286
- },
287
- {
288
- name: 'Button.Utility',
289
- props: [
290
- {
291
- name: 'icon',
292
- values: [
293
- 'carat-down-small',
294
- 'carat-down',
295
- 'carat-left-small',
296
- 'carat-left',
297
- 'carat-right-small',
298
- 'carat-right',
299
- 'carat-up-small',
300
- 'carat-up',
301
- ],
302
- },
303
- ],
304
- },
305
- {
306
- name: 'Icon',
307
- props: [
308
- {
309
- name: 'icon',
310
- values: [
311
- 'carat-down-small',
312
- 'carat-down',
313
- 'carat-left-small',
314
- 'carat-left',
315
- 'carat-right-small',
316
- 'carat-right',
317
- 'carat-up-small',
318
- 'carat-up',
319
- ],
320
- },
321
- ],
322
- },
323
30
  {
324
- name: 'Box',
325
- props: deprecatedBoxPropValues,
31
+ name: 'Carousel',
32
+ props: ['pageControlPosition', 'shouldShowPagination'],
326
33
  },
34
+ { name: 'Error', props: ['visible'] },
35
+ { name: 'Tag', props: ['variant'] },
327
36
  ],
328
37
  },
329
38
  ],
@@ -333,6 +42,7 @@ module.exports = {
333
42
  plugins: ['@hero-design'],
334
43
  extends: ['plugin:@hero-design/internalRn'],
335
44
  rules: {
45
+ '@hero-design/no-invalid-theme-access': 'error',
336
46
  '@hero-design/not-recommended-import': [
337
47
  'warn',
338
48
  {
@@ -0,0 +1,4 @@
1
+
2
+ const rule = require('./no-deprecated-component-prop');
3
+
4
+ module.exports = rule;
@@ -0,0 +1,97 @@
1
+ 'use strict';
2
+
3
+ //------------------------------------------------------------------------------
4
+ // Rule Definition
5
+ //------------------------------------------------------------------------------
6
+
7
+ const findPaths = (node, paths) => {
8
+ if (node == null) {
9
+ return paths;
10
+ }
11
+ const property = node.property;
12
+ if (
13
+ property != null &&
14
+ property.type === 'Identifier' &&
15
+ property.name != null
16
+ ) {
17
+ return findPaths(node.parent, [...paths, property.name]);
18
+ }
19
+ return paths;
20
+ };
21
+
22
+ const getError = (themePath) => {
23
+ if (themePath == null || themePath === '') {
24
+ return 'Invalid access to theming object';
25
+ }
26
+
27
+ if (themePath.startsWith('__hd__')) {
28
+ return 'Invalid access to component level theming object.';
29
+ }
30
+
31
+ return undefined;
32
+ };
33
+
34
+ /** @type {import('eslint').Rule.RuleModule} */
35
+ module.exports = {
36
+ meta: {
37
+ type: 'problem', // `problem`, `suggestion`, or `layout`
38
+ docs: {
39
+ description: 'Invalidate theming access',
40
+ recommended: false,
41
+ },
42
+ fixable: null, // or "code" or "whitespace"
43
+ schema: [
44
+ {
45
+ properties: {
46
+ themeFile: { type: ['string'] },
47
+ },
48
+ },
49
+ ],
50
+ messages: {
51
+ invalidThemeAccess: 'Invalid access to component level theming object.',
52
+ },
53
+ },
54
+ create: function (context) {
55
+ return {
56
+ MemberExpression(node) {
57
+ const object = node.object;
58
+ if (object == null) {
59
+ return;
60
+ }
61
+
62
+ if (object.type === 'Identifier' && object.name === 'theme') {
63
+ const paths = findPaths(node, []);
64
+ const themePath = paths.join('.');
65
+ const error = getError(themePath);
66
+ if (error != null) {
67
+ context.report({
68
+ node,
69
+ messageId: 'invalidThemeAccess',
70
+ });
71
+ }
72
+ return;
73
+ }
74
+
75
+ const property = node.property;
76
+ if (
77
+ property != null &&
78
+ property.name === 'theme' &&
79
+ object.type === 'Identifier' &&
80
+ object.name === 'props'
81
+ ) {
82
+ // First element is theme, we don't need it
83
+ const [, ...paths] = findPaths(node, []);
84
+ const themePath = paths.join('.');
85
+ const error = getError(themePath);
86
+ if (error != null) {
87
+ context.report({
88
+ node,
89
+ messageId: 'invalidThemeAccess',
90
+ });
91
+ }
92
+ return;
93
+ }
94
+ },
95
+ };
96
+ },
97
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hero-design/eslint-plugin",
3
- "version": "9.2.0-rc.1",
3
+ "version": "9.3.0-rc.0",
4
4
  "description": "Hero Design's eslint plugin",
5
5
  "keywords": [
6
6
  "eslint",
@@ -26,7 +26,7 @@
26
26
  "eslint-plugin-eslint-plugin": "^5.0.0",
27
27
  "eslint-plugin-node": "^11.1.0",
28
28
  "jest": "^27.3.1",
29
- "prettier-config-hd": "9.2.0-rc.1"
29
+ "prettier-config-hd": "9.3.0-rc.0"
30
30
  },
31
31
  "engines": {
32
32
  "node": "^14.17.0 || ^16.0.0 || >= 18.0.0"
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ //------------------------------------------------------------------------------
4
+ // Requirements
5
+ //------------------------------------------------------------------------------
6
+
7
+ var rule = require('../../../lib/rules/no-invalid-theme-access'),
8
+ RuleTester = require('eslint').RuleTester;
9
+
10
+ //------------------------------------------------------------------------------
11
+ // Tests
12
+ //------------------------------------------------------------------------------
13
+
14
+ var ruleTester = new RuleTester();
15
+ ruleTester.run('no-invalid-theme-access', rule, {
16
+ valid: [
17
+ {
18
+ code: 'theme.space.medium',
19
+ },
20
+ ],
21
+ invalid: [
22
+ {
23
+ code: 'theme.__hd__.card.space.titlePadding',
24
+ errors: [
25
+ {
26
+ type: 'MemberExpression',
27
+ message: 'Invalid access to component level theming object.',
28
+ },
29
+ ],
30
+ },
31
+ {
32
+ code: 'props.theme.__hd__.card.space.titlePadding',
33
+ errors: [
34
+ {
35
+ type: 'MemberExpression',
36
+ message: 'Invalid access to component level theming object.',
37
+ },
38
+ ],
39
+ },
40
+ ],
41
+ });