@hero-design/eslint-plugin 8.34.4 → 8.35.1-alpha-10
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/.turbo/turbo-lint.log +1 -0
- package/.turbo/turbo-publish:npm.log +9 -0
- package/lib/index.js +4 -300
- package/lib/rules/no-deprecated-component-prop-next.js +4 -0
- package/lib/rules/no-invalid-theme-access.js +101 -0
- package/package.json +1 -1
- package/tests/lib/rules/no-invalid-theme-access.js +49 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
$ eslint .
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
[35m@hero-design/eslint-plugin:publish:npm[0m: cache hit, replaying output [2me4366cba7a6afe95[0m
|
|
2
|
+
[35m@hero-design/eslint-plugin:publish:npm: [0m$ yarn publish --access public
|
|
3
|
+
[35m@hero-design/eslint-plugin:publish:npm: [0m[1/4] Bumping version...
|
|
4
|
+
[35m@hero-design/eslint-plugin:publish:npm: [0minfo Current version: 8.12.0-rc.0
|
|
5
|
+
[35m@hero-design/eslint-plugin:publish:npm: [0m[2/4] Logging in...
|
|
6
|
+
[35m@hero-design/eslint-plugin:publish:npm: [0m[3/4] Publishing...
|
|
7
|
+
[35m@hero-design/eslint-plugin:publish:npm: [0msuccess Published.
|
|
8
|
+
[35m@hero-design/eslint-plugin:publish:npm: [0m[4/4] Revoking token...
|
|
9
|
+
[35m@hero-design/eslint-plugin:publish:npm: [0minfo Not revoking login token, specified via config file.
|
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,13 @@ module.exports = {
|
|
|
228
21
|
internalRn: {
|
|
229
22
|
plugins: ['@hero-design'],
|
|
230
23
|
rules: {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
keys: themeKeysMap,
|
|
235
|
-
},
|
|
236
|
-
],
|
|
237
|
-
'@hero-design/no-deprecated-component-prop': [
|
|
238
|
-
'error',
|
|
239
|
-
{
|
|
240
|
-
package: '@hero-design/rn',
|
|
241
|
-
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',
|
|
24
|
+
// Rules for the next major version
|
|
25
|
+
'@hero-design/no-deprecated-component-prop-next': [
|
|
26
|
+
'warn',
|
|
258
27
|
{
|
|
259
28
|
package: '@hero-design/rn',
|
|
260
29
|
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
|
-
{
|
|
324
|
-
name: 'Box',
|
|
325
|
-
props: deprecatedBoxPropValues,
|
|
326
|
-
},
|
|
30
|
+
{ name: 'Tag', props: ['variant'] },
|
|
327
31
|
],
|
|
328
32
|
},
|
|
329
33
|
],
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Invalidate theming access
|
|
3
|
+
* @author Hieu Pham
|
|
4
|
+
*/
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Rule Definition
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
const findPaths = (node, paths) => {
|
|
12
|
+
if (node == null) {
|
|
13
|
+
return paths;
|
|
14
|
+
}
|
|
15
|
+
const property = node.property;
|
|
16
|
+
if (
|
|
17
|
+
property != null &&
|
|
18
|
+
property.type === 'Identifier' &&
|
|
19
|
+
property.name != null
|
|
20
|
+
) {
|
|
21
|
+
return findPaths(node.parent, [...paths, property.name]);
|
|
22
|
+
}
|
|
23
|
+
return paths;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const getError = (themePath) => {
|
|
27
|
+
if (themePath == null || themePath === '') {
|
|
28
|
+
return 'Invalid access to theming object';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (themePath.startsWith('__hd__')) {
|
|
32
|
+
return 'Invalid access to component level theming object';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return undefined;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
39
|
+
module.exports = {
|
|
40
|
+
meta: {
|
|
41
|
+
type: 'problem', // `problem`, `suggestion`, or `layout`
|
|
42
|
+
docs: {
|
|
43
|
+
description: 'Invalidate theming access',
|
|
44
|
+
recommended: false,
|
|
45
|
+
},
|
|
46
|
+
fixable: null, // or "code" or "whitespace"
|
|
47
|
+
schema: [
|
|
48
|
+
{
|
|
49
|
+
properties: {
|
|
50
|
+
themeFile: { type: ['string'] },
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
messages: {
|
|
55
|
+
invalidThemeAccess: 'Invalid access to component level theming object.',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
create: function (context) {
|
|
59
|
+
return {
|
|
60
|
+
MemberExpression(node) {
|
|
61
|
+
const object = node.object;
|
|
62
|
+
if (object == null) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (object.type === 'Identifier' && object.name === 'theme') {
|
|
67
|
+
const paths = findPaths(node, []);
|
|
68
|
+
const themePath = paths.join('.');
|
|
69
|
+
const error = getError(themePath);
|
|
70
|
+
if (error != null) {
|
|
71
|
+
context.report({
|
|
72
|
+
node,
|
|
73
|
+
messageId: 'invalidThemeAccess',
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const property = node.property;
|
|
80
|
+
if (
|
|
81
|
+
property != null &&
|
|
82
|
+
property.name === 'theme' &&
|
|
83
|
+
object.type === 'Identifier' &&
|
|
84
|
+
object.name === 'props'
|
|
85
|
+
) {
|
|
86
|
+
// First element is theme, we don't need it
|
|
87
|
+
const [, ...paths] = findPaths(node, []);
|
|
88
|
+
const themePath = paths.join('.');
|
|
89
|
+
const error = getError(themePath);
|
|
90
|
+
if (error != null) {
|
|
91
|
+
context.report({
|
|
92
|
+
node,
|
|
93
|
+
messageId: 'invalidThemeAccess',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Invalidate theming access
|
|
3
|
+
* @author Hieu Pham
|
|
4
|
+
*/
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
// Requirements
|
|
9
|
+
//------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
var rule = require('../../../lib/rules/no-invalid-theme-access'),
|
|
12
|
+
RuleTester = require('eslint').RuleTester;
|
|
13
|
+
|
|
14
|
+
//------------------------------------------------------------------------------
|
|
15
|
+
// Tests
|
|
16
|
+
//------------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
var themeFile = './../../src/theme';
|
|
19
|
+
|
|
20
|
+
var ruleTester = new RuleTester();
|
|
21
|
+
ruleTester.run('no-invalid-theme-access', rule, {
|
|
22
|
+
valid: [
|
|
23
|
+
{
|
|
24
|
+
code: 'theme.space.medium',
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
invalid: [
|
|
28
|
+
{
|
|
29
|
+
code: 'theme.__hd__.card.space.titlePadding',
|
|
30
|
+
options: [{ package: themeFile, name: 'theme' }],
|
|
31
|
+
errors: [
|
|
32
|
+
{
|
|
33
|
+
type: 'MemberExpression',
|
|
34
|
+
message: 'Invalid access to component level theming object',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
code: 'props.theme.__hd__.card.space.titlePadding',
|
|
40
|
+
options: [{ package: themeFile, name: 'theme' }],
|
|
41
|
+
errors: [
|
|
42
|
+
{
|
|
43
|
+
type: 'MemberExpression',
|
|
44
|
+
message: 'Invalid access to component level theming object',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
});
|