@atlaskit/eslint-plugin-design-system 8.33.0 → 8.34.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.
Files changed (79) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -0
  3. package/constellation/ensure-design-token-usage/usage.mdx +2 -2
  4. package/constellation/index/usage.mdx +1 -0
  5. package/constellation/use-tokens-typography/usage.mdx +42 -0
  6. package/dist/cjs/ast-nodes/index.js +7 -0
  7. package/dist/cjs/ast-nodes/object-entry.js +27 -0
  8. package/dist/cjs/ast-nodes/object.js +1 -1
  9. package/dist/cjs/presets/all.codegen.js +2 -1
  10. package/dist/cjs/rules/ensure-design-token-usage/index.js +5 -4
  11. package/dist/cjs/rules/ensure-design-token-usage/rule-meta.js +1 -1
  12. package/dist/cjs/rules/ensure-design-token-usage/spacing.js +5 -1
  13. package/dist/cjs/rules/ensure-design-token-usage/utils.js +52 -42
  14. package/dist/cjs/rules/index.codegen.js +3 -1
  15. package/dist/cjs/rules/use-tokens-typography/config/index.js +26 -0
  16. package/dist/cjs/rules/use-tokens-typography/error-boundary.js +24 -0
  17. package/dist/cjs/rules/use-tokens-typography/index.js +44 -0
  18. package/dist/cjs/rules/use-tokens-typography/transformers/style-object.js +212 -0
  19. package/dist/cjs/rules/use-tokens-typography/utils.js +146 -0
  20. package/dist/es2019/ast-nodes/index.js +1 -0
  21. package/dist/es2019/ast-nodes/object-entry.js +22 -0
  22. package/dist/es2019/ast-nodes/object.js +1 -1
  23. package/dist/es2019/presets/all.codegen.js +2 -1
  24. package/dist/es2019/rules/ensure-design-token-usage/index.js +6 -5
  25. package/dist/es2019/rules/ensure-design-token-usage/rule-meta.js +1 -1
  26. package/dist/es2019/rules/ensure-design-token-usage/spacing.js +5 -1
  27. package/dist/es2019/rules/ensure-design-token-usage/utils.js +42 -38
  28. package/dist/es2019/rules/index.codegen.js +3 -1
  29. package/dist/es2019/rules/use-tokens-typography/config/index.js +20 -0
  30. package/dist/es2019/rules/use-tokens-typography/error-boundary.js +19 -0
  31. package/dist/es2019/rules/use-tokens-typography/index.js +36 -0
  32. package/dist/es2019/rules/use-tokens-typography/transformers/style-object.js +209 -0
  33. package/dist/es2019/rules/use-tokens-typography/utils.js +99 -0
  34. package/dist/esm/ast-nodes/index.js +1 -0
  35. package/dist/esm/ast-nodes/object-entry.js +22 -0
  36. package/dist/esm/ast-nodes/object.js +1 -1
  37. package/dist/esm/presets/all.codegen.js +2 -1
  38. package/dist/esm/rules/ensure-design-token-usage/index.js +6 -5
  39. package/dist/esm/rules/ensure-design-token-usage/rule-meta.js +1 -1
  40. package/dist/esm/rules/ensure-design-token-usage/spacing.js +5 -1
  41. package/dist/esm/rules/ensure-design-token-usage/utils.js +46 -38
  42. package/dist/esm/rules/index.codegen.js +3 -1
  43. package/dist/esm/rules/use-tokens-typography/config/index.js +20 -0
  44. package/dist/esm/rules/use-tokens-typography/error-boundary.js +18 -0
  45. package/dist/esm/rules/use-tokens-typography/index.js +38 -0
  46. package/dist/esm/rules/use-tokens-typography/transformers/style-object.js +206 -0
  47. package/dist/esm/rules/use-tokens-typography/utils.js +129 -0
  48. package/dist/types/ast-nodes/index.d.ts +1 -0
  49. package/dist/types/ast-nodes/object-entry.d.ts +6 -0
  50. package/dist/types/ast-nodes/object.d.ts +1 -1
  51. package/dist/types/index.codegen.d.ts +1 -0
  52. package/dist/types/presets/all.codegen.d.ts +2 -1
  53. package/dist/types/rules/ensure-design-token-usage/types.d.ts +1 -1
  54. package/dist/types/rules/ensure-design-token-usage/utils.d.ts +22 -22
  55. package/dist/types/rules/index.codegen.d.ts +1 -0
  56. package/dist/types/rules/use-tokens-typography/config/index.d.ts +6 -0
  57. package/dist/types/rules/use-tokens-typography/error-boundary.d.ts +11 -0
  58. package/dist/types/rules/use-tokens-typography/index.d.ts +3 -0
  59. package/dist/types/rules/use-tokens-typography/transformers/style-object.d.ts +31 -0
  60. package/dist/types/rules/use-tokens-typography/utils.d.ts +161 -0
  61. package/dist/types-ts4.5/ast-nodes/index.d.ts +1 -0
  62. package/dist/types-ts4.5/ast-nodes/object-entry.d.ts +6 -0
  63. package/dist/types-ts4.5/ast-nodes/object.d.ts +1 -1
  64. package/dist/types-ts4.5/index.codegen.d.ts +1 -0
  65. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  66. package/dist/types-ts4.5/rules/ensure-design-token-usage/types.d.ts +1 -1
  67. package/dist/types-ts4.5/rules/ensure-design-token-usage/utils.d.ts +22 -22
  68. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  69. package/dist/types-ts4.5/rules/use-tokens-typography/config/index.d.ts +6 -0
  70. package/dist/types-ts4.5/rules/use-tokens-typography/error-boundary.d.ts +11 -0
  71. package/dist/types-ts4.5/rules/use-tokens-typography/index.d.ts +3 -0
  72. package/dist/types-ts4.5/rules/use-tokens-typography/transformers/style-object.d.ts +31 -0
  73. package/dist/types-ts4.5/rules/use-tokens-typography/utils.d.ts +161 -0
  74. package/package.json +1 -1
  75. package/dist/cjs/rules/ensure-design-token-usage/typography.js +0 -39
  76. package/dist/es2019/rules/ensure-design-token-usage/typography.js +0 -19
  77. package/dist/esm/rules/ensure-design-token-usage/typography.js +0 -33
  78. package/dist/types/rules/ensure-design-token-usage/typography.d.ts +0 -9
  79. package/dist/types-ts4.5/rules/ensure-design-token-usage/typography.d.ts +0 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 8.34.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#75311](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/75311) [`96ca033f8748`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/96ca033f8748) - Added new `use-tokens-typography` rule that handles converting fontSize and similar font properties to tokens. Removed typography functionality from `ensure-design-token-usage` rule.
8
+
3
9
  ## 8.33.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -78,6 +78,7 @@ module.exports = {
78
78
  | <a href="./src/rules/use-href-in-link-item/README.md">use-href-in-link-item</a> | Inform developers of eventual requirement of `href` prop in `LinkItem` component. Elements with a `link` role require an `href` attribute for users to properly navigate, particularly those using assistive technologies. If no valid `href` is required for your use case, consider using a `ButtonItem` instead. | Yes | Yes | Yes |
79
79
  | <a href="./src/rules/use-primitives/README.md">use-primitives</a> | Encourage the usage of primitives components. | | Yes | Yes |
80
80
  | <a href="./src/rules/use-primitives-text/README.md">use-primitives-text</a> | Encourage the usage of text components. | | Yes | Yes |
81
+ | <a href="./src/rules/use-tokens-typography/README.md">use-tokens-typography</a> | Enforces usage of design tokens for typography properties rather than hard-coded values. | | Yes | Yes |
81
82
  | <a href="./src/rules/use-visually-hidden/README.md">use-visually-hidden</a> | Enforce usage of the visually hidden component. | Yes | Yes | |
82
83
 
83
84
  <!-- END_RULE_TABLE_CODEGEN -->
@@ -2,7 +2,7 @@
2
2
 
3
3
  Using design tokens results in a harmonious experience for end users whilst providing theming and consistency.
4
4
  All experiences must use color tokens otherwise when switching between themes, unexpected incidents can occur where not all of the UI is themed.
5
- Space, typography, and shape tokens are strongly recommended to further align our experiences and make future changes easier.
5
+ Space, and shape tokens are strongly recommended to further align our experiences and make future changes easier.
6
6
 
7
7
  ## Examples
8
8
 
@@ -57,7 +57,7 @@ This rule comes with options to aid in migrating to design tokens.
57
57
 
58
58
  ### domains
59
59
 
60
- An array specifiying which token domains to lint against (`color`, `spacing`, `typography`, `shape`). Defaults to [`'color'`] if not provided.
60
+ An array specifiying which token domains to lint against (`color`, `spacing`, `shape`). Defaults to [`'color'`] if not provided.
61
61
 
62
62
  ### applyImport
63
63
 
@@ -40,6 +40,7 @@ This plugin contains rules that should be used when working with the [Atlassian
40
40
  | <a href="use-href-in-link-item/usage">use-href-in-link-item</a> | Inform developers of eventual requirement of `href` prop in `LinkItem` component. Elements with a `link` role require an `href` attribute for users to properly navigate, particularly those using assistive technologies. If no valid `href` is required for your use case, consider using a `ButtonItem` instead. | Yes | Yes | Yes |
41
41
  | <a href="use-primitives/usage">use-primitives</a> | Encourage the usage of primitives components. | | Yes | Yes |
42
42
  | <a href="use-primitives-text/usage">use-primitives-text</a> | Encourage the usage of text components. | | Yes | Yes |
43
+ | <a href="use-tokens-typography/usage">use-tokens-typography</a> | Enforces usage of design tokens for typography properties rather than hard-coded values. | | Yes | Yes |
43
44
  | <a href="use-visually-hidden/usage">use-visually-hidden</a> | Enforce usage of the visually hidden component. | Yes | Yes | |
44
45
 
45
46
  <!-- END_RULE_TABLE_CODEGEN -->
@@ -0,0 +1,42 @@
1
+ # use-tokens-typography
2
+
3
+ Enforces the use of design tokens for typography properties.
4
+
5
+ Using design tokens results in a harmonious experience for end users whilst providing theming and consistency.
6
+ Typography tokens are strongly recommended to further align our experiences and make future changes easier.
7
+
8
+ Note: This rule is fairly defensive when it comes to replacing values with tokens. It will only run over style blocks that contain a fontSize property. It will then attempt to match that font size to a token. If multiple matching tokens are found it then tries to match on font weight. If a token can be found to match the font size but not font weight, the token is applied and then a font weight token override is applied to ensure the tokenised styles match the original. One main exception is line height - **this rule will match against tokens that have a different line height**. Letter spacing values are also ignored.
9
+
10
+ ## Examples
11
+
12
+ Using anything other than design tokens such as hardcoded values or legacy theme constants will be considered violations.
13
+
14
+ ### Incorrect
15
+
16
+ ```js
17
+ import { fontSize } from '@atlaskit/theme/constants';
18
+
19
+ css({ fontSize: fontSize() });
20
+ ^^^^^^^^^^
21
+
22
+ css({ fontSize: '14px' });
23
+ ^^^^^^
24
+
25
+ css({
26
+ fontSize: '14px',
27
+ ^^^^^^
28
+ lineHeight: '20px',
29
+ fontWeight: 600
30
+ });
31
+
32
+ ```
33
+
34
+ ### Correct
35
+
36
+ ```js
37
+ import { token } from '@atlaskit/tokens';
38
+
39
+ css({ fontSize: token('font.heading.large') });
40
+
41
+ css({ fontSize: token('font.body') });
42
+ ```
@@ -33,6 +33,12 @@ Object.defineProperty(exports, "Object", {
33
33
  return _object.Object;
34
34
  }
35
35
  });
36
+ Object.defineProperty(exports, "ObjectEntry", {
37
+ enumerable: true,
38
+ get: function get() {
39
+ return _objectEntry.ObjectEntry;
40
+ }
41
+ });
36
42
  Object.defineProperty(exports, "Root", {
37
43
  enumerable: true,
38
44
  get: function get() {
@@ -44,4 +50,5 @@ var _import = require("./import");
44
50
  var _jsxAttribute = require("./jsx-attribute");
45
51
  var _jsxElement = require("./jsx-element");
46
52
  var _object = require("./object");
53
+ var _objectEntry = require("./object-entry");
47
54
  var _root = require("./root");
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ObjectEntry = void 0;
7
+ var ObjectEntry = exports.ObjectEntry = {
8
+ deleteEntry: function deleteEntry(node, context, fixer) {
9
+ var _lastToken;
10
+ // context.getSourceCode() is deprecated in favour of context.sourceCode, however this returns undefined for some reason
11
+ var sourceCode = context.getSourceCode();
12
+
13
+ // fixer.remove() doesn't account for things like commas or newlines within an ObjectExpression and will result in invalid output.
14
+ // This approach specifically removes the node and trailing comma, and should work for single- and multi-line objects.
15
+ // From https://github.com/eslint/eslint/issues/9576#issuecomment-341737453
16
+ var prevToken = sourceCode.getTokenBefore(node);
17
+ while (((_prevToken = prevToken) === null || _prevToken === void 0 ? void 0 : _prevToken.value) !== ',' && ((_prevToken2 = prevToken) === null || _prevToken2 === void 0 ? void 0 : _prevToken2.value) !== '{') {
18
+ var _prevToken, _prevToken2;
19
+ prevToken = sourceCode.getTokenBefore(node);
20
+ }
21
+ var lastToken = sourceCode.getTokenAfter(node);
22
+ if (((_lastToken = lastToken) === null || _lastToken === void 0 ? void 0 : _lastToken.value) !== ',') {
23
+ lastToken = sourceCode.getTokenBefore(lastToken);
24
+ }
25
+ return fixer.removeRange([prevToken.range[1], lastToken.range[1]]);
26
+ }
27
+ };
@@ -33,7 +33,7 @@ var ASTObjectExpression = exports.Object = {
33
33
  });
34
34
  },
35
35
  /**
36
- * Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`.
36
+ * Returns the first Property node from an Object that matches the provided name.
37
37
  */
38
38
  getEntryByPropertyName: function getEntryByPropertyName(node, name) {
39
39
  return node.properties.find(function (property) {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::bcb633b9d5c2def00d43b11139433c5c>>
9
+ * @codegen <<SignedSource::d90c2cf5e100daf98915f9467f2e5663>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -41,6 +41,7 @@ var _default = exports.default = {
41
41
  '@atlaskit/design-system/use-href-in-link-item': 'warn',
42
42
  '@atlaskit/design-system/use-primitives': 'warn',
43
43
  '@atlaskit/design-system/use-primitives-text': 'warn',
44
+ '@atlaskit/design-system/use-tokens-typography': 'warn',
44
45
  '@atlaskit/design-system/use-visually-hidden': 'error'
45
46
  }
46
47
  };
@@ -111,11 +111,12 @@ var createWithConfig = exports.createWithConfig = function createWithConfig(init
111
111
  if (domains.includes('color')) {
112
112
  return (0, _color.lintObjectForColor)(node, context, config);
113
113
  }
114
- if (domains.includes('spacing') || domains.includes('shape') || domains.includes('typography')) {
114
+ if (domains.includes('spacing') || domains.includes('shape')) {
115
115
  /**
116
- * We do this in case the fontSize for a style object is declared alongside the `em` or `lineHeight` declaration
116
+ * We do this in case the fontSize for a style object is declared alongside the `em` or `lineHeight` declaration.
117
117
  */
118
- var fontSize = (0, _utils.getFontSizeFromNode)(parentNode, context);
118
+ var fontSizeNode = (0, _utils.getPropertyNodeFromParent)('fontSize', parentNode);
119
+ var fontSize = fontSizeNode && (0, _utils.getValueForPropertyNode)(fontSizeNode, context);
119
120
  return (0, _spacing.lintObjectForSpacing)(node, context, config, fontSize, tokenNode);
120
121
  }
121
122
  }
@@ -173,7 +174,7 @@ var createWithConfig = exports.createWithConfig = function createWithConfig(init
173
174
  return currentSource;
174
175
  }
175
176
  }
176
- if (domains.includes('spacing') || domains.includes('typography') || domains.includes('shape')) {
177
+ if (domains.includes('spacing') || domains.includes('shape')) {
177
178
  if (!(0, _utils.isValidSpacingValue)(resolvedCssValues, globalFontSize)) {
178
179
  // no changes should be made to the current property
179
180
  return currentSource;
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var domainsToLint = ['color', 'spacing', 'typography', 'shape'];
7
+ var domainsToLint = ['color', 'spacing', 'shape'];
8
8
  var ruleMeta = {
9
9
  name: 'ensure-design-token-usage',
10
10
  hasSuggestions: true,
@@ -74,7 +74,8 @@ var lintObjectForSpacing = exports.lintObjectForSpacing = function lintObjectFor
74
74
  payload: "".concat(propertyName, ":").concat(pixelValue)
75
75
  },
76
76
  fix: function fix(fixer) {
77
- var replacementNode = (0, _utils.getTokenReplacement)(propertyName, pixelValue);
77
+ // Casting due to possibility of pixelValue being string | number from emToPixels
78
+ var replacementNode = pixelValue && (0, _utils.getTokenReplacement)(propertyName, pixelValue);
78
79
  if (!replacementNode) {
79
80
  return null;
80
81
  }
@@ -121,6 +122,8 @@ var lintObjectForSpacing = exports.lintObjectForSpacing = function lintObjectFor
121
122
  if (!allResolvableValues) {
122
123
  return null;
123
124
  }
125
+
126
+ // Casting due to possibility of value being string | number
124
127
  var valuesWithTokenReplacement = valuesForProperty.filter(function (value) {
125
128
  return (0, _utils.findTokenNameByPropertyValue)(propertyName, value);
126
129
  }).filter(function (value) {
@@ -154,6 +157,7 @@ var lintObjectForSpacing = exports.lintObjectForSpacing = function lintObjectFor
154
157
  var pixelValueString = "".concat(pixelValue, "px");
155
158
  // if there is a token we take it, otherwise we go with the original value
156
159
 
160
+ // Casting due to possibility of value being string | number
157
161
  return (0, _utils.findTokenNameByPropertyValue)(propertyName, value) ? "${".concat((0, _utils.getTokenNodeForValue)(propertyName, pixelValueString), "}") : originalValues[index];
158
162
  }).join(' '), "`"))]);
159
163
  }
@@ -8,12 +8,14 @@ exports.cleanComments = cleanComments;
8
8
  exports.findParentNodeForLine = exports.emToPixels = exports.convertHyphenatedNameToCamelCase = void 0;
9
9
  exports.findTokenNameByPropertyValue = findTokenNameByPropertyValue;
10
10
  exports.getDomainsForProperty = getDomainsForProperty;
11
- exports.getFontSizeFromNode = getFontSizeFromNode;
12
11
  exports.getFontSizeValueInScope = getFontSizeValueInScope;
12
+ exports.getPropertyNodeFromParent = getPropertyNodeFromParent;
13
13
  exports.getRawExpression = void 0;
14
14
  exports.getTokenNodeForValue = getTokenNodeForValue;
15
15
  exports.getTokenReplacement = getTokenReplacement;
16
- exports.getValueFromTemplateLiteralRaw = exports.getValueFromShorthand = exports.getValue = void 0;
16
+ exports.getValue = void 0;
17
+ exports.getValueForPropertyNode = getValueForPropertyNode;
18
+ exports.getValueFromTemplateLiteralRaw = exports.getValueFromShorthand = void 0;
17
19
  exports.includesTokenString = includesTokenString;
18
20
  exports.insertTokensImport = insertTokensImport;
19
21
  exports.isSpacingProperty = exports.isCalc = exports.isAuto = void 0;
@@ -30,7 +32,6 @@ var _tokensRaw = require("@atlaskit/tokens/tokens-raw");
30
32
  var _findInParent = require("../utils/find-in-parent");
31
33
  var _isColor = require("../utils/is-color");
32
34
  var _shape = require("./shape");
33
- var _typography = require("./typography");
34
35
  // eslint-disable-next-line import/no-extraneous-dependencies
35
36
 
36
37
  var properties = ['padding', 'paddingBlock', 'paddingInline', 'paddingLeft', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingInline', 'paddingInlineStart', 'paddingInlineEnd', 'paddingBlock', 'paddingBlockStart', 'paddingBlockEnd', 'marginLeft', 'marginTop', 'marginRight', 'marginBottom', 'marginInline', 'marginInlineStart', 'marginInlineEnd', 'marginBlock', 'marginBlockStart', 'marginBlockEnd', 'margin', 'gap', 'rowGap', 'gridRowGap', 'columnGap', 'gridColumnGap', 'top', 'left', 'right', 'bottom', 'inlineStart', 'inlineEnd', 'blockStart', 'blockEnd', 'outline-offset'];
@@ -60,8 +61,10 @@ var splitShorthandValues = exports.splitShorthandValues = function splitShorthan
60
61
  };
61
62
  var getValueFromShorthand = exports.getValueFromShorthand = function getValueFromShorthand(str) {
62
63
  var valueString = String(str);
63
- var fontFamily = /(sans-serif$)|(monospace$)/;
64
- if (fontFamily.test(valueString)) {
64
+ var fontFamily = /(Charlie)|(sans-serif$)|(monospace$)/;
65
+ var fontWeightString = /(regular$)|(medium$)|(semibold$)|(bold$)/;
66
+ var fontStyleString = /(inherit$)|(normal$)|(italic$)/;
67
+ if (fontFamily.test(valueString) || fontWeightString.test(valueString) || fontStyleString.test(valueString)) {
65
68
  return [valueString];
66
69
  }
67
70
  // If we want to filter out NaN just add .filter(Boolean)
@@ -90,6 +93,12 @@ var getRawExpressionForToken = function getRawExpressionForToken(node, context)
90
93
  }).join(', '), ")}");
91
94
  return call;
92
95
  };
96
+ var isFontSize = function isFontSize(node) {
97
+ return (0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression') && (0, _eslintCodemodUtils.isNodeOfType)(node.callee, 'Identifier') && (node.callee.name === 'fontSize' || node.callee.name === 'getFontSize');
98
+ };
99
+ var isFontSizeSmall = function isFontSizeSmall(node) {
100
+ return (0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression') && (0, _eslintCodemodUtils.isNodeOfType)(node.callee, 'Identifier') && node.callee.name === 'fontSizeSmall';
101
+ };
93
102
  var getValueFromCallExpression = function getValueFromCallExpression(node, context) {
94
103
  if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression')) {
95
104
  return null;
@@ -100,18 +109,12 @@ var getValueFromCallExpression = function getValueFromCallExpression(node, conte
100
109
  if ((0, _shape.isBorderRadius)(node)) {
101
110
  return 3;
102
111
  }
103
- if ((0, _typography.isFontSize)(node)) {
112
+ if (isFontSize(node)) {
104
113
  return 14;
105
114
  }
106
- if ((0, _typography.isFontSizeSmall)(node)) {
115
+ if (isFontSizeSmall(node)) {
107
116
  return 11;
108
117
  }
109
- if ((0, _typography.isFontFamily)(node)) {
110
- return "-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif";
111
- }
112
- if ((0, _typography.isCodeFontFamily)(node)) {
113
- return "'SFMono-Medium', 'SF Mono', 'Segoe UI Mono', 'Roboto Mono', 'Ubuntu Mono', Menlo, Consolas, Courier, monospace";
114
- }
115
118
  if (isToken(node)) {
116
119
  return getRawExpressionForToken(node, context);
117
120
  }
@@ -316,7 +319,7 @@ var convertHyphenatedNameToCamelCase = exports.convertHyphenatedNameToCamelCase
316
319
 
317
320
  /**
318
321
  * @param node
319
- * @returns The furthest parent node that is on the same line as the input node
322
+ * @returns The furthest parent node that is on the same line as the input node.
320
323
  */
321
324
  var findParentNodeForLine = exports.findParentNodeForLine = function findParentNodeForLine(node) {
322
325
  var _node$loc, _node$parent$loc;
@@ -331,14 +334,13 @@ var findParentNodeForLine = exports.findParentNodeForLine = function findParentN
331
334
  };
332
335
 
333
336
  /**
334
- * Returns an array of domains that are relevant to the provided property based on the rule options
337
+ * Returns an array of domains that are relevant to the provided property based on the rule options.
335
338
  * @param propertyName camelCase CSS property
336
- * @param targetOptions Array containing the types of properties that should be included in the rule
339
+ * @param targetOptions Array containing the types of properties that should be included in the rule.
337
340
  * @example
338
341
  * ```
339
342
  * propertyName: padding, targetOptions: ['spacing'] -> returns ['spacing']
340
- * propertyName: fontWeight, targetOptions: ['spacing', 'typography'] -> returns ['typography']
341
- * propertyName: backgroundColor, targetOptions: ['spacing', 'typography'] -> returns []
343
+ * propertyName: backgroundColor, targetOptions: ['spacing'] -> returns []
342
344
  * propertyName: backgroundColor, targetOptions: ['color', 'spacing'] -> returns ['color']
343
345
  * ```
344
346
  */
@@ -353,15 +355,12 @@ function getDomainsForProperty(propertyName, targetOptions) {
353
355
  if ((0, _shape.isShapeProperty)(propertyName) && targetOptions.includes('shape')) {
354
356
  domains.push('shape');
355
357
  }
356
- if ((0, _typography.isTypographyProperty)(propertyName) && targetOptions.includes('typography')) {
357
- domains.push('typography');
358
- }
359
358
  return domains;
360
359
  }
361
360
 
362
361
  /**
363
362
  * Function that removes JS comments from a string of code,
364
- * sometimes makers will have single or multiline comments in their tagged template literals styles, this can mess with our parsing logic
363
+ * sometimes makers will have single or multiline comments in their tagged template literals styles, this can mess with our parsing logic.
365
364
  */
366
365
  function cleanComments(str) {
367
366
  return str.replace(/\/\*([\s\S]*?)\*\//g, '').replace(/\/\/(.*)/g, '');
@@ -369,11 +368,11 @@ function cleanComments(str) {
369
368
 
370
369
  /**
371
370
  * Returns an array of tuples representing a processed css within `TaggedTemplateExpression` node.
372
- * each element of the array is a tuple `[string, string]`,
371
+ * Each element of the array is a tuple `[string, string]`,
373
372
  * where the first element is the processed css line with computed values
374
- * and the second element of the tuple is the original css line from source
375
- * @param node TaggedTemplateExpression node
376
- * @param context Rule.RuleContext
373
+ * and the second element of the tuple is the original css line from source.
374
+ * @param node TaggedTemplateExpression node.
375
+ * @param context Rule.RuleContext.
377
376
  * @example
378
377
  * ```
379
378
  * `[['padding: 8', 'padding: ${gridSize()}'], ['margin: 6', 'margin: 6px' ]]`
@@ -448,7 +447,7 @@ function getFontSizeValueInScope(cssProperties) {
448
447
 
449
448
  /**
450
449
  * Attempts to remove all non-essential words & characters from a style block.
451
- * Including selectors and queries
450
+ * Including selectors and queries.
452
451
  * @param styleString string of css properties
453
452
  */
454
453
  function splitCssProperties(styleString) {
@@ -473,8 +472,8 @@ function splitCssProperties(styleString) {
473
472
  }
474
473
 
475
474
  /**
476
- * returns whether the current string is a token value
477
- * @param originalVaue string representing a css property value e.g 1em, 12px
475
+ * Returns whether the current string is a token value.
476
+ * @param originalVaue string representing a css property value e.g 1em, 12px.
478
477
  */
479
478
  function isTokenValueString(originalValue) {
480
479
  return originalValue.startsWith('${token(') && originalValue.endsWith('}');
@@ -488,19 +487,27 @@ function includesTokenString(originalValue) {
488
487
  *
489
488
  * -> for pixels this '8px'
490
489
  * -> for weights '400'
491
- * -> for family 'Arial'
490
+ * -> for family 'Arial'.
492
491
  *
493
492
  * @internal
494
493
  */
495
494
  function normaliseValue(propertyName, value) {
496
- var isFontWeightOrFamily = /fontWeight|fontFamily/.test(propertyName);
495
+ var isFontStringProperty = /fontWeight|fontFamily|fontStyle/.test(propertyName);
496
+ var isLineHeight = /lineHeight/.test(propertyName);
497
497
  var propertyValue = typeof value === 'string' ? value.trim() : value;
498
- var lookupValue = isFontWeightOrFamily ? propertyValue : typeof propertyValue === 'string' ? propertyValue : "".concat(propertyValue, "px");
498
+ var lookupValue;
499
+ if (isFontStringProperty) {
500
+ lookupValue = "".concat(propertyValue);
501
+ } else if (isLineHeight) {
502
+ lookupValue = value === 1 ? "".concat(propertyValue) : "".concat(propertyValue, "px");
503
+ } else {
504
+ lookupValue = typeof propertyValue === 'string' ? propertyValue : "".concat(propertyValue, "px");
505
+ }
499
506
  return lookupValue;
500
507
  }
501
508
  function findTokenNameByPropertyValue(propertyName, value) {
502
509
  var lookupValue = normaliseValue(propertyName, value);
503
- var tokenName = (0, _shape.isShapeProperty)(propertyName) ? (0, _shape.isBorderSizeProperty)(propertyName) ? _shape.borderWidthValueToToken[lookupValue] : _shape.radiusValueToToken[lookupValue] : (0, _typography.isTypographyProperty)(propertyName) ? _typography.typographyValueToToken[propertyName][lookupValue] : spacingValueToToken[lookupValue];
510
+ var tokenName = (0, _shape.isShapeProperty)(propertyName) ? (0, _shape.isBorderSizeProperty)(propertyName) ? _shape.borderWidthValueToToken[lookupValue] : _shape.radiusValueToToken[lookupValue] : spacingValueToToken[lookupValue];
504
511
  if (!tokenName) {
505
512
  return undefined;
506
513
  }
@@ -509,9 +516,9 @@ function findTokenNameByPropertyValue(propertyName, value) {
509
516
 
510
517
  /**
511
518
  * Returns a stringifiable node with the token expression corresponding to its matching token.
512
- * if no token found for the pair the function returns undefined
513
- * @param propertyName string camelCased css property
514
- * @param value the computed value e.g '8px' -> '8'
519
+ * If no token found for the pair the function returns undefined.
520
+ * @param propertyName string camelCased css property.
521
+ * @param value The computed value e.g '8px' -> '8'.
515
522
  */
516
523
  function getTokenReplacement(propertyName, value) {
517
524
  var tokenName = findTokenNameByPropertyValue(propertyName, value);
@@ -521,17 +528,20 @@ function getTokenReplacement(propertyName, value) {
521
528
  var fallbackValue = normaliseValue(propertyName, value);
522
529
  return getTokenNodeForValue(propertyName, fallbackValue);
523
530
  }
524
- function getFontSizeFromNode(parentNode, context) {
525
- var fontSizeNode = parentNode.properties.find(function (node) {
531
+ function getPropertyNodeFromParent(property, parentNode) {
532
+ var propertyNode = parentNode.properties.find(function (node) {
526
533
  if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'Property')) {
527
534
  return;
528
535
  }
529
536
  if (!(0, _eslintCodemodUtils.isNodeOfType)(node.key, 'Identifier')) {
530
537
  return;
531
538
  }
532
- return node.key.name === 'fontSize';
539
+ return node.key.name === property;
533
540
  });
534
- var fontSizeValue = (0, _eslintCodemodUtils.isNodeOfType)(fontSizeNode, 'Property') ? getValue(fontSizeNode.value, context) : null;
535
- var fontSize = Array.isArray(fontSizeValue) ? fontSizeValue[0] : fontSizeValue;
536
- return fontSize;
541
+ return propertyNode;
542
+ }
543
+ function getValueForPropertyNode(propertyNode, context) {
544
+ var propertyValueRaw = (0, _eslintCodemodUtils.isNodeOfType)(propertyNode, 'Property') ? getValue(propertyNode.value, context) : null;
545
+ var propertyValue = Array.isArray(propertyValueRaw) ? propertyValueRaw[0] : propertyValueRaw;
546
+ return propertyValue;
537
547
  }
@@ -34,10 +34,11 @@ var _useHeadingLevelInSpotlightCard = _interopRequireDefault(require("./use-head
34
34
  var _useHrefInLinkItem = _interopRequireDefault(require("./use-href-in-link-item"));
35
35
  var _usePrimitives = _interopRequireDefault(require("./use-primitives"));
36
36
  var _usePrimitivesText = _interopRequireDefault(require("./use-primitives-text"));
37
+ var _useTokensTypography = _interopRequireDefault(require("./use-tokens-typography"));
37
38
  var _useVisuallyHidden = _interopRequireDefault(require("./use-visually-hidden"));
38
39
  /**
39
40
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
40
- * @codegen <<SignedSource::23062a8759ba919facf30a402e5546bd>>
41
+ * @codegen <<SignedSource::c283cd7ede5e813a9119cd707d339273>>
41
42
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
42
43
  */
43
44
  var _default = exports.default = {
@@ -70,5 +71,6 @@ var _default = exports.default = {
70
71
  'use-href-in-link-item': _useHrefInLinkItem.default,
71
72
  'use-primitives': _usePrimitives.default,
72
73
  'use-primitives-text': _usePrimitivesText.default,
74
+ 'use-tokens-typography': _useTokensTypography.default,
73
75
  'use-visually-hidden': _useVisuallyHidden.default
74
76
  };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ruleSchema = exports.getConfig = void 0;
7
+ var ruleSchema = exports.ruleSchema = {
8
+ type: 'array',
9
+ items: {
10
+ type: 'object',
11
+ properties: {
12
+ failSilently: {
13
+ type: 'boolean'
14
+ }
15
+ }
16
+ }
17
+ };
18
+ var defaultConfig = {
19
+ failSilently: false
20
+ };
21
+ var getConfig = exports.getConfig = function getConfig(overrides) {
22
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
23
+ // start with an empty object, then merge in the defaults, then merge in overrides.
24
+ // The empty object is returned, as well as modified in place
25
+ return Object.assign({}, defaultConfig, overrides);
26
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.errorBoundary = void 0;
7
+ /**
8
+ * ESLint rules should NEVER throw exceptions, because that breaks the VSCode ESLint server
9
+ * (and probably the IntelliJ one too), which causes linting to fail in a file.
10
+ *
11
+ * It also breaks CI, which was the reason this error boundary was added. It's a final
12
+ * catch all.
13
+ */
14
+ var errorBoundary = exports.errorBoundary = function errorBoundary(func, _ref) {
15
+ var config = _ref.config;
16
+ try {
17
+ func();
18
+ } catch (err) {
19
+ if (!config.failSilently) {
20
+ // eslint-disable-next-line no-console
21
+ console.warn(err);
22
+ }
23
+ }
24
+ };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _createRule = require("../utils/create-rule");
8
+ var _config = require("./config");
9
+ var _errorBoundary = require("./error-boundary");
10
+ var _styleObject = require("./transformers/style-object");
11
+ var create = function create(context) {
12
+ var config = (0, _config.getConfig)(context.options[0]);
13
+ return {
14
+ // const styles = css({ fontSize: '14px, ... }), styled.div({ fontSize: 14, ... })
15
+ ObjectExpression: function ObjectExpression(node) {
16
+ return (0, _errorBoundary.errorBoundary)(function () {
17
+ return _styleObject.StyleObject.lint(node, {
18
+ context: context
19
+ });
20
+ }, {
21
+ config: config
22
+ });
23
+ }
24
+ };
25
+ };
26
+ var rule = (0, _createRule.createLintRule)({
27
+ meta: {
28
+ name: 'use-tokens-typography',
29
+ type: 'problem',
30
+ fixable: 'code',
31
+ hasSuggestions: true,
32
+ docs: {
33
+ description: 'Enforces usage of design tokens for typography properties rather than hard-coded values.',
34
+ recommended: false,
35
+ severity: 'warn'
36
+ },
37
+ messages: {
38
+ noRawTypographyValues: 'Typography primitives or tokens should be used instead of hard-coded values.\n\n@meta <<{{payload}}>>.'
39
+ },
40
+ schema: _config.ruleSchema
41
+ },
42
+ create: create
43
+ });
44
+ var _default = exports.default = rule;