@atlaskit/eslint-plugin-design-system 13.24.2 → 13.26.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/CHANGELOG.md +21 -0
- package/README.md +71 -71
- package/dist/cjs/presets/all-flat.codegen.js +2 -2
- package/dist/cjs/presets/all.codegen.js +2 -2
- package/dist/cjs/presets/recommended-flat.codegen.js +2 -2
- package/dist/cjs/presets/recommended.codegen.js +2 -2
- package/dist/cjs/rules/index.codegen.js +3 -3
- package/dist/cjs/rules/{lozenge-appearance-and-isbold-migration → lozenge-isBold-and-lozenge-badge-appearance-migration}/index.js +115 -19
- package/dist/cjs/rules/use-tokens-shape/transformers/style-map.js +4 -1
- package/dist/es2019/presets/all-flat.codegen.js +2 -2
- package/dist/es2019/presets/all.codegen.js +2 -2
- package/dist/es2019/presets/recommended-flat.codegen.js +2 -2
- package/dist/es2019/presets/recommended.codegen.js +2 -2
- package/dist/es2019/rules/index.codegen.js +3 -3
- package/dist/es2019/rules/{lozenge-appearance-and-isbold-migration → lozenge-isBold-and-lozenge-badge-appearance-migration}/index.js +109 -15
- package/dist/es2019/rules/use-tokens-shape/transformers/style-map.js +4 -1
- package/dist/esm/presets/all-flat.codegen.js +2 -2
- package/dist/esm/presets/all.codegen.js +2 -2
- package/dist/esm/presets/recommended-flat.codegen.js +2 -2
- package/dist/esm/presets/recommended.codegen.js +2 -2
- package/dist/esm/rules/index.codegen.js +3 -3
- package/dist/esm/rules/{lozenge-appearance-and-isbold-migration → lozenge-isBold-and-lozenge-badge-appearance-migration}/index.js +115 -19
- package/dist/esm/rules/use-tokens-shape/transformers/style-map.js +4 -1
- package/dist/types/presets/all-flat.codegen.d.ts +1 -1
- package/dist/types/presets/all.codegen.d.ts +1 -1
- package/dist/types/presets/recommended-flat.codegen.d.ts +1 -1
- package/dist/types/presets/recommended.codegen.d.ts +1 -1
- package/dist/types/rules/index.codegen.d.ts +1 -1
- package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +1 -1
- package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -1
- package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +1 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -1
- package/package.json +3 -3
- /package/dist/types/rules/{lozenge-appearance-and-isbold-migration → lozenge-isBold-and-lozenge-badge-appearance-migration}/index.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{lozenge-appearance-and-isbold-migration → lozenge-isBold-and-lozenge-badge-appearance-migration}/index.d.ts +0 -0
|
@@ -2,18 +2,20 @@ import { isNodeOfType } from 'eslint-codemod-utils';
|
|
|
2
2
|
import { createLintRule } from '../utils/create-rule';
|
|
3
3
|
var rule = createLintRule({
|
|
4
4
|
meta: {
|
|
5
|
-
name: 'lozenge-
|
|
5
|
+
name: 'lozenge-isBold-and-lozenge-badge-appearance-migration',
|
|
6
6
|
fixable: 'code',
|
|
7
7
|
type: 'suggestion',
|
|
8
8
|
docs: {
|
|
9
|
-
description: 'Helps migrate
|
|
9
|
+
description: 'Helps migrate Lozenge isBold prop and appearance values (for both Lozenge and Badge components) as part of the Labelling System Phase 1 migration.',
|
|
10
10
|
recommended: true,
|
|
11
11
|
severity: 'warn'
|
|
12
12
|
},
|
|
13
13
|
messages: {
|
|
14
14
|
updateAppearance: 'Update appearance value to new semantic value.',
|
|
15
15
|
migrateTag: 'Non-bold <Lozenge> variants should migrate to <Tag> component.',
|
|
16
|
-
manualReview: "Dynamic 'isBold' props require manual review before migration."
|
|
16
|
+
manualReview: "Dynamic 'isBold' props require manual review before migration.",
|
|
17
|
+
updateBadgeAppearance: 'Update Badge appearance value "{{oldValue}}" to new semantic value "{{newValue}}".',
|
|
18
|
+
dynamicBadgeAppearance: 'Dynamic appearance prop values require manual review to ensure they use the new semantic values: neutral, information, inverse, danger, success.'
|
|
17
19
|
}
|
|
18
20
|
},
|
|
19
21
|
create: function create(context) {
|
|
@@ -22,6 +24,11 @@ var rule = createLintRule({
|
|
|
22
24
|
*/
|
|
23
25
|
var lozengeImports = {}; // local name -> import source
|
|
24
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Contains a map of imported Badge components.
|
|
29
|
+
*/
|
|
30
|
+
var badgeImports = {}; // local name -> import source
|
|
31
|
+
|
|
25
32
|
/**
|
|
26
33
|
* Check if a JSX attribute value is a literal false
|
|
27
34
|
*/
|
|
@@ -30,14 +37,25 @@ var rule = createLintRule({
|
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
/**
|
|
33
|
-
* Check if a JSX attribute value is dynamic (not a literal
|
|
40
|
+
* Check if a JSX attribute value is dynamic (not a static literal value)
|
|
41
|
+
* Can be used for any prop type (boolean, string, etc.)
|
|
34
42
|
*/
|
|
35
43
|
function isDynamicExpression(node) {
|
|
36
|
-
if (!node
|
|
44
|
+
if (!node) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// If it's a plain literal (e.g., appearance="value"), it's not dynamic
|
|
49
|
+
if (node.type === 'Literal') {
|
|
37
50
|
return false;
|
|
38
51
|
}
|
|
39
|
-
|
|
40
|
-
|
|
52
|
+
|
|
53
|
+
// If it's an expression container with a non-literal expression, it's dynamic
|
|
54
|
+
if (node.type === 'JSXExpressionContainer') {
|
|
55
|
+
var expr = node.expression;
|
|
56
|
+
return expr && expr.type !== 'Literal';
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
41
59
|
}
|
|
42
60
|
|
|
43
61
|
/**
|
|
@@ -70,6 +88,21 @@ var rule = createLintRule({
|
|
|
70
88
|
return mapping[oldValue] || oldValue;
|
|
71
89
|
}
|
|
72
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Map Badge old appearance values to new semantic appearance values
|
|
93
|
+
*/
|
|
94
|
+
function mapBadgeToNewAppearanceValue(oldValue) {
|
|
95
|
+
var mapping = {
|
|
96
|
+
added: 'success',
|
|
97
|
+
removed: 'danger',
|
|
98
|
+
default: 'neutral',
|
|
99
|
+
primary: 'information',
|
|
100
|
+
primaryInverted: 'inverse',
|
|
101
|
+
important: 'danger'
|
|
102
|
+
};
|
|
103
|
+
return mapping[oldValue] || oldValue;
|
|
104
|
+
}
|
|
105
|
+
|
|
73
106
|
/**
|
|
74
107
|
* Extract the string value from a JSX attribute value
|
|
75
108
|
*/
|
|
@@ -86,6 +119,25 @@ var rule = createLintRule({
|
|
|
86
119
|
return null;
|
|
87
120
|
}
|
|
88
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Create a fixer function to replace an appearance prop value
|
|
124
|
+
* Handles both Literal and JSXExpressionContainer with Literal
|
|
125
|
+
*/
|
|
126
|
+
function createAppearanceFixer(attrValue, newValue) {
|
|
127
|
+
return function (fixer) {
|
|
128
|
+
if (!attrValue) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
if (attrValue.type === 'Literal') {
|
|
132
|
+
return fixer.replaceText(attrValue, "\"".concat(newValue, "\""));
|
|
133
|
+
}
|
|
134
|
+
if (attrValue.type === 'JSXExpressionContainer' && 'expression' in attrValue && attrValue.expression && attrValue.expression.type === 'Literal') {
|
|
135
|
+
return fixer.replaceText(attrValue.expression, "\"".concat(newValue, "\""));
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
89
141
|
/**
|
|
90
142
|
* Generate the replacement JSX element text
|
|
91
143
|
*/
|
|
@@ -147,6 +199,18 @@ var rule = createLintRule({
|
|
|
147
199
|
}
|
|
148
200
|
});
|
|
149
201
|
}
|
|
202
|
+
// Track Badge imports
|
|
203
|
+
if (moduleSource === '@atlaskit/badge' || moduleSource.startsWith('@atlaskit/badge')) {
|
|
204
|
+
node.specifiers.forEach(function (spec) {
|
|
205
|
+
if (spec.type === 'ImportDefaultSpecifier') {
|
|
206
|
+
badgeImports[spec.local.name] = moduleSource;
|
|
207
|
+
} else if (spec.type === 'ImportSpecifier' && spec.imported.type === 'Identifier') {
|
|
208
|
+
if (spec.imported.name === 'Badge' || spec.imported.name === 'default') {
|
|
209
|
+
badgeImports[spec.local.name] = moduleSource;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
150
214
|
}
|
|
151
215
|
},
|
|
152
216
|
JSXElement: function JSXElement(node) {
|
|
@@ -158,6 +222,45 @@ var rule = createLintRule({
|
|
|
158
222
|
}
|
|
159
223
|
var elementName = node.openingElement.name.name;
|
|
160
224
|
|
|
225
|
+
// Handle Badge components
|
|
226
|
+
if (badgeImports[elementName]) {
|
|
227
|
+
// Find the appearance prop
|
|
228
|
+
var _appearanceProp = node.openingElement.attributes.find(function (attr) {
|
|
229
|
+
return attr.type === 'JSXAttribute' && attr.name.type === 'JSXIdentifier' && attr.name.name === 'appearance';
|
|
230
|
+
});
|
|
231
|
+
if (!_appearanceProp || _appearanceProp.type !== 'JSXAttribute') {
|
|
232
|
+
// No appearance prop or it's a spread attribute, nothing to migrate
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Check if it's a dynamic expression
|
|
237
|
+
if (isDynamicExpression(_appearanceProp.value)) {
|
|
238
|
+
context.report({
|
|
239
|
+
node: _appearanceProp,
|
|
240
|
+
messageId: 'dynamicBadgeAppearance'
|
|
241
|
+
});
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Extract the string value
|
|
246
|
+
var stringValue = extractStringValue(_appearanceProp.value);
|
|
247
|
+
if (stringValue && typeof stringValue === 'string') {
|
|
248
|
+
var mappedValue = mapBadgeToNewAppearanceValue(stringValue);
|
|
249
|
+
if (mappedValue !== stringValue) {
|
|
250
|
+
context.report({
|
|
251
|
+
node: _appearanceProp,
|
|
252
|
+
messageId: 'updateBadgeAppearance',
|
|
253
|
+
data: {
|
|
254
|
+
oldValue: stringValue,
|
|
255
|
+
newValue: mappedValue
|
|
256
|
+
},
|
|
257
|
+
fix: createAppearanceFixer(_appearanceProp.value, mappedValue)
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
|
|
161
264
|
// Only process if this is a Lozenge component we've imported
|
|
162
265
|
if (!lozengeImports[elementName]) {
|
|
163
266
|
return;
|
|
@@ -171,21 +274,14 @@ var rule = createLintRule({
|
|
|
171
274
|
var shouldMigrateToTag = !isBoldProp || isLiteralFalse(isBoldProp.value);
|
|
172
275
|
if (!shouldMigrateToTag) {
|
|
173
276
|
// Only update appearance values for Lozenge components that stay as Lozenge
|
|
174
|
-
var
|
|
175
|
-
if (
|
|
176
|
-
var
|
|
177
|
-
if (
|
|
277
|
+
var _stringValue = extractStringValue(appearanceProp.value);
|
|
278
|
+
if (_stringValue && typeof _stringValue === 'string') {
|
|
279
|
+
var _mappedValue = mapToNewAppearanceValue(_stringValue);
|
|
280
|
+
if (_mappedValue !== _stringValue) {
|
|
178
281
|
context.report({
|
|
179
282
|
node: appearanceProp,
|
|
180
283
|
messageId: 'updateAppearance',
|
|
181
|
-
fix:
|
|
182
|
-
if (appearanceProp.value.type === 'Literal') {
|
|
183
|
-
return fixer.replaceText(appearanceProp.value, "\"".concat(mappedValue, "\""));
|
|
184
|
-
} else if (appearanceProp.value.type === 'JSXExpressionContainer' && appearanceProp.value.expression && appearanceProp.value.expression.type === 'Literal') {
|
|
185
|
-
return fixer.replaceText(appearanceProp.value.expression, "\"".concat(mappedValue, "\""));
|
|
186
|
-
}
|
|
187
|
-
return null;
|
|
188
|
-
}
|
|
284
|
+
fix: createAppearanceFixer(appearanceProp.value, _mappedValue)
|
|
189
285
|
});
|
|
190
286
|
}
|
|
191
287
|
}
|
|
@@ -5,6 +5,7 @@ var radiusTokenMap = {
|
|
|
5
5
|
'6px': 'radius.medium',
|
|
6
6
|
'8px': 'radius.large',
|
|
7
7
|
'12px': 'radius.xlarge',
|
|
8
|
+
'16px': 'radius.xxlarge',
|
|
8
9
|
'50%': 'radius.full',
|
|
9
10
|
'100%': 'radius.full',
|
|
10
11
|
2: 'radius.xsmall',
|
|
@@ -13,11 +14,13 @@ var radiusTokenMap = {
|
|
|
13
14
|
6: 'radius.medium',
|
|
14
15
|
8: 'radius.large',
|
|
15
16
|
12: 'radius.xlarge',
|
|
17
|
+
16: 'radius.xxlarge',
|
|
16
18
|
'0.125rem': 'radius.xsmall',
|
|
17
19
|
'0.25rem': 'radius.small',
|
|
18
20
|
'0.375rem': 'radius.medium',
|
|
19
21
|
'0.5rem': 'radius.large',
|
|
20
|
-
'0.75rem': 'radius.xlarge'
|
|
22
|
+
'0.75rem': 'radius.xlarge',
|
|
23
|
+
'1rem': 'radius.xxlarge'
|
|
21
24
|
};
|
|
22
25
|
var borderWidthTokenMap = {
|
|
23
26
|
'1px': 'border.width'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::df988d512376c1317e5f7a350ad19fb9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
import type { Linter } from 'eslint';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::2dee8518d733b0b364809d0f5641afda>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
import type { ESLint } from 'eslint';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::7ed1a8eeaaea559980cb2c533ba9a2e6>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
import type { Linter } from 'eslint';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::32a0942d7edc5a3fdc70dd0833bb8aca>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
import type { ESLint } from 'eslint';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::c74b833590d4eb693616a3fcbf2e335a>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
import type { Rule } from 'eslint';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::df988d512376c1317e5f7a350ad19fb9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
import type { Linter } from 'eslint';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::2dee8518d733b0b364809d0f5641afda>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
import type { ESLint } from 'eslint';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::7ed1a8eeaaea559980cb2c533ba9a2e6>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
import type { Linter } from 'eslint';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::32a0942d7edc5a3fdc70dd0833bb8aca>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
import type { ESLint } from 'eslint';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::c74b833590d4eb693616a3fcbf2e335a>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
import type { Rule } from 'eslint';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-design-system",
|
|
3
3
|
"description": "The essential plugin for use with the Atlassian Design System.",
|
|
4
|
-
"version": "13.
|
|
4
|
+
"version": "13.26.0",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"publishConfig": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@atlaskit/eslint-utils": "^2.0.0",
|
|
42
42
|
"@atlaskit/icon": "^29.0.0",
|
|
43
43
|
"@atlaskit/icon-lab": "^5.12.0",
|
|
44
|
-
"@atlaskit/tokens": "^8.
|
|
44
|
+
"@atlaskit/tokens": "^8.2.0",
|
|
45
45
|
"@babel/runtime": "^7.0.0",
|
|
46
46
|
"@typescript-eslint/utils": "^7.1.0",
|
|
47
47
|
"ajv": "^6.12.6",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@af/formatting": "workspace:^",
|
|
57
|
-
"@atlaskit/ds-lib": "^5.
|
|
57
|
+
"@atlaskit/ds-lib": "^5.3.0",
|
|
58
58
|
"@atlaskit/theme": "^21.0.0",
|
|
59
59
|
"@atlassian/codegen": "^0.1.0",
|
|
60
60
|
"@atlassian/eslint-utils": "^0.5.0",
|
|
File without changes
|