@atlaskit/eslint-plugin-design-system 4.13.1 → 4.13.3

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 4.13.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`4793b01cfcc`](https://bitbucket.org/atlassian/atlassian-frontend/commits/4793b01cfcc) - Add an optional `customTokens` configuration option for no-unsafe-design-token-usage
8
+
9
+ ## 4.13.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [`1a7a2c87797`](https://bitbucket.org/atlassian/atlassian-frontend/commits/1a7a2c87797) - @atlaskit/eslint-plugin-design-system now maps values to rem based tokens
14
+
3
15
  ## 4.13.1
4
16
 
5
17
  ### Patch Changes
@@ -23,11 +23,22 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
23
23
 
24
24
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
25
25
 
26
+ var pixelsToRems = function pixelsToRems(pixelValueString) {
27
+ var pixels = (0, _utils.removePixelSuffix)(pixelValueString);
28
+
29
+ if (pixels === '0' || pixels === 0) {
30
+ return pixels;
31
+ }
32
+
33
+ return "".concat(Number(pixels) / 16, "rem");
34
+ };
26
35
  /**
27
36
  * Currently we have a wide range of experimental spacing tokens that we are testing.
28
37
  * We only want transforms to apply to the stable scale values, not the rest.
29
38
  * This could be removed in the future.
30
39
  */
40
+
41
+
31
42
  var onlyScaleTokens = _spacingRaw.default.filter(function (token) {
32
43
  return token.name.startsWith('spacing.scale.');
33
44
  });
@@ -43,14 +54,14 @@ var spacingValueToToken = Object.fromEntries(onlyScaleTokens.map(function (token
43
54
  */
44
55
 
45
56
  function pixelValueToSpacingTokenNode(pixelValueString) {
46
- var _spacingValueToToken$;
47
-
57
+ var remValueString = pixelsToRems(pixelValueString);
58
+ var token = spacingValueToToken[remValueString];
48
59
  return (0, _eslintCodemodUtils.callExpression)({
49
60
  callee: (0, _eslintCodemodUtils.identifier)({
50
61
  name: 'token'
51
62
  }),
52
63
  arguments: [(0, _eslintCodemodUtils.literal)({
53
- value: "'".concat((_spacingValueToToken$ = spacingValueToToken[pixelValueString]) !== null && _spacingValueToToken$ !== void 0 ? _spacingValueToToken$ : '', "'")
64
+ value: "'".concat(token !== null && token !== void 0 ? token : '', "'")
54
65
  }), (0, _eslintCodemodUtils.literal)("'".concat(pixelValueString, "'"))],
55
66
  optional: false
56
67
  });
@@ -166,7 +177,8 @@ var rule = {
166
177
  }
167
178
 
168
179
  var pixelValueString = "".concat(pixelValue, "px");
169
- var tokenName = spacingValueToToken[pixelValueString];
180
+ var remValueString = pixelsToRems(pixelValueString);
181
+ var tokenName = spacingValueToToken[remValueString];
170
182
 
171
183
  if (!tokenName) {
172
184
  return null;
@@ -298,7 +310,8 @@ var rule = {
298
310
  var replacementValue = values.map(function (value) {
299
311
  var pixelValue = (0, _utils.emToPixels)(value, fontSize);
300
312
  var pixelValueString = "".concat(pixelValue, "px");
301
- var tokenName = spacingValueToToken[pixelValueString];
313
+ var remValueString = pixelsToRems(pixelValueString);
314
+ var tokenName = spacingValueToToken[remValueString];
302
315
 
303
316
  if (!tokenName) {
304
317
  return pixelValueString;
@@ -41,6 +41,7 @@ var rule = {
41
41
  },
42
42
  create: function create(context) {
43
43
  var config = context.options[0] || defaultConfig;
44
+ var UNSAFE_ignoreTokens = new Set(config.UNSAFE_ignoreTokens);
44
45
  return {
45
46
  'TaggedTemplateExpression[tag.name="css"],TaggedTemplateExpression[tag.object.name="styled"]': function TaggedTemplateExpressionTagNameCssTaggedTemplateExpressionTagObjectNameStyled(node) {
46
47
  if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'TaggedTemplateExpression')) {
@@ -182,7 +183,7 @@ var rule = {
182
183
  return;
183
184
  }
184
185
 
185
- if (typeof tokenKey !== 'string' || typeof tokenKey === 'string' && !_tokenNames.default[tokenKey]) {
186
+ if (typeof tokenKey !== 'string' || typeof tokenKey === 'string' && !_tokenNames.default[tokenKey] && !UNSAFE_ignoreTokens.has(tokenKey)) {
186
187
  context.report({
187
188
  messageId: 'invalidToken',
188
189
  node: node,
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
- "version": "4.13.1",
3
+ "version": "4.13.3",
4
4
  "sideEffects": false
5
5
  }
@@ -1,12 +1,24 @@
1
1
  import { callExpression, identifier, isNodeOfType, literal, node as nodeFn, property } from 'eslint-codemod-utils';
2
2
  import spacingScale from '@atlaskit/tokens/spacing-raw';
3
3
  import { isDecendantOfGlobalToken } from '../utils/is-node';
4
+ import { convertHyphenatedNameToCamelCase, emToPixels, findParentNodeForLine, getValue, getValueFromShorthand, isSpacingProperty, isValidSpacingValue, removePixelSuffix } from './utils';
5
+
6
+ const pixelsToRems = pixelValueString => {
7
+ const pixels = removePixelSuffix(pixelValueString);
8
+
9
+ if (pixels === '0' || pixels === 0) {
10
+ return pixels;
11
+ }
12
+
13
+ return `${Number(pixels) / 16}rem`;
14
+ };
4
15
  /**
5
16
  * Currently we have a wide range of experimental spacing tokens that we are testing.
6
17
  * We only want transforms to apply to the stable scale values, not the rest.
7
18
  * This could be removed in the future.
8
19
  */
9
20
 
21
+
10
22
  const onlyScaleTokens = spacingScale.filter(token => token.name.startsWith('spacing.scale.'));
11
23
  const spacingValueToToken = Object.fromEntries(onlyScaleTokens.map(token => [token.value, token.name]));
12
24
  /**
@@ -17,20 +29,19 @@ const spacingValueToToken = Object.fromEntries(onlyScaleTokens.map(token => [tok
17
29
  */
18
30
 
19
31
  function pixelValueToSpacingTokenNode(pixelValueString) {
20
- var _spacingValueToToken$;
21
-
32
+ const remValueString = pixelsToRems(pixelValueString);
33
+ const token = spacingValueToToken[remValueString];
22
34
  return callExpression({
23
35
  callee: identifier({
24
36
  name: 'token'
25
37
  }),
26
38
  arguments: [literal({
27
- value: `'${(_spacingValueToToken$ = spacingValueToToken[pixelValueString]) !== null && _spacingValueToToken$ !== void 0 ? _spacingValueToToken$ : ''}'`
39
+ value: `'${token !== null && token !== void 0 ? token : ''}'`
28
40
  }), literal(`'${pixelValueString}'`)],
29
41
  optional: false
30
42
  });
31
43
  }
32
44
 
33
- import { convertHyphenatedNameToCamelCase, emToPixels, findParentNodeForLine, getValue, getValueFromShorthand, isSpacingProperty, isValidSpacingValue } from './utils';
34
45
  const rule = {
35
46
  meta: {
36
47
  type: 'problem',
@@ -140,7 +151,8 @@ const rule = {
140
151
  }
141
152
 
142
153
  const pixelValueString = `${pixelValue}px`;
143
- const tokenName = spacingValueToToken[pixelValueString];
154
+ const remValueString = pixelsToRems(pixelValueString);
155
+ const tokenName = spacingValueToToken[remValueString];
144
156
 
145
157
  if (!tokenName) {
146
158
  return null;
@@ -256,7 +268,8 @@ const rule = {
256
268
  const replacementValue = values.map(value => {
257
269
  const pixelValue = emToPixels(value, fontSize);
258
270
  const pixelValueString = `${pixelValue}px`;
259
- const tokenName = spacingValueToToken[pixelValueString];
271
+ const remValueString = pixelsToRems(pixelValueString);
272
+ const tokenName = spacingValueToToken[remValueString];
260
273
 
261
274
  if (!tokenName) {
262
275
  return pixelValueString;
@@ -49,6 +49,7 @@ token('color.background.blanket');
49
49
 
50
50
  create(context) {
51
51
  const config = context.options[0] || defaultConfig;
52
+ const UNSAFE_ignoreTokens = new Set(config.UNSAFE_ignoreTokens);
52
53
  return {
53
54
  'TaggedTemplateExpression[tag.name="css"],TaggedTemplateExpression[tag.object.name="styled"]': node => {
54
55
  if (!isNodeOfType(node, 'TaggedTemplateExpression')) {
@@ -173,7 +174,7 @@ token('color.background.blanket');
173
174
  return;
174
175
  }
175
176
 
176
- if (typeof tokenKey !== 'string' || typeof tokenKey === 'string' && !tokens[tokenKey]) {
177
+ if (typeof tokenKey !== 'string' || typeof tokenKey === 'string' && !tokens[tokenKey] && !UNSAFE_ignoreTokens.has(tokenKey)) {
177
178
  context.report({
178
179
  messageId: 'invalidToken',
179
180
  node,
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
- "version": "4.13.1",
3
+ "version": "4.13.3",
4
4
  "sideEffects": false
5
5
  }
@@ -8,12 +8,24 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
8
8
  import { callExpression, identifier, isNodeOfType, literal, node as nodeFn, property } from 'eslint-codemod-utils';
9
9
  import spacingScale from '@atlaskit/tokens/spacing-raw';
10
10
  import { isDecendantOfGlobalToken } from '../utils/is-node';
11
+ import { convertHyphenatedNameToCamelCase, emToPixels, findParentNodeForLine, getValue, getValueFromShorthand, isSpacingProperty, isValidSpacingValue, removePixelSuffix } from './utils';
12
+
13
+ var pixelsToRems = function pixelsToRems(pixelValueString) {
14
+ var pixels = removePixelSuffix(pixelValueString);
15
+
16
+ if (pixels === '0' || pixels === 0) {
17
+ return pixels;
18
+ }
19
+
20
+ return "".concat(Number(pixels) / 16, "rem");
21
+ };
11
22
  /**
12
23
  * Currently we have a wide range of experimental spacing tokens that we are testing.
13
24
  * We only want transforms to apply to the stable scale values, not the rest.
14
25
  * This could be removed in the future.
15
26
  */
16
27
 
28
+
17
29
  var onlyScaleTokens = spacingScale.filter(function (token) {
18
30
  return token.name.startsWith('spacing.scale.');
19
31
  });
@@ -28,20 +40,19 @@ var spacingValueToToken = Object.fromEntries(onlyScaleTokens.map(function (token
28
40
  */
29
41
 
30
42
  function pixelValueToSpacingTokenNode(pixelValueString) {
31
- var _spacingValueToToken$;
32
-
43
+ var remValueString = pixelsToRems(pixelValueString);
44
+ var token = spacingValueToToken[remValueString];
33
45
  return callExpression({
34
46
  callee: identifier({
35
47
  name: 'token'
36
48
  }),
37
49
  arguments: [literal({
38
- value: "'".concat((_spacingValueToToken$ = spacingValueToToken[pixelValueString]) !== null && _spacingValueToToken$ !== void 0 ? _spacingValueToToken$ : '', "'")
50
+ value: "'".concat(token !== null && token !== void 0 ? token : '', "'")
39
51
  }), literal("'".concat(pixelValueString, "'"))],
40
52
  optional: false
41
53
  });
42
54
  }
43
55
 
44
- import { convertHyphenatedNameToCamelCase, emToPixels, findParentNodeForLine, getValue, getValueFromShorthand, isSpacingProperty, isValidSpacingValue } from './utils';
45
56
  var rule = {
46
57
  meta: {
47
58
  type: 'problem',
@@ -152,7 +163,8 @@ var rule = {
152
163
  }
153
164
 
154
165
  var pixelValueString = "".concat(pixelValue, "px");
155
- var tokenName = spacingValueToToken[pixelValueString];
166
+ var remValueString = pixelsToRems(pixelValueString);
167
+ var tokenName = spacingValueToToken[remValueString];
156
168
 
157
169
  if (!tokenName) {
158
170
  return null;
@@ -284,7 +296,8 @@ var rule = {
284
296
  var replacementValue = values.map(function (value) {
285
297
  var pixelValue = emToPixels(value, fontSize);
286
298
  var pixelValueString = "".concat(pixelValue, "px");
287
- var tokenName = spacingValueToToken[pixelValueString];
299
+ var remValueString = pixelsToRems(pixelValueString);
300
+ var tokenName = spacingValueToToken[remValueString];
288
301
 
289
302
  if (!tokenName) {
290
303
  return pixelValueString;
@@ -26,6 +26,7 @@ var rule = {
26
26
  },
27
27
  create: function create(context) {
28
28
  var config = context.options[0] || defaultConfig;
29
+ var UNSAFE_ignoreTokens = new Set(config.UNSAFE_ignoreTokens);
29
30
  return {
30
31
  'TaggedTemplateExpression[tag.name="css"],TaggedTemplateExpression[tag.object.name="styled"]': function TaggedTemplateExpressionTagNameCssTaggedTemplateExpressionTagObjectNameStyled(node) {
31
32
  if (!isNodeOfType(node, 'TaggedTemplateExpression')) {
@@ -166,7 +167,7 @@ var rule = {
166
167
  return;
167
168
  }
168
169
 
169
- if (typeof tokenKey !== 'string' || typeof tokenKey === 'string' && !tokens[tokenKey]) {
170
+ if (typeof tokenKey !== 'string' || typeof tokenKey === 'string' && !tokens[tokenKey] && !UNSAFE_ignoreTokens.has(tokenKey)) {
170
171
  context.report({
171
172
  messageId: 'invalidToken',
172
173
  node: node,
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
- "version": "4.13.1",
3
+ "version": "4.13.3",
4
4
  "sideEffects": false
5
5
  }
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": "4.13.1",
4
+ "version": "4.13.3",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "publishConfig": {
7
7
  "registry": "https://registry.npmjs.org/"