@atlaskit/eslint-plugin-design-system 9.4.0 → 9.5.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 +12 -0
- package/constellation/use-tokens-typography/usage.mdx +6 -2
- package/dist/cjs/rules/use-tokens-typography/config/index.js +5 -1
- package/dist/cjs/rules/use-tokens-typography/index.js +2 -1
- package/dist/cjs/rules/use-tokens-typography/transformers/style-object.js +16 -9
- package/dist/cjs/rules/use-tokens-typography/utils.js +9 -9
- package/dist/es2019/rules/use-tokens-typography/config/index.js +5 -1
- package/dist/es2019/rules/use-tokens-typography/index.js +2 -1
- package/dist/es2019/rules/use-tokens-typography/transformers/style-object.js +16 -9
- package/dist/es2019/rules/use-tokens-typography/utils.js +8 -9
- package/dist/esm/rules/use-tokens-typography/config/index.js +5 -1
- package/dist/esm/rules/use-tokens-typography/index.js +2 -1
- package/dist/esm/rules/use-tokens-typography/transformers/style-object.js +16 -9
- package/dist/esm/rules/use-tokens-typography/utils.js +9 -9
- package/dist/types/rules/use-tokens-typography/config/index.d.ts +1 -0
- package/dist/types/rules/use-tokens-typography/transformers/style-object.d.ts +6 -2
- package/dist/types/rules/use-tokens-typography/utils.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-tokens-typography/config/index.d.ts +1 -0
- package/dist/types-ts4.5/rules/use-tokens-typography/transformers/style-object.d.ts +6 -2
- package/dist/types-ts4.5/rules/use-tokens-typography/utils.d.ts +1 -1
- package/package.json +8 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 9.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#91506](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/91506) [`2724a3783955`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/2724a3783955) - Add support for React 18.
|
|
8
|
+
|
|
9
|
+
## 9.4.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#90125](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/90125) [`3ee5bf94b4fd`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3ee5bf94b4fd) - Added the `shouldEnforceFallbacks` option to the `use-tokens-typography` rule which can be used to prevent token fallback values being added automatically.
|
|
14
|
+
|
|
3
15
|
## 9.4.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -36,7 +36,11 @@ css({
|
|
|
36
36
|
```js
|
|
37
37
|
import { token } from '@atlaskit/tokens';
|
|
38
38
|
|
|
39
|
-
css({
|
|
39
|
+
css({ font: token('font.heading.large') });
|
|
40
40
|
|
|
41
|
-
css({
|
|
41
|
+
css({ font: token('font.body') });
|
|
42
42
|
```
|
|
43
|
+
|
|
44
|
+
## Options
|
|
45
|
+
|
|
46
|
+
`shouldEnforceFallbacks`: Set to `false` to ensure token fallback values are not added. Defaults to `true`.
|
|
@@ -11,12 +11,16 @@ var ruleSchema = exports.ruleSchema = {
|
|
|
11
11
|
properties: {
|
|
12
12
|
failSilently: {
|
|
13
13
|
type: 'boolean'
|
|
14
|
+
},
|
|
15
|
+
shouldEnforceFallbacks: {
|
|
16
|
+
type: 'boolean'
|
|
14
17
|
}
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
};
|
|
18
21
|
var defaultConfig = {
|
|
19
|
-
failSilently: false
|
|
22
|
+
failSilently: false,
|
|
23
|
+
shouldEnforceFallbacks: true
|
|
20
24
|
};
|
|
21
25
|
var getConfig = exports.getConfig = function getConfig(overrides) {
|
|
22
26
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
|
|
@@ -15,7 +15,8 @@ var create = function create(context) {
|
|
|
15
15
|
ObjectExpression: function ObjectExpression(node) {
|
|
16
16
|
return (0, _errorBoundary.errorBoundary)(function () {
|
|
17
17
|
return _styleObject.StyleObject.lint(node, {
|
|
18
|
-
context: context
|
|
18
|
+
context: context,
|
|
19
|
+
config: config
|
|
19
20
|
});
|
|
20
21
|
}, {
|
|
21
22
|
config: config
|
|
@@ -13,7 +13,8 @@ var _utils2 = require("../utils");
|
|
|
13
13
|
|
|
14
14
|
var StyleObject = exports.StyleObject = {
|
|
15
15
|
lint: function lint(node, _ref) {
|
|
16
|
-
var context = _ref.context
|
|
16
|
+
var context = _ref.context,
|
|
17
|
+
config = _ref.config;
|
|
17
18
|
// To force the correct node type
|
|
18
19
|
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'ObjectExpression')) {
|
|
19
20
|
return {
|
|
@@ -23,7 +24,8 @@ var StyleObject = exports.StyleObject = {
|
|
|
23
24
|
|
|
24
25
|
// Check whether all criteria needed to make a transformation are met
|
|
25
26
|
var _StyleObject$_check = StyleObject._check(node, {
|
|
26
|
-
context: context
|
|
27
|
+
context: context,
|
|
28
|
+
config: config
|
|
27
29
|
}),
|
|
28
30
|
success = _StyleObject$_check.success,
|
|
29
31
|
refs = _StyleObject$_check.refs;
|
|
@@ -34,6 +36,7 @@ var StyleObject = exports.StyleObject = {
|
|
|
34
36
|
fontSizeRaw = refs.fontSizeRaw,
|
|
35
37
|
tokensImportNode = refs.tokensImportNode,
|
|
36
38
|
themeImportNode = refs.themeImportNode,
|
|
39
|
+
shouldAddFallback = refs.shouldAddFallback,
|
|
37
40
|
shouldAddFallbackImport = refs.shouldAddFallbackImport;
|
|
38
41
|
var fontSizeValue = (0, _utils.normaliseValue)('fontSize', fontSizeRaw);
|
|
39
42
|
|
|
@@ -116,16 +119,17 @@ var StyleObject = exports.StyleObject = {
|
|
|
116
119
|
var nodesToReplace = [fontSizeNode, fontWeightNode, lineHeightNode, fontFamilyNode, fontStyleNode, letterSpacingNode].filter(_utils2.notUndefined);
|
|
117
120
|
var fontFamilyTokenName = fontFamilyToAdd ? "font.family.brand.".concat(fontFamilyToAdd) : '';
|
|
118
121
|
var fontWeightReplacementToken = shouldAddFontWeight ? (0, _utils2.findFontWeightTokenForValue)(fontWeightValue) : undefined;
|
|
119
|
-
var fontWeightReplacement = fontWeightReplacementToken && (0, _utils2.getTokenProperty)('fontWeight', fontWeightReplacementToken.tokenName, fontWeightValue);
|
|
122
|
+
var fontWeightReplacement = fontWeightReplacementToken && (0, _utils2.getTokenProperty)('fontWeight', fontWeightReplacementToken.tokenName, shouldAddFallback ? fontWeightValue : undefined);
|
|
120
123
|
var fontFamilyReplacement = fontFamilyToAdd && (fontFamilyToAdd === 'original' ? (0, _utils2.convertPropertyNodeToStringableNode)(
|
|
121
124
|
// This will always exist if fontFamilyToAdd === 'original', TS can't figure that out.
|
|
122
|
-
fontFamilyNode) : (0, _utils2.getTokenProperty)('fontFamily', fontFamilyTokenName, (0, _utils2.findFontFamilyValueForToken)(fontFamilyTokenName)));
|
|
125
|
+
fontFamilyNode) : (0, _utils2.getTokenProperty)('fontFamily', fontFamilyTokenName, shouldAddFallback ? (0, _utils2.findFontFamilyValueForToken)(fontFamilyTokenName) : undefined));
|
|
123
126
|
var fontStyleReplacement = fontStyleToAdd && (0, _utils2.getLiteralProperty)('fontStyle', fontStyleToAdd);
|
|
124
127
|
var fixerRefs = {
|
|
125
128
|
matchingToken: matchingToken,
|
|
126
129
|
nodesToReplace: nodesToReplace,
|
|
127
130
|
tokensImportNode: tokensImportNode,
|
|
128
131
|
themeImportNode: themeImportNode,
|
|
132
|
+
shouldAddFallback: shouldAddFallback,
|
|
129
133
|
shouldAddFallbackImport: shouldAddFallbackImport,
|
|
130
134
|
fontWeightReplacement: fontWeightReplacement,
|
|
131
135
|
fontFamilyReplacement: fontFamilyReplacement,
|
|
@@ -151,7 +155,8 @@ var StyleObject = exports.StyleObject = {
|
|
|
151
155
|
return;
|
|
152
156
|
},
|
|
153
157
|
_check: function _check(node, _ref2) {
|
|
154
|
-
var context = _ref2.context
|
|
158
|
+
var context = _ref2.context,
|
|
159
|
+
config = _ref2.config;
|
|
155
160
|
if (!(0, _isNode.isDecendantOfStyleBlock)(node) && !(0, _isNode.isDecendantOfType)(node, 'JSXExpressionContainer')) {
|
|
156
161
|
return {
|
|
157
162
|
success: false
|
|
@@ -181,13 +186,13 @@ var StyleObject = exports.StyleObject = {
|
|
|
181
186
|
success: false
|
|
182
187
|
};
|
|
183
188
|
}
|
|
184
|
-
|
|
189
|
+
var shouldAddFallback = Boolean(config.shouldEnforceFallbacks);
|
|
185
190
|
// This exists purely because we're not inlining the fallback values
|
|
186
191
|
// and instead referencing a `fontFallback` object that exists in @atlaskit/theme/typography.
|
|
187
192
|
// This is a temporary measure until fallbacks are no longer required
|
|
188
|
-
var shouldAddFallbackImport = 'full';
|
|
193
|
+
var shouldAddFallbackImport = shouldAddFallback && 'full';
|
|
189
194
|
var themeImportDeclaration = _astNodes.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/theme/typography');
|
|
190
|
-
if (themeImportDeclaration.length) {
|
|
195
|
+
if (themeImportDeclaration.length && shouldAddFallback) {
|
|
191
196
|
// Import exists, check if specifier exists
|
|
192
197
|
shouldAddFallbackImport = 'specifier';
|
|
193
198
|
var fallbackImport = themeImportDeclaration[0].specifiers.find(function (specifier) {
|
|
@@ -213,6 +218,7 @@ var StyleObject = exports.StyleObject = {
|
|
|
213
218
|
fontSizeRaw: fontSizeRaw,
|
|
214
219
|
tokensImportNode: tokensImportDeclaration[0],
|
|
215
220
|
themeImportNode: themeImportDeclaration[0],
|
|
221
|
+
shouldAddFallback: shouldAddFallback,
|
|
216
222
|
shouldAddFallbackImport: shouldAddFallbackImport
|
|
217
223
|
}
|
|
218
224
|
};
|
|
@@ -223,6 +229,7 @@ var StyleObject = exports.StyleObject = {
|
|
|
223
229
|
nodesToReplace = refs.nodesToReplace,
|
|
224
230
|
tokensImportNode = refs.tokensImportNode,
|
|
225
231
|
themeImportNode = refs.themeImportNode,
|
|
232
|
+
shouldAddFallback = refs.shouldAddFallback,
|
|
226
233
|
shouldAddFallbackImport = refs.shouldAddFallbackImport,
|
|
227
234
|
fontWeightReplacement = refs.fontWeightReplacement,
|
|
228
235
|
fontFamilyReplacement = refs.fontFamilyReplacement,
|
|
@@ -239,7 +246,7 @@ var StyleObject = exports.StyleObject = {
|
|
|
239
246
|
return (!tokensImportNode ? [(0, _utils2.insertTokensImport)(root, fixer)] : []).concat(fallbackImport ? [fallbackImport] : [], nodesToReplace.map(function (node, index) {
|
|
240
247
|
// Replace first node with token, delete remaining nodes. Guaranteed to be fontSize
|
|
241
248
|
if (index === 0) {
|
|
242
|
-
return fixer.replaceText(node, "".concat((0, _utils2.getTokenProperty)('font', matchingToken.tokenName, fallbackName, true)));
|
|
249
|
+
return fixer.replaceText(node, "".concat((0, _utils2.getTokenProperty)('font', matchingToken.tokenName, shouldAddFallback ? fallbackName : undefined, true)));
|
|
243
250
|
}
|
|
244
251
|
|
|
245
252
|
// We don't replace fontWeight/fontFamily/fontStyle here in case it occurs before the font property.
|
|
@@ -119,20 +119,20 @@ function isValidPropertyNode(node) {
|
|
|
119
119
|
}
|
|
120
120
|
return true;
|
|
121
121
|
}
|
|
122
|
-
function getTokenNode(tokenName,
|
|
123
|
-
var
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
122
|
+
function getTokenNode(tokenName, fallbackValue) {
|
|
123
|
+
var isFallbackMember = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
124
|
+
var callExpressionArgs = [(0, _eslintCodemodUtils.literal)({
|
|
125
|
+
value: "'".concat(tokenName, "'")
|
|
126
|
+
})];
|
|
127
|
+
if (fallbackValue) {
|
|
128
|
+
var fallback = isFallbackMember ? createMemberExpressionFromArray(fallbackValue.split('.')) : (0, _eslintCodemodUtils.literal)(fallbackValue);
|
|
129
|
+
callExpressionArgs.push(fallback);
|
|
128
130
|
}
|
|
129
131
|
return (0, _eslintCodemodUtils.callExpression)({
|
|
130
132
|
callee: (0, _eslintCodemodUtils.identifier)({
|
|
131
133
|
name: 'token'
|
|
132
134
|
}),
|
|
133
|
-
arguments:
|
|
134
|
-
value: "'".concat(tokenName, "'")
|
|
135
|
-
}), fallback],
|
|
135
|
+
arguments: callExpressionArgs,
|
|
136
136
|
optional: false
|
|
137
137
|
});
|
|
138
138
|
}
|
|
@@ -5,12 +5,16 @@ export const ruleSchema = {
|
|
|
5
5
|
properties: {
|
|
6
6
|
failSilently: {
|
|
7
7
|
type: 'boolean'
|
|
8
|
+
},
|
|
9
|
+
shouldEnforceFallbacks: {
|
|
10
|
+
type: 'boolean'
|
|
8
11
|
}
|
|
9
12
|
}
|
|
10
13
|
}
|
|
11
14
|
};
|
|
12
15
|
const defaultConfig = {
|
|
13
|
-
failSilently: false
|
|
16
|
+
failSilently: false,
|
|
17
|
+
shouldEnforceFallbacks: true
|
|
14
18
|
};
|
|
15
19
|
export const getConfig = overrides => {
|
|
16
20
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
|
|
@@ -7,7 +7,8 @@ import { isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfType }
|
|
|
7
7
|
import { convertPropertyNodeToStringableNode, defaultFontWeight, findFontFamilyValueForToken, findFontWeightTokenForValue, findTypographyTokenForValues, fontWeightMap, getLiteralProperty, getTokenProperty, insertFallbackImportFull, insertFallbackImportSpecifier, insertTokensImport, isValidPropertyNode, notUndefined } from '../utils';
|
|
8
8
|
export const StyleObject = {
|
|
9
9
|
lint(node, {
|
|
10
|
-
context
|
|
10
|
+
context,
|
|
11
|
+
config
|
|
11
12
|
}) {
|
|
12
13
|
// To force the correct node type
|
|
13
14
|
if (!isNodeOfType(node, 'ObjectExpression')) {
|
|
@@ -21,7 +22,8 @@ export const StyleObject = {
|
|
|
21
22
|
success,
|
|
22
23
|
refs
|
|
23
24
|
} = StyleObject._check(node, {
|
|
24
|
-
context
|
|
25
|
+
context,
|
|
26
|
+
config
|
|
25
27
|
});
|
|
26
28
|
if (!success || !refs) {
|
|
27
29
|
return;
|
|
@@ -31,6 +33,7 @@ export const StyleObject = {
|
|
|
31
33
|
fontSizeRaw,
|
|
32
34
|
tokensImportNode,
|
|
33
35
|
themeImportNode,
|
|
36
|
+
shouldAddFallback,
|
|
34
37
|
shouldAddFallbackImport
|
|
35
38
|
} = refs;
|
|
36
39
|
const fontSizeValue = normaliseValue('fontSize', fontSizeRaw);
|
|
@@ -110,16 +113,17 @@ export const StyleObject = {
|
|
|
110
113
|
const nodesToReplace = [fontSizeNode, fontWeightNode, lineHeightNode, fontFamilyNode, fontStyleNode, letterSpacingNode].filter(notUndefined);
|
|
111
114
|
const fontFamilyTokenName = fontFamilyToAdd ? `font.family.brand.${fontFamilyToAdd}` : '';
|
|
112
115
|
const fontWeightReplacementToken = shouldAddFontWeight ? findFontWeightTokenForValue(fontWeightValue) : undefined;
|
|
113
|
-
const fontWeightReplacement = fontWeightReplacementToken && getTokenProperty('fontWeight', fontWeightReplacementToken.tokenName, fontWeightValue);
|
|
116
|
+
const fontWeightReplacement = fontWeightReplacementToken && getTokenProperty('fontWeight', fontWeightReplacementToken.tokenName, shouldAddFallback ? fontWeightValue : undefined);
|
|
114
117
|
const fontFamilyReplacement = fontFamilyToAdd && (fontFamilyToAdd === 'original' ? convertPropertyNodeToStringableNode(
|
|
115
118
|
// This will always exist if fontFamilyToAdd === 'original', TS can't figure that out.
|
|
116
|
-
fontFamilyNode) : getTokenProperty('fontFamily', fontFamilyTokenName, findFontFamilyValueForToken(fontFamilyTokenName)));
|
|
119
|
+
fontFamilyNode) : getTokenProperty('fontFamily', fontFamilyTokenName, shouldAddFallback ? findFontFamilyValueForToken(fontFamilyTokenName) : undefined));
|
|
117
120
|
const fontStyleReplacement = fontStyleToAdd && getLiteralProperty('fontStyle', fontStyleToAdd);
|
|
118
121
|
const fixerRefs = {
|
|
119
122
|
matchingToken,
|
|
120
123
|
nodesToReplace,
|
|
121
124
|
tokensImportNode,
|
|
122
125
|
themeImportNode,
|
|
126
|
+
shouldAddFallback,
|
|
123
127
|
shouldAddFallbackImport,
|
|
124
128
|
fontWeightReplacement,
|
|
125
129
|
fontFamilyReplacement,
|
|
@@ -145,7 +149,8 @@ export const StyleObject = {
|
|
|
145
149
|
return;
|
|
146
150
|
},
|
|
147
151
|
_check(node, {
|
|
148
|
-
context
|
|
152
|
+
context,
|
|
153
|
+
config
|
|
149
154
|
}) {
|
|
150
155
|
if (!isDecendantOfStyleBlock(node) && !isDecendantOfType(node, 'JSXExpressionContainer')) {
|
|
151
156
|
return {
|
|
@@ -176,13 +181,13 @@ export const StyleObject = {
|
|
|
176
181
|
success: false
|
|
177
182
|
};
|
|
178
183
|
}
|
|
179
|
-
|
|
184
|
+
const shouldAddFallback = Boolean(config.shouldEnforceFallbacks);
|
|
180
185
|
// This exists purely because we're not inlining the fallback values
|
|
181
186
|
// and instead referencing a `fontFallback` object that exists in @atlaskit/theme/typography.
|
|
182
187
|
// This is a temporary measure until fallbacks are no longer required
|
|
183
|
-
let shouldAddFallbackImport = 'full';
|
|
188
|
+
let shouldAddFallbackImport = shouldAddFallback && 'full';
|
|
184
189
|
const themeImportDeclaration = Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/theme/typography');
|
|
185
|
-
if (themeImportDeclaration.length) {
|
|
190
|
+
if (themeImportDeclaration.length && shouldAddFallback) {
|
|
186
191
|
// Import exists, check if specifier exists
|
|
187
192
|
shouldAddFallbackImport = 'specifier';
|
|
188
193
|
const fallbackImport = themeImportDeclaration[0].specifiers.find(specifier => {
|
|
@@ -208,6 +213,7 @@ export const StyleObject = {
|
|
|
208
213
|
fontSizeRaw,
|
|
209
214
|
tokensImportNode: tokensImportDeclaration[0],
|
|
210
215
|
themeImportNode: themeImportDeclaration[0],
|
|
216
|
+
shouldAddFallback,
|
|
211
217
|
shouldAddFallbackImport
|
|
212
218
|
}
|
|
213
219
|
};
|
|
@@ -219,6 +225,7 @@ export const StyleObject = {
|
|
|
219
225
|
nodesToReplace,
|
|
220
226
|
tokensImportNode,
|
|
221
227
|
themeImportNode,
|
|
228
|
+
shouldAddFallback,
|
|
222
229
|
shouldAddFallbackImport,
|
|
223
230
|
fontWeightReplacement,
|
|
224
231
|
fontFamilyReplacement,
|
|
@@ -236,7 +243,7 @@ export const StyleObject = {
|
|
|
236
243
|
return (!tokensImportNode ? [insertTokensImport(root, fixer)] : []).concat(fallbackImport ? [fallbackImport] : [], nodesToReplace.map((node, index) => {
|
|
237
244
|
// Replace first node with token, delete remaining nodes. Guaranteed to be fontSize
|
|
238
245
|
if (index === 0) {
|
|
239
|
-
return fixer.replaceText(node, `${getTokenProperty('font', matchingToken.tokenName, fallbackName, true)}`);
|
|
246
|
+
return fixer.replaceText(node, `${getTokenProperty('font', matchingToken.tokenName, shouldAddFallback ? fallbackName : undefined, true)}`);
|
|
240
247
|
}
|
|
241
248
|
|
|
242
249
|
// We don't replace fontWeight/fontFamily/fontStyle here in case it occurs before the font property.
|
|
@@ -69,20 +69,19 @@ export function isValidPropertyNode(node) {
|
|
|
69
69
|
}
|
|
70
70
|
return true;
|
|
71
71
|
}
|
|
72
|
-
function getTokenNode(tokenName,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
fallback = literal(
|
|
72
|
+
function getTokenNode(tokenName, fallbackValue, isFallbackMember = false) {
|
|
73
|
+
const callExpressionArgs = [literal({
|
|
74
|
+
value: `'${tokenName}'`
|
|
75
|
+
})];
|
|
76
|
+
if (fallbackValue) {
|
|
77
|
+
const fallback = isFallbackMember ? createMemberExpressionFromArray(fallbackValue.split('.')) : literal(fallbackValue);
|
|
78
|
+
callExpressionArgs.push(fallback);
|
|
78
79
|
}
|
|
79
80
|
return callExpression({
|
|
80
81
|
callee: identifier({
|
|
81
82
|
name: 'token'
|
|
82
83
|
}),
|
|
83
|
-
arguments:
|
|
84
|
-
value: `'${tokenName}'`
|
|
85
|
-
}), fallback],
|
|
84
|
+
arguments: callExpressionArgs,
|
|
86
85
|
optional: false
|
|
87
86
|
});
|
|
88
87
|
}
|
|
@@ -5,12 +5,16 @@ export var ruleSchema = {
|
|
|
5
5
|
properties: {
|
|
6
6
|
failSilently: {
|
|
7
7
|
type: 'boolean'
|
|
8
|
+
},
|
|
9
|
+
shouldEnforceFallbacks: {
|
|
10
|
+
type: 'boolean'
|
|
8
11
|
}
|
|
9
12
|
}
|
|
10
13
|
}
|
|
11
14
|
};
|
|
12
15
|
var defaultConfig = {
|
|
13
|
-
failSilently: false
|
|
16
|
+
failSilently: false,
|
|
17
|
+
shouldEnforceFallbacks: true
|
|
14
18
|
};
|
|
15
19
|
export var getConfig = function getConfig(overrides) {
|
|
16
20
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
|
|
@@ -7,7 +7,8 @@ import { isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfType }
|
|
|
7
7
|
import { convertPropertyNodeToStringableNode, defaultFontWeight, findFontFamilyValueForToken, findFontWeightTokenForValue, findTypographyTokenForValues, fontWeightMap, getLiteralProperty, getTokenProperty, insertFallbackImportFull, insertFallbackImportSpecifier, insertTokensImport, isValidPropertyNode, notUndefined } from '../utils';
|
|
8
8
|
export var StyleObject = {
|
|
9
9
|
lint: function lint(node, _ref) {
|
|
10
|
-
var context = _ref.context
|
|
10
|
+
var context = _ref.context,
|
|
11
|
+
config = _ref.config;
|
|
11
12
|
// To force the correct node type
|
|
12
13
|
if (!isNodeOfType(node, 'ObjectExpression')) {
|
|
13
14
|
return {
|
|
@@ -17,7 +18,8 @@ export var StyleObject = {
|
|
|
17
18
|
|
|
18
19
|
// Check whether all criteria needed to make a transformation are met
|
|
19
20
|
var _StyleObject$_check = StyleObject._check(node, {
|
|
20
|
-
context: context
|
|
21
|
+
context: context,
|
|
22
|
+
config: config
|
|
21
23
|
}),
|
|
22
24
|
success = _StyleObject$_check.success,
|
|
23
25
|
refs = _StyleObject$_check.refs;
|
|
@@ -28,6 +30,7 @@ export var StyleObject = {
|
|
|
28
30
|
fontSizeRaw = refs.fontSizeRaw,
|
|
29
31
|
tokensImportNode = refs.tokensImportNode,
|
|
30
32
|
themeImportNode = refs.themeImportNode,
|
|
33
|
+
shouldAddFallback = refs.shouldAddFallback,
|
|
31
34
|
shouldAddFallbackImport = refs.shouldAddFallbackImport;
|
|
32
35
|
var fontSizeValue = normaliseValue('fontSize', fontSizeRaw);
|
|
33
36
|
|
|
@@ -110,16 +113,17 @@ export var StyleObject = {
|
|
|
110
113
|
var nodesToReplace = [fontSizeNode, fontWeightNode, lineHeightNode, fontFamilyNode, fontStyleNode, letterSpacingNode].filter(notUndefined);
|
|
111
114
|
var fontFamilyTokenName = fontFamilyToAdd ? "font.family.brand.".concat(fontFamilyToAdd) : '';
|
|
112
115
|
var fontWeightReplacementToken = shouldAddFontWeight ? findFontWeightTokenForValue(fontWeightValue) : undefined;
|
|
113
|
-
var fontWeightReplacement = fontWeightReplacementToken && getTokenProperty('fontWeight', fontWeightReplacementToken.tokenName, fontWeightValue);
|
|
116
|
+
var fontWeightReplacement = fontWeightReplacementToken && getTokenProperty('fontWeight', fontWeightReplacementToken.tokenName, shouldAddFallback ? fontWeightValue : undefined);
|
|
114
117
|
var fontFamilyReplacement = fontFamilyToAdd && (fontFamilyToAdd === 'original' ? convertPropertyNodeToStringableNode(
|
|
115
118
|
// This will always exist if fontFamilyToAdd === 'original', TS can't figure that out.
|
|
116
|
-
fontFamilyNode) : getTokenProperty('fontFamily', fontFamilyTokenName, findFontFamilyValueForToken(fontFamilyTokenName)));
|
|
119
|
+
fontFamilyNode) : getTokenProperty('fontFamily', fontFamilyTokenName, shouldAddFallback ? findFontFamilyValueForToken(fontFamilyTokenName) : undefined));
|
|
117
120
|
var fontStyleReplacement = fontStyleToAdd && getLiteralProperty('fontStyle', fontStyleToAdd);
|
|
118
121
|
var fixerRefs = {
|
|
119
122
|
matchingToken: matchingToken,
|
|
120
123
|
nodesToReplace: nodesToReplace,
|
|
121
124
|
tokensImportNode: tokensImportNode,
|
|
122
125
|
themeImportNode: themeImportNode,
|
|
126
|
+
shouldAddFallback: shouldAddFallback,
|
|
123
127
|
shouldAddFallbackImport: shouldAddFallbackImport,
|
|
124
128
|
fontWeightReplacement: fontWeightReplacement,
|
|
125
129
|
fontFamilyReplacement: fontFamilyReplacement,
|
|
@@ -145,7 +149,8 @@ export var StyleObject = {
|
|
|
145
149
|
return;
|
|
146
150
|
},
|
|
147
151
|
_check: function _check(node, _ref2) {
|
|
148
|
-
var context = _ref2.context
|
|
152
|
+
var context = _ref2.context,
|
|
153
|
+
config = _ref2.config;
|
|
149
154
|
if (!isDecendantOfStyleBlock(node) && !isDecendantOfType(node, 'JSXExpressionContainer')) {
|
|
150
155
|
return {
|
|
151
156
|
success: false
|
|
@@ -175,13 +180,13 @@ export var StyleObject = {
|
|
|
175
180
|
success: false
|
|
176
181
|
};
|
|
177
182
|
}
|
|
178
|
-
|
|
183
|
+
var shouldAddFallback = Boolean(config.shouldEnforceFallbacks);
|
|
179
184
|
// This exists purely because we're not inlining the fallback values
|
|
180
185
|
// and instead referencing a `fontFallback` object that exists in @atlaskit/theme/typography.
|
|
181
186
|
// This is a temporary measure until fallbacks are no longer required
|
|
182
|
-
var shouldAddFallbackImport = 'full';
|
|
187
|
+
var shouldAddFallbackImport = shouldAddFallback && 'full';
|
|
183
188
|
var themeImportDeclaration = Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/theme/typography');
|
|
184
|
-
if (themeImportDeclaration.length) {
|
|
189
|
+
if (themeImportDeclaration.length && shouldAddFallback) {
|
|
185
190
|
// Import exists, check if specifier exists
|
|
186
191
|
shouldAddFallbackImport = 'specifier';
|
|
187
192
|
var fallbackImport = themeImportDeclaration[0].specifiers.find(function (specifier) {
|
|
@@ -207,6 +212,7 @@ export var StyleObject = {
|
|
|
207
212
|
fontSizeRaw: fontSizeRaw,
|
|
208
213
|
tokensImportNode: tokensImportDeclaration[0],
|
|
209
214
|
themeImportNode: themeImportDeclaration[0],
|
|
215
|
+
shouldAddFallback: shouldAddFallback,
|
|
210
216
|
shouldAddFallbackImport: shouldAddFallbackImport
|
|
211
217
|
}
|
|
212
218
|
};
|
|
@@ -217,6 +223,7 @@ export var StyleObject = {
|
|
|
217
223
|
nodesToReplace = refs.nodesToReplace,
|
|
218
224
|
tokensImportNode = refs.tokensImportNode,
|
|
219
225
|
themeImportNode = refs.themeImportNode,
|
|
226
|
+
shouldAddFallback = refs.shouldAddFallback,
|
|
220
227
|
shouldAddFallbackImport = refs.shouldAddFallbackImport,
|
|
221
228
|
fontWeightReplacement = refs.fontWeightReplacement,
|
|
222
229
|
fontFamilyReplacement = refs.fontFamilyReplacement,
|
|
@@ -233,7 +240,7 @@ export var StyleObject = {
|
|
|
233
240
|
return (!tokensImportNode ? [insertTokensImport(root, fixer)] : []).concat(fallbackImport ? [fallbackImport] : [], nodesToReplace.map(function (node, index) {
|
|
234
241
|
// Replace first node with token, delete remaining nodes. Guaranteed to be fontSize
|
|
235
242
|
if (index === 0) {
|
|
236
|
-
return fixer.replaceText(node, "".concat(getTokenProperty('font', matchingToken.tokenName, fallbackName, true)));
|
|
243
|
+
return fixer.replaceText(node, "".concat(getTokenProperty('font', matchingToken.tokenName, shouldAddFallback ? fallbackName : undefined, true)));
|
|
237
244
|
}
|
|
238
245
|
|
|
239
246
|
// We don't replace fontWeight/fontFamily/fontStyle here in case it occurs before the font property.
|
|
@@ -99,20 +99,20 @@ export function isValidPropertyNode(node) {
|
|
|
99
99
|
}
|
|
100
100
|
return true;
|
|
101
101
|
}
|
|
102
|
-
function getTokenNode(tokenName,
|
|
103
|
-
var
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
102
|
+
function getTokenNode(tokenName, fallbackValue) {
|
|
103
|
+
var isFallbackMember = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
104
|
+
var callExpressionArgs = [literal({
|
|
105
|
+
value: "'".concat(tokenName, "'")
|
|
106
|
+
})];
|
|
107
|
+
if (fallbackValue) {
|
|
108
|
+
var fallback = isFallbackMember ? createMemberExpressionFromArray(fallbackValue.split('.')) : literal(fallbackValue);
|
|
109
|
+
callExpressionArgs.push(fallback);
|
|
108
110
|
}
|
|
109
111
|
return callExpression({
|
|
110
112
|
callee: identifier({
|
|
111
113
|
name: 'token'
|
|
112
114
|
}),
|
|
113
|
-
arguments:
|
|
114
|
-
value: "'".concat(tokenName, "'")
|
|
115
|
-
}), fallback],
|
|
115
|
+
arguments: callExpressionArgs,
|
|
116
116
|
optional: false
|
|
117
117
|
});
|
|
118
118
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
|
|
2
2
|
export type RuleConfig = {
|
|
3
3
|
failSilently?: boolean;
|
|
4
|
+
shouldEnforceFallbacks?: boolean;
|
|
4
5
|
};
|
|
5
6
|
export declare const ruleSchema: JSONSchema4;
|
|
6
7
|
export declare const getConfig: (overrides: RuleConfig) => RuleConfig;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
2
|
import { ImportDeclaration, ObjectExpression, Property, StringableASTNode } from 'eslint-codemod-utils';
|
|
3
|
+
import { RuleConfig } from '../config';
|
|
3
4
|
import { TokenValueMap } from '../utils';
|
|
4
5
|
interface MetaData {
|
|
5
6
|
context: Rule.RuleContext;
|
|
7
|
+
config: RuleConfig;
|
|
6
8
|
}
|
|
7
9
|
interface Refs {
|
|
8
10
|
fontSizeNode: Property;
|
|
9
11
|
fontSizeRaw: string | number;
|
|
10
12
|
tokensImportNode: ImportDeclaration | undefined;
|
|
11
13
|
themeImportNode: ImportDeclaration | undefined;
|
|
14
|
+
shouldAddFallback: boolean;
|
|
12
15
|
shouldAddFallbackImport: 'full' | 'specifier' | false;
|
|
13
16
|
}
|
|
14
17
|
type Check = {
|
|
@@ -20,16 +23,17 @@ interface FixerRefs {
|
|
|
20
23
|
nodesToReplace: Property[];
|
|
21
24
|
tokensImportNode: ImportDeclaration | undefined;
|
|
22
25
|
themeImportNode: ImportDeclaration | undefined;
|
|
26
|
+
shouldAddFallback: boolean;
|
|
23
27
|
shouldAddFallbackImport: Refs['shouldAddFallbackImport'];
|
|
24
28
|
fontWeightReplacement: StringableASTNode<Property> | undefined;
|
|
25
29
|
fontFamilyReplacement: StringableASTNode<Property> | undefined;
|
|
26
30
|
fontStyleReplacement: StringableASTNode<Property> | undefined;
|
|
27
31
|
}
|
|
28
32
|
export declare const StyleObject: {
|
|
29
|
-
lint(node: Rule.Node, { context }: MetaData): {
|
|
33
|
+
lint(node: Rule.Node, { context, config }: MetaData): {
|
|
30
34
|
success: boolean;
|
|
31
35
|
} | undefined;
|
|
32
|
-
_check(node: ObjectExpression & Rule.NodeParentExtension, { context }: MetaData): Check;
|
|
36
|
+
_check(node: ObjectExpression & Rule.NodeParentExtension, { context, config }: MetaData): Check;
|
|
33
37
|
_fix(refs: FixerRefs, context: Rule.RuleContext): (fixer: Rule.RuleFixer) => Rule.Fix[];
|
|
34
38
|
};
|
|
35
39
|
export {};
|
|
@@ -190,7 +190,7 @@ export declare const fontFamilyTokens: ({
|
|
|
190
190
|
export declare function findFontFamilyValueForToken(tokenName: string): string;
|
|
191
191
|
export declare function notUndefined<V>(value: V | undefined): value is V;
|
|
192
192
|
export declare function isValidPropertyNode(node: Property): boolean;
|
|
193
|
-
export declare function getTokenProperty(propertyName: string, tokenName: string, tokenFallback
|
|
193
|
+
export declare function getTokenProperty(propertyName: string, tokenName: string, tokenFallback?: string, isFallbackMember?: boolean): StringableASTNode<Property>;
|
|
194
194
|
export declare function getLiteralProperty(propertyName: string, propertyValue: string): StringableASTNode<Property>;
|
|
195
195
|
export declare function convertPropertyNodeToStringableNode(node: Property): StringableASTNode<Property>;
|
|
196
196
|
export declare function insertTokensImport(root: (Directive | Statement | ModuleDeclaration)[], fixer: Rule.RuleFixer): Rule.Fix;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
|
|
2
2
|
export type RuleConfig = {
|
|
3
3
|
failSilently?: boolean;
|
|
4
|
+
shouldEnforceFallbacks?: boolean;
|
|
4
5
|
};
|
|
5
6
|
export declare const ruleSchema: JSONSchema4;
|
|
6
7
|
export declare const getConfig: (overrides: RuleConfig) => RuleConfig;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
2
|
import { ImportDeclaration, ObjectExpression, Property, StringableASTNode } from 'eslint-codemod-utils';
|
|
3
|
+
import { RuleConfig } from '../config';
|
|
3
4
|
import { TokenValueMap } from '../utils';
|
|
4
5
|
interface MetaData {
|
|
5
6
|
context: Rule.RuleContext;
|
|
7
|
+
config: RuleConfig;
|
|
6
8
|
}
|
|
7
9
|
interface Refs {
|
|
8
10
|
fontSizeNode: Property;
|
|
9
11
|
fontSizeRaw: string | number;
|
|
10
12
|
tokensImportNode: ImportDeclaration | undefined;
|
|
11
13
|
themeImportNode: ImportDeclaration | undefined;
|
|
14
|
+
shouldAddFallback: boolean;
|
|
12
15
|
shouldAddFallbackImport: 'full' | 'specifier' | false;
|
|
13
16
|
}
|
|
14
17
|
type Check = {
|
|
@@ -20,16 +23,17 @@ interface FixerRefs {
|
|
|
20
23
|
nodesToReplace: Property[];
|
|
21
24
|
tokensImportNode: ImportDeclaration | undefined;
|
|
22
25
|
themeImportNode: ImportDeclaration | undefined;
|
|
26
|
+
shouldAddFallback: boolean;
|
|
23
27
|
shouldAddFallbackImport: Refs['shouldAddFallbackImport'];
|
|
24
28
|
fontWeightReplacement: StringableASTNode<Property> | undefined;
|
|
25
29
|
fontFamilyReplacement: StringableASTNode<Property> | undefined;
|
|
26
30
|
fontStyleReplacement: StringableASTNode<Property> | undefined;
|
|
27
31
|
}
|
|
28
32
|
export declare const StyleObject: {
|
|
29
|
-
lint(node: Rule.Node, { context }: MetaData): {
|
|
33
|
+
lint(node: Rule.Node, { context, config }: MetaData): {
|
|
30
34
|
success: boolean;
|
|
31
35
|
} | undefined;
|
|
32
|
-
_check(node: ObjectExpression & Rule.NodeParentExtension, { context }: MetaData): Check;
|
|
36
|
+
_check(node: ObjectExpression & Rule.NodeParentExtension, { context, config }: MetaData): Check;
|
|
33
37
|
_fix(refs: FixerRefs, context: Rule.RuleContext): (fixer: Rule.RuleFixer) => Rule.Fix[];
|
|
34
38
|
};
|
|
35
39
|
export {};
|
|
@@ -190,7 +190,7 @@ export declare const fontFamilyTokens: ({
|
|
|
190
190
|
export declare function findFontFamilyValueForToken(tokenName: string): string;
|
|
191
191
|
export declare function notUndefined<V>(value: V | undefined): value is V;
|
|
192
192
|
export declare function isValidPropertyNode(node: Property): boolean;
|
|
193
|
-
export declare function getTokenProperty(propertyName: string, tokenName: string, tokenFallback
|
|
193
|
+
export declare function getTokenProperty(propertyName: string, tokenName: string, tokenFallback?: string, isFallbackMember?: boolean): StringableASTNode<Property>;
|
|
194
194
|
export declare function getLiteralProperty(propertyName: string, propertyValue: string): StringableASTNode<Property>;
|
|
195
195
|
export declare function convertPropertyNodeToStringableNode(node: Property): StringableASTNode<Property>;
|
|
196
196
|
export declare function insertTokensImport(root: (Directive | Statement | ModuleDeclaration)[], fixer: Rule.RuleFixer): Rule.Fix;
|
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": "9.
|
|
4
|
+
"version": "9.5.0",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"publishConfig": {
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"website": {
|
|
17
17
|
"name": "ESLint plugin",
|
|
18
18
|
"category": "Tooling"
|
|
19
|
-
}
|
|
19
|
+
},
|
|
20
|
+
"runReact18": true
|
|
20
21
|
},
|
|
21
22
|
"repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
|
|
22
23
|
"main": "dist/cjs/index.js",
|
|
@@ -36,8 +37,11 @@
|
|
|
36
37
|
"af:exports": {
|
|
37
38
|
".": "./src/index.tsx"
|
|
38
39
|
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": "^16.8.0 || ^17.0.0 || ~18.2.0"
|
|
42
|
+
},
|
|
39
43
|
"dependencies": {
|
|
40
|
-
"@atlaskit/eslint-utils": "^1.
|
|
44
|
+
"@atlaskit/eslint-utils": "^1.2.0",
|
|
41
45
|
"@atlaskit/tokens": "*",
|
|
42
46
|
"@babel/runtime": "^7.0.0",
|
|
43
47
|
"@typescript-eslint/utils": "^5.48.1",
|
|
@@ -49,7 +53,7 @@
|
|
|
49
53
|
"semver": "^7.5.2"
|
|
50
54
|
},
|
|
51
55
|
"devDependencies": {
|
|
52
|
-
"@atlaskit/ds-lib": "^2.
|
|
56
|
+
"@atlaskit/ds-lib": "^2.3.0",
|
|
53
57
|
"@atlaskit/theme": "^12.7.0",
|
|
54
58
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
55
59
|
"@atlassian/codegen": "*",
|