@atlaskit/eslint-plugin-design-system 8.37.3 → 9.0.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 (78) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +1 -0
  3. package/constellation/consistent-css-prop-usage/usage.mdx +3 -19
  4. package/constellation/index/usage.mdx +1 -0
  5. package/constellation/use-tokens-space/usage.mdx +30 -0
  6. package/dist/cjs/ast-nodes/object-entry.js +35 -0
  7. package/dist/cjs/ast-nodes/object.js +12 -0
  8. package/dist/cjs/presets/all.codegen.js +2 -1
  9. package/dist/cjs/rules/consistent-css-prop-usage/index.js +53 -85
  10. package/dist/cjs/rules/index.codegen.js +3 -1
  11. package/dist/cjs/rules/use-tokens-space/index.js +54 -0
  12. package/dist/cjs/rules/use-tokens-space/transformers/index.js +12 -0
  13. package/dist/cjs/rules/use-tokens-space/transformers/style-property/index.js +130 -0
  14. package/dist/cjs/rules/use-tokens-space/transformers/style-property/style-map.js +80 -0
  15. package/dist/cjs/rules/use-tokens-space/transformers/style-property/supported.js +14 -0
  16. package/dist/cjs/rules/use-tokens-space/transformers/style-property/upsert-import-declaration.js +37 -0
  17. package/dist/cjs/rules/use-tokens-space/utils/index.js +12 -0
  18. package/dist/cjs/rules/use-tokens-space/utils/is-string-or-number.js +9 -0
  19. package/dist/cjs/rules/utils/is-supported-import.js +12 -3
  20. package/dist/es2019/ast-nodes/object-entry.js +37 -3
  21. package/dist/es2019/ast-nodes/object.js +12 -0
  22. package/dist/es2019/presets/all.codegen.js +2 -1
  23. package/dist/es2019/rules/consistent-css-prop-usage/index.js +21 -48
  24. package/dist/es2019/rules/index.codegen.js +3 -1
  25. package/dist/es2019/rules/use-tokens-space/index.js +38 -0
  26. package/dist/es2019/rules/use-tokens-space/transformers/index.js +1 -0
  27. package/dist/es2019/rules/use-tokens-space/transformers/style-property/index.js +121 -0
  28. package/dist/es2019/rules/use-tokens-space/transformers/style-property/style-map.js +152 -0
  29. package/dist/es2019/rules/use-tokens-space/transformers/style-property/supported.js +8 -0
  30. package/dist/es2019/rules/use-tokens-space/transformers/style-property/upsert-import-declaration.js +30 -0
  31. package/dist/es2019/rules/use-tokens-space/utils/index.js +1 -0
  32. package/dist/es2019/rules/use-tokens-space/utils/is-string-or-number.js +3 -0
  33. package/dist/es2019/rules/utils/is-supported-import.js +15 -2
  34. package/dist/esm/ast-nodes/object-entry.js +37 -3
  35. package/dist/esm/ast-nodes/object.js +12 -0
  36. package/dist/esm/presets/all.codegen.js +2 -1
  37. package/dist/esm/rules/consistent-css-prop-usage/index.js +53 -85
  38. package/dist/esm/rules/index.codegen.js +3 -1
  39. package/dist/esm/rules/use-tokens-space/index.js +48 -0
  40. package/dist/esm/rules/use-tokens-space/transformers/index.js +1 -0
  41. package/dist/esm/rules/use-tokens-space/transformers/style-property/index.js +120 -0
  42. package/dist/esm/rules/use-tokens-space/transformers/style-property/style-map.js +73 -0
  43. package/dist/esm/rules/use-tokens-space/transformers/style-property/supported.js +8 -0
  44. package/dist/esm/rules/use-tokens-space/transformers/style-property/upsert-import-declaration.js +29 -0
  45. package/dist/esm/rules/use-tokens-space/utils/index.js +1 -0
  46. package/dist/esm/rules/use-tokens-space/utils/is-string-or-number.js +3 -0
  47. package/dist/esm/rules/utils/is-supported-import.js +11 -2
  48. package/dist/types/ast-nodes/object-entry.d.ts +12 -2
  49. package/dist/types/ast-nodes/object.d.ts +1 -0
  50. package/dist/types/index.codegen.d.ts +1 -0
  51. package/dist/types/presets/all.codegen.d.ts +2 -1
  52. package/dist/types/rules/consistent-css-prop-usage/types.d.ts +1 -2
  53. package/dist/types/rules/index.codegen.d.ts +1 -0
  54. package/dist/types/rules/use-tokens-space/index.d.ts +3 -0
  55. package/dist/types/rules/use-tokens-space/transformers/index.d.ts +1 -0
  56. package/dist/types/rules/use-tokens-space/transformers/style-property/index.d.ts +26 -0
  57. package/dist/types/rules/use-tokens-space/transformers/style-property/style-map.d.ts +7 -0
  58. package/dist/types/rules/use-tokens-space/transformers/style-property/supported.d.ts +6 -0
  59. package/dist/types/rules/use-tokens-space/transformers/style-property/upsert-import-declaration.d.ts +14 -0
  60. package/dist/types/rules/use-tokens-space/utils/index.d.ts +1 -0
  61. package/dist/types/rules/use-tokens-space/utils/is-string-or-number.d.ts +1 -0
  62. package/dist/types/rules/utils/is-supported-import.d.ts +5 -4
  63. package/dist/types-ts4.5/ast-nodes/object-entry.d.ts +12 -2
  64. package/dist/types-ts4.5/ast-nodes/object.d.ts +1 -0
  65. package/dist/types-ts4.5/index.codegen.d.ts +1 -0
  66. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  67. package/dist/types-ts4.5/rules/consistent-css-prop-usage/types.d.ts +1 -2
  68. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  69. package/dist/types-ts4.5/rules/use-tokens-space/index.d.ts +3 -0
  70. package/dist/types-ts4.5/rules/use-tokens-space/transformers/index.d.ts +1 -0
  71. package/dist/types-ts4.5/rules/use-tokens-space/transformers/style-property/index.d.ts +26 -0
  72. package/dist/types-ts4.5/rules/use-tokens-space/transformers/style-property/style-map.d.ts +7 -0
  73. package/dist/types-ts4.5/rules/use-tokens-space/transformers/style-property/supported.d.ts +6 -0
  74. package/dist/types-ts4.5/rules/use-tokens-space/transformers/style-property/upsert-import-declaration.d.ts +14 -0
  75. package/dist/types-ts4.5/rules/use-tokens-space/utils/index.d.ts +1 -0
  76. package/dist/types-ts4.5/rules/use-tokens-space/utils/is-string-or-number.d.ts +1 -0
  77. package/dist/types-ts4.5/rules/utils/is-supported-import.d.ts +5 -4
  78. package/package.json +2 -2
@@ -0,0 +1,152 @@
1
+ // TODO: https://product-fabric.atlassian.net/browse/DSP-16054
2
+ const tokenMap = {
3
+ '-2px': 'space.negative.025',
4
+ '-4px': 'space.negative.050',
5
+ '-6px': 'space.negative.075',
6
+ '-8px': 'space.negative.100',
7
+ '-12px': 'space.negative.150',
8
+ '-16px': 'space.negative.200',
9
+ '-20px': 'space.negative.250',
10
+ '-24px': 'space.negative.300',
11
+ '-32px': 'space.negative.400',
12
+ [-2]: 'space.negative.025',
13
+ [-4]: 'space.negative.050',
14
+ [-6]: 'space.negative.075',
15
+ [-8]: 'space.negative.100',
16
+ [-12]: 'space.negative.150',
17
+ [-16]: 'space.negative.200',
18
+ [-20]: 'space.negative.250',
19
+ [-24]: 'space.negative.300',
20
+ [-32]: 'space.negative.400',
21
+ // '0px': 'space.0', // Don't map 0 to match the implementation of `ensure-design-token-usage`
22
+ '2px': 'space.025',
23
+ '4px': 'space.050',
24
+ '6px': 'space.075',
25
+ '8px': 'space.100',
26
+ '12px': 'space.150',
27
+ '16px': 'space.200',
28
+ '20px': 'space.250',
29
+ '24px': 'space.300',
30
+ '32px': 'space.400',
31
+ '40px': 'space.500',
32
+ '48px': 'space.600',
33
+ '64px': 'space.800',
34
+ '80px': 'space.1000',
35
+ // 0: 'space.0', // Don't map 0 to match the implementation of `ensure-design-token-usage`
36
+ 2: 'space.025',
37
+ 4: 'space.050',
38
+ 6: 'space.075',
39
+ 8: 'space.100',
40
+ 12: 'space.150',
41
+ 16: 'space.200',
42
+ 20: 'space.250',
43
+ 24: 'space.300',
44
+ 32: 'space.400',
45
+ 40: 'space.500',
46
+ 48: 'space.600',
47
+ 64: 'space.800',
48
+ 80: 'space.1000',
49
+ '-0.125rem': 'space.negative.025',
50
+ '-0.25rem': 'space.negative.050',
51
+ '-0.375rem': 'space.negative.075',
52
+ '-0.5rem': 'space.negative.100',
53
+ '-0.75rem': 'space.negative.150',
54
+ '-1rem': 'space.negative.200',
55
+ '-1.25rem': 'space.negative.250',
56
+ '-1.5rem': 'space.negative.300',
57
+ '-2rem': 'space.negative.400',
58
+ '0.125rem': 'space.025',
59
+ '0.25rem': 'space.050',
60
+ '0.375rem': 'space.075',
61
+ '0.5rem': 'space.100',
62
+ '0.75rem': 'space.150',
63
+ '1rem': 'space.200',
64
+ '1.25rem': 'space.250',
65
+ '1.5rem': 'space.300',
66
+ '2rem': 'space.400',
67
+ '2.5rem': 'space.500',
68
+ '3rem': 'space.600',
69
+ '4rem': 'space.800',
70
+ '5rem': 'space.1000',
71
+ '-0.125em': 'space.negative.025',
72
+ '-0.25em': 'space.negative.050',
73
+ '-0.375em': 'space.negative.075',
74
+ '-0.5em': 'space.negative.100',
75
+ '-0.75em': 'space.negative.150',
76
+ '-1em': 'space.negative.200',
77
+ '-1.25em': 'space.negative.250',
78
+ '-1.5em': 'space.negative.300',
79
+ '-2em': 'space.negative.400',
80
+ '0.125em': 'space.025',
81
+ '0.25em': 'space.050',
82
+ '0.375em': 'space.075',
83
+ '0.5em': 'space.100',
84
+ '0.75em': 'space.150',
85
+ '1em': 'space.200',
86
+ '1.25em': 'space.250',
87
+ '1.5em': 'space.300',
88
+ '2em': 'space.400',
89
+ '2.5em': 'space.500',
90
+ '3em': 'space.600',
91
+ '4em': 'space.800',
92
+ '5em': 'space.1000'
93
+ };
94
+ export const styleMap = {
95
+ 'column-gap': tokenMap,
96
+ columnGap: tokenMap,
97
+ gap: tokenMap,
98
+ 'grid-column-gap': tokenMap,
99
+ 'grid-row-gap': tokenMap,
100
+ gridColumnGap: tokenMap,
101
+ gridRowGap: tokenMap,
102
+ 'margin-block-end': tokenMap,
103
+ 'margin-block-start': tokenMap,
104
+ 'margin-block': tokenMap,
105
+ 'margin-bottom': tokenMap,
106
+ 'margin-inline-end': tokenMap,
107
+ 'margin-inline-start': tokenMap,
108
+ 'margin-inline': tokenMap,
109
+ 'margin-left': tokenMap,
110
+ 'margin-right': tokenMap,
111
+ 'margin-top': tokenMap,
112
+ 'outline-offset': tokenMap,
113
+ outlineOffset: tokenMap,
114
+ 'padding-block-end': tokenMap,
115
+ 'padding-block-start': tokenMap,
116
+ 'padding-block': tokenMap,
117
+ 'padding-bottom': tokenMap,
118
+ 'padding-inline-end': tokenMap,
119
+ 'padding-inline-start': tokenMap,
120
+ 'padding-inline': tokenMap,
121
+ 'padding-left': tokenMap,
122
+ 'padding-right': tokenMap,
123
+ 'padding-top': tokenMap,
124
+ 'row-gap': tokenMap,
125
+ rowGap: tokenMap,
126
+ margin: tokenMap,
127
+ marginBlock: tokenMap,
128
+ marginBlockEnd: tokenMap,
129
+ marginBlockStart: tokenMap,
130
+ marginBottom: tokenMap,
131
+ marginInline: tokenMap,
132
+ marginInlineEnd: tokenMap,
133
+ marginInlineStart: tokenMap,
134
+ marginLeft: tokenMap,
135
+ marginRight: tokenMap,
136
+ marginTop: tokenMap,
137
+ padding: tokenMap,
138
+ paddingBlock: tokenMap,
139
+ paddingBlockEnd: tokenMap,
140
+ paddingBlockStart: tokenMap,
141
+ paddingBottom: tokenMap,
142
+ paddingInline: tokenMap,
143
+ paddingInlineEnd: tokenMap,
144
+ paddingInlineStart: tokenMap,
145
+ paddingLeft: tokenMap,
146
+ paddingRight: tokenMap,
147
+ paddingTop: tokenMap
148
+ // bottom: tokenMap,
149
+ // left: tokenMap,
150
+ // right: tokenMap,
151
+ // top: tokenMap,
152
+ };
@@ -0,0 +1,8 @@
1
+ export default {
2
+ values: {
3
+ ignore: ['auto', 'initial', 'inherit', 'unset', 'revert', 'revert-layer', 'none',
4
+ // outline-offset can be set to none
5
+ // Currently the DST opinion is that 0 is valid. It doesn't need to be converted to `space.0`
6
+ 0, '0', '0px', '0em', '0rem']
7
+ }
8
+ };
@@ -0,0 +1,30 @@
1
+ import * as ast from '../../../../ast-nodes';
2
+
3
+ /**
4
+ * Currently this is defined here because it's not very general purpose.
5
+ * If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
6
+ * and the other half would be in `Import`.
7
+ *
8
+ * TODO: Refactor and move to `ast-nodes`
9
+ *
10
+ * Note: It does not handle default imports, namespace imports, or aliased imports.
11
+ */
12
+ export const upsertImportDeclaration = ({
13
+ module,
14
+ specifiers
15
+ }, context, fixer) => {
16
+ // Find any imports that match the packageName
17
+ const root = context.getSourceCode().ast.body;
18
+ const importDeclarations = ast.Root.findImportsByModule(root, module);
19
+
20
+ // The import doesn't exist yet, we can just insert a whole new one
21
+ if (importDeclarations.length === 0) {
22
+ return ast.Root.insertImport(root, {
23
+ module,
24
+ specifiers
25
+ }, fixer);
26
+ }
27
+
28
+ // The import exists so, modify the existing one
29
+ return ast.Import.insertNamedSpecifiers(importDeclarations[0], specifiers, fixer);
30
+ };
@@ -0,0 +1 @@
1
+ export { isStringOrNumber } from './is-string-or-number';
@@ -0,0 +1,3 @@
1
+ export const isStringOrNumber = value => {
2
+ return typeof value === 'string' || typeof value === 'number';
3
+ };
@@ -1,3 +1,10 @@
1
+ // This should be kept in sync with
2
+ // packages/design-system/eslint-plugin-ui-styling-standard/src/rules/utils/is-supported-import.tsx
3
+ // whenever possible.
4
+ //
5
+ // TODO: would having an @atlassian/eslint-plugin-design-system-common
6
+ // package be useful?
7
+
1
8
  // eslint-disable-next-line import/no-extraneous-dependencies
2
9
 
3
10
  export const CSS_IN_JS_IMPORTS = {
@@ -109,8 +116,14 @@ export const isCssMap = isSupportedImportWrapper('cssMap');
109
116
  export const isKeyframes = isSupportedImportWrapper('keyframes');
110
117
  // `styled` is also the explicit default of `styled-components` and `@emotion/styled`, so we also match on default imports generally
111
118
  export const isStyled = isSupportedImportWrapper('styled', ['styled-components', '@emotion/styled']);
112
- export const isImportedFrom = (moduleName, exactMatch = true) => (nodeToCheck, referencesInScope, importSources) => {
113
- if (!importSources.some(importSource => importSource === moduleName || !exactMatch && importSource.startsWith(moduleName))) {
119
+ export const isXcss = isSupportedImportWrapper('xcss');
120
+ export const isImportedFrom = (moduleName, exactMatch = true) => (nodeToCheck, referencesInScope,
121
+ /**
122
+ * If we strictly have specific import sources in the config scope, pass them to make this more performant.
123
+ * Pass `null` if you don't care if its configured or not.
124
+ */
125
+ importSources = null) => {
126
+ if (importSources && !importSources.some(importSource => importSource === moduleName || !exactMatch && importSource.startsWith(moduleName))) {
114
127
  // Don't go through the trouble of checking the import sources does not include this
115
128
  // We'll assume this is skipped elsewhere.
116
129
  return false;
@@ -1,5 +1,40 @@
1
+ /* eslint-disable @repo/internal/react/require-jsdoc */
2
+
1
3
  import { isNodeOfType } from 'eslint-codemod-utils';
2
- var ObjectEntry = {
4
+ export var ObjectEntry = {
5
+ getProperty: function getProperty(node) {
6
+ if (isNodeOfType(node.key, 'Identifier')) {
7
+ return {
8
+ type: 'Identifier',
9
+ value: node.key.name
10
+ };
11
+ }
12
+ if (isNodeOfType(node.key, 'Literal') && node.key.value) {
13
+ return {
14
+ type: 'Literal',
15
+ value: node.key.value.toString()
16
+ };
17
+ }
18
+ return {
19
+ type: undefined,
20
+ value: undefined
21
+ };
22
+ },
23
+ getValue: function getValue(node) {
24
+ // The value is a number, like `-3`
25
+ if (isNodeOfType(node.value, 'UnaryExpression') && isNodeOfType(node.value.argument, 'Literal') && node.value.argument.raw) {
26
+ if (node.value.operator === '-') {
27
+ return -1 * Number.parseInt(node.value.argument.raw);
28
+ }
29
+ return Number.parseInt(node.value.argument.raw);
30
+ }
31
+
32
+ // The value is a string, like `'4px'`
33
+ if (isNodeOfType(node.value, 'Literal') && node.value.value) {
34
+ return node.value.value;
35
+ }
36
+ return undefined;
37
+ },
3
38
  deleteEntry: function deleteEntry(node, context, fixer) {
4
39
  var _lastToken;
5
40
  // context.getSourceCode() is deprecated in favour of context.sourceCode, however this returns undefined for some reason
@@ -31,5 +66,4 @@ var ObjectEntry = {
31
66
  return node.key.name;
32
67
  }
33
68
  }
34
- };
35
- export { ObjectEntry };
69
+ };
@@ -99,6 +99,18 @@ var ASTObjectExpression = {
99
99
  key: identifier(key),
100
100
  value: literal(value)
101
101
  }).toString(), ", "));
102
+ },
103
+ recurse: function recurse(node, callback) {
104
+ node.properties.forEach(function (entry) {
105
+ // Call the callback first, in case the user wants to do something with SpreadElements
106
+ callback(entry);
107
+ if (!isNodeOfType(entry, 'Property')) {
108
+ return;
109
+ }
110
+ if (isNodeOfType(entry.value, 'ObjectExpression')) {
111
+ ASTObjectExpression.recurse(entry.value, callback);
112
+ }
113
+ });
102
114
  }
103
115
  };
104
116
  export { ASTObjectExpression as Object };
@@ -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::d90c2cf5e100daf98915f9467f2e5663>>
3
+ * @codegen <<SignedSource::d95217b658f807294de3c81123068bf1>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  export default {
@@ -35,6 +35,7 @@ export default {
35
35
  '@atlaskit/design-system/use-href-in-link-item': 'warn',
36
36
  '@atlaskit/design-system/use-primitives': 'warn',
37
37
  '@atlaskit/design-system/use-primitives-text': 'warn',
38
+ '@atlaskit/design-system/use-tokens-space': 'error',
38
39
  '@atlaskit/design-system/use-tokens-typography': 'warn',
39
40
  '@atlaskit/design-system/use-visually-hidden': 'error'
40
41
  }
@@ -1,4 +1,3 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
3
  import _createClass from "@babel/runtime/helpers/createClass";
@@ -33,6 +32,18 @@ var getProgramNode = function getProgramNode(expression) {
33
32
  }
34
33
  return expression.parent;
35
34
  };
35
+ var isDeclaredInsideComponent = function isDeclaredInsideComponent(expression) {
36
+ // These nodes imply that there is a distinct own scope (function scope / block scope),
37
+ // and so the presence of them means that expression was not defined in the module scope.
38
+ var NOT_MODULE_SCOPE = ['ArrowFunctionExpression', 'BlockStatement', 'ClassDeclaration', 'FunctionExpression'];
39
+ while (expression.type !== 'Program') {
40
+ if (NOT_MODULE_SCOPE.includes(expression.type)) {
41
+ return true;
42
+ }
43
+ expression = expression.parent;
44
+ }
45
+ return false;
46
+ };
36
47
  var JSXExpressionLinter = /*#__PURE__*/function () {
37
48
  // File-level tracking of styles hoisted from the cssAtTopOfModule/cssAtBottomOfModule fixers.
38
49
 
@@ -112,13 +123,13 @@ var JSXExpressionLinter = /*#__PURE__*/function () {
112
123
  });
113
124
  return;
114
125
  }
115
- if (identifier.parent.parent.parent.type !== 'Program') {
126
+ if (isDeclaredInsideComponent(identifier)) {
116
127
  // When variable is declared inside the component
117
128
  this.context.report({
118
129
  node: sourceIdentifier,
119
130
  messageId: this.configuration.stylesPlacement === 'bottom' ? 'cssAtBottomOfModule' : 'cssAtTopOfModule',
120
131
  fix: function fix(fixer) {
121
- if (_this.configuration.fixNamesOnly) {
132
+ if (!_this.configuration.autoFix) {
122
133
  return [];
123
134
  }
124
135
  return _this.fixCssNotInModuleScope(fixer, identifier, false);
@@ -140,7 +151,7 @@ var JSXExpressionLinter = /*#__PURE__*/function () {
140
151
  node: identifier,
141
152
  messageId: 'cssObjectTypeOnly',
142
153
  fix: function fix(fixer) {
143
- if (_this.configuration.fixNamesOnly) {
154
+ if (!_this.configuration.autoFix) {
144
155
  return [];
145
156
  }
146
157
  return _this.addCssFunctionCall(fixer, identifier.parent);
@@ -316,10 +327,11 @@ var JSXExpressionLinter = /*#__PURE__*/function () {
316
327
  // The last value is the bottom of the file
317
328
  fixerNodePlacement = programNode.body[programNode.body.length - 1];
318
329
  } else {
330
+ var _ref3;
319
331
  // Place after the last ImportDeclaration
320
- fixerNodePlacement = programNode.body.length === 1 ? programNode.body[0] : programNode.body.find(function (node) {
332
+ fixerNodePlacement = (_ref3 = programNode.body.length === 1 ? programNode.body[0] : programNode.body.find(function (node) {
321
333
  return node.type !== 'ImportDeclaration';
322
- });
334
+ })) !== null && _ref3 !== void 0 ? _ref3 : fixerNodePlacement;
323
335
  }
324
336
  var moduleString;
325
337
  var fixes = [];
@@ -403,7 +415,7 @@ var JSXExpressionLinter = /*#__PURE__*/function () {
403
415
  node: expression,
404
416
  messageId: this.configuration.stylesPlacement === 'bottom' ? 'cssAtBottomOfModule' : 'cssAtTopOfModule',
405
417
  fix: function fix(fixer) {
406
- if (_this3.configuration.fixNamesOnly) {
418
+ if (!_this3.configuration.autoFix) {
407
419
  return [];
408
420
  }
409
421
 
@@ -448,8 +460,7 @@ var defaultConfig = {
448
460
  cssImportSource: CSS_IN_JS_IMPORTS.compiled,
449
461
  xcssImportSource: CSS_IN_JS_IMPORTS.atlaskitPrimitives,
450
462
  excludeReactComponents: false,
451
- fixNamesOnly: false,
452
- autoFixNames: true
463
+ autoFix: true
453
464
  };
454
465
  var rule = createLintRule({
455
466
  meta: {
@@ -468,8 +479,7 @@ var rule = createLintRule({
468
479
  cssObjectTypeOnly: "Create styles using objects passed to a css function call, e.g. `css({ textAlign: 'center'; })`.",
469
480
  cssInModule: "Imported styles should not be used; instead define in the module, import a component, or use a design token.",
470
481
  cssArrayStylesOnly: "Compose styles with an array on the css prop instead of using object spread.",
471
- noMemberExpressions: "Styles should be a regular variable (e.g. 'buttonStyles'), not a member of an object (e.g. 'myObject.styles').",
472
- shouldEndInStyles: 'Declared styles should end in "styles".'
482
+ noMemberExpressions: "Styles should be a regular variable (e.g. 'buttonStyles'), not a member of an object (e.g. 'myObject.styles')."
473
483
  },
474
484
  schema: [{
475
485
  type: 'object',
@@ -493,10 +503,7 @@ var rule = createLintRule({
493
503
  excludeReactComponents: {
494
504
  type: 'boolean'
495
505
  },
496
- autoFixNames: {
497
- type: 'boolean'
498
- },
499
- fixNamesOnly: {
506
+ autoFix: {
500
507
  type: 'boolean'
501
508
  }
502
509
  },
@@ -504,80 +511,41 @@ var rule = createLintRule({
504
511
  }]
505
512
  },
506
513
  create: function create(context) {
507
- var _ref3;
508
514
  var mergedConfig = assign({}, defaultConfig, context.options[0]);
509
- var declarationSuffix = 'Styles';
510
- var callSelectorFunctions = [].concat(_toConsumableArray(mergedConfig.cssFunctions), ['cssMap']);
511
- var callSelector = callSelectorFunctions.map(function (fn) {
512
- return "CallExpression[callee.name=".concat(fn, "]");
513
- }).join(',');
514
- return _ref3 = {}, _defineProperty(_ref3, callSelector, function (node) {
515
- if (node.parent.type !== 'VariableDeclarator') {
516
- // We aren't interested in these that don't have a parent.
517
- return;
518
- }
519
- var identifier = node.parent.id;
520
- if (identifier.type === 'Identifier' && (identifier.name.endsWith(declarationSuffix) || identifier.name.startsWith(declarationSuffix.toLowerCase()) || identifier.name === declarationSuffix.toLowerCase())) {
521
- // Already prefixed! Nothing to do.
522
- return;
523
- }
524
- if (!mergedConfig.autoFixNames) {
525
- return;
526
- }
527
- context.report({
528
- node: identifier,
529
- messageId: 'shouldEndInStyles',
530
- fix: function fix(fixer) {
531
- var _context$getScope$var;
532
- var identifierName = identifier.type === 'Identifier' ? identifier.name : '';
533
- var references = ((_context$getScope$var = context.getScope().variables.find(function (varb) {
534
- return varb.name === identifierName;
535
- })) === null || _context$getScope$var === void 0 ? void 0 : _context$getScope$var.references) || [];
536
- var newIdentifierName = "".concat(identifierName
537
- // Remove "Style" if it is already defined.
538
- .replace(/Style$/, '')).concat(declarationSuffix);
539
- return references.filter(function (ref) {
540
- return ref.identifier.name === identifierName;
541
- }).map(function (ref) {
542
- if (ref.identifier.parent && ref.identifier.parent.shorthand) {
543
- return fixer.replaceText(ref.identifier, "".concat(identifierName, ": ").concat(newIdentifierName));
544
- }
545
- return fixer.replaceText(ref.identifier, newIdentifierName);
546
- });
547
- }
548
- });
549
- }), _defineProperty(_ref3, "JSXAttribute", function JSXAttribute(nodeOriginal) {
550
- var node = nodeOriginal;
551
- var name = node.name,
552
- value = node.value;
553
- if (mergedConfig.excludeReactComponents && node.parent.type === 'JSXOpeningElement') {
554
- // e.g. <item.before />
555
- if (node.parent.name.type === 'JSXMemberExpression') {
556
- return;
557
- }
558
- // e.g. <div />, <MenuItem />
559
- if (node.parent.name.type === 'JSXIdentifier' && !isDOMElementName(node.parent.name.name)) {
560
- return;
561
- }
562
- }
563
- if (name.type === 'JSXIdentifier' && mergedConfig.cssFunctions.includes(name.name)) {
564
- // When not a jsx expression. For eg. css=""
565
- if ((value === null || value === void 0 ? void 0 : value.type) !== 'JSXExpressionContainer') {
566
- context.report({
567
- node: node,
568
- messageId: mergedConfig.stylesPlacement === 'bottom' ? 'cssAtBottomOfModule' : 'cssAtTopOfModule'
569
- });
570
- return;
515
+ return {
516
+ JSXAttribute: function JSXAttribute(nodeOriginal) {
517
+ var node = nodeOriginal;
518
+ var name = node.name,
519
+ value = node.value;
520
+ if (mergedConfig.excludeReactComponents && node.parent.type === 'JSXOpeningElement') {
521
+ // e.g. <item.before />
522
+ if (node.parent.name.type === 'JSXMemberExpression') {
523
+ return;
524
+ }
525
+ // e.g. <div />, <MenuItem />
526
+ if (node.parent.name.type === 'JSXIdentifier' && !isDOMElementName(node.parent.name.name)) {
527
+ return;
528
+ }
571
529
  }
572
- if (value.expression.type === 'JSXEmptyExpression') {
573
- // e.g. the comment in
574
- // <div css={/* Hello there */} />
575
- return;
530
+ if (name.type === 'JSXIdentifier' && mergedConfig.cssFunctions.includes(name.name)) {
531
+ // When not a jsx expression. For eg. css=""
532
+ if ((value === null || value === void 0 ? void 0 : value.type) !== 'JSXExpressionContainer') {
533
+ context.report({
534
+ node: node,
535
+ messageId: mergedConfig.stylesPlacement === 'bottom' ? 'cssAtBottomOfModule' : 'cssAtTopOfModule'
536
+ });
537
+ return;
538
+ }
539
+ if (value.expression.type === 'JSXEmptyExpression') {
540
+ // e.g. the comment in
541
+ // <div css={/* Hello there */} />
542
+ return;
543
+ }
544
+ var linter = new JSXExpressionLinter(context, name.name, mergedConfig, value.expression);
545
+ linter.run();
576
546
  }
577
- var linter = new JSXExpressionLinter(context, name.name, mergedConfig, value.expression);
578
- linter.run();
579
547
  }
580
- }), _ref3;
548
+ };
581
549
  }
582
550
  });
583
551
  export default rule;
@@ -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::c283cd7ede5e813a9119cd707d339273>>
3
+ * @codegen <<SignedSource::d1c25758089a050334359276ede0ca3a>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import consistentCssPropUsage from './consistent-css-prop-usage';
@@ -32,6 +32,7 @@ import useHeadingLevelInSpotlightCard from './use-heading-level-in-spotlight-car
32
32
  import useHrefInLinkItem from './use-href-in-link-item';
33
33
  import usePrimitives from './use-primitives';
34
34
  import usePrimitivesText from './use-primitives-text';
35
+ import useTokensSpace from './use-tokens-space';
35
36
  import useTokensTypography from './use-tokens-typography';
36
37
  import useVisuallyHidden from './use-visually-hidden';
37
38
  export default {
@@ -64,6 +65,7 @@ export default {
64
65
  'use-href-in-link-item': useHrefInLinkItem,
65
66
  'use-primitives': usePrimitives,
66
67
  'use-primitives-text': usePrimitivesText,
68
+ 'use-tokens-space': useTokensSpace,
67
69
  'use-tokens-typography': useTokensTypography,
68
70
  'use-visually-hidden': useVisuallyHidden
69
71
  };
@@ -0,0 +1,48 @@
1
+ import { createLintRule } from '../utils/create-rule';
2
+ import { StyleProperty } from './transformers';
3
+ var rule = createLintRule({
4
+ meta: {
5
+ name: 'use-tokens-space',
6
+ type: 'problem',
7
+ fixable: 'code',
8
+ hasSuggestions: true,
9
+ docs: {
10
+ description: 'Enforces usage of space design tokens rather than hard-coded values.',
11
+ recommended: false,
12
+ severity: 'error'
13
+ },
14
+ messages: {
15
+ noRawSpacingValues: 'The use of spacing primitives or tokens is preferred over the direct application of spacing properties.'
16
+ }
17
+ },
18
+ create: function create(context) {
19
+ return {
20
+ 'CallExpression[callee.name="css"] ObjectExpression Property': function CallExpressionCalleeNameCssObjectExpressionProperty(node) {
21
+ return StyleProperty.lint(node, {
22
+ context: context
23
+ });
24
+ },
25
+ 'CallExpression[callee.name="keyframes"] ObjectExpression Property': function CallExpressionCalleeNameKeyframesObjectExpressionProperty(node) {
26
+ return StyleProperty.lint(node, {
27
+ context: context
28
+ });
29
+ },
30
+ 'CallExpression[callee.name="cssMap"] ObjectExpression Property': function CallExpressionCalleeNameCssMapObjectExpressionProperty(node) {
31
+ return StyleProperty.lint(node, {
32
+ context: context
33
+ });
34
+ },
35
+ 'CallExpression[callee.object.name=styled] ObjectExpression Property': function CallExpressionCalleeObjectNameStyledObjectExpressionProperty(node) {
36
+ return StyleProperty.lint(node, {
37
+ context: context
38
+ });
39
+ },
40
+ 'CallExpression[callee.object.name=styled2] ObjectExpression Property': function CallExpressionCalleeObjectNameStyled2ObjectExpressionProperty(node) {
41
+ return StyleProperty.lint(node, {
42
+ context: context
43
+ });
44
+ }
45
+ };
46
+ }
47
+ });
48
+ export default rule;
@@ -0,0 +1 @@
1
+ export { StyleProperty } from './style-property';