@atlaskit/eslint-plugin-design-system 8.23.2 → 8.23.4

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 (155) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +1 -0
  3. package/constellation/index/usage.mdx +39 -0
  4. package/dist/cjs/ast-nodes/index.js +7 -0
  5. package/dist/cjs/ast-nodes/object.js +84 -0
  6. package/dist/cjs/presets/all.codegen.js +2 -1
  7. package/dist/cjs/presets/recommended.codegen.js +2 -1
  8. package/dist/cjs/rules/consistent-css-prop-usage/index.js +25 -5
  9. package/dist/cjs/rules/index.codegen.js +3 -1
  10. package/dist/cjs/rules/local-cx-xcss/index.js +51 -0
  11. package/dist/cjs/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.js +3 -1
  12. package/dist/cjs/rules/no-css-tagged-template-expression/index.js +2 -2
  13. package/dist/cjs/rules/use-primitives/index.js +4 -30
  14. package/dist/cjs/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.js +39 -0
  15. package/dist/cjs/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.js +44 -0
  16. package/dist/cjs/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.js +5 -2
  17. package/dist/cjs/rules/use-primitives/transformers/compiled-styled/index.js +117 -0
  18. package/dist/cjs/rules/use-primitives/transformers/compiled-styled/supported.js +10 -0
  19. package/dist/cjs/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +37 -0
  20. package/dist/cjs/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +27 -0
  21. package/dist/cjs/rules/use-primitives/transformers/emotion-css/index.js +4 -47
  22. package/dist/cjs/rules/use-primitives/transformers/emotion-css/supported.js +2 -44
  23. package/dist/cjs/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +37 -0
  24. package/dist/cjs/rules/use-primitives/transformers/index.js +10 -10
  25. package/dist/cjs/rules/use-primitives/utils/index.js +1 -43
  26. package/dist/cjs/rules/utils/is-supported-import.js +61 -0
  27. package/dist/es2019/ast-nodes/index.js +1 -0
  28. package/dist/es2019/ast-nodes/object.js +79 -0
  29. package/dist/es2019/presets/all.codegen.js +2 -1
  30. package/dist/es2019/presets/recommended.codegen.js +2 -1
  31. package/dist/es2019/rules/consistent-css-prop-usage/index.js +23 -5
  32. package/dist/es2019/rules/index.codegen.js +3 -1
  33. package/dist/es2019/rules/local-cx-xcss/index.js +45 -0
  34. package/dist/es2019/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.js +3 -1
  35. package/dist/es2019/rules/no-css-tagged-template-expression/index.js +2 -2
  36. package/dist/es2019/rules/use-primitives/index.js +4 -30
  37. package/dist/es2019/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.js +29 -0
  38. package/dist/es2019/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.js +37 -0
  39. package/dist/es2019/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.js +2 -2
  40. package/dist/es2019/rules/use-primitives/transformers/compiled-styled/index.js +107 -0
  41. package/dist/es2019/rules/use-primitives/transformers/compiled-styled/supported.js +4 -0
  42. package/dist/es2019/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +30 -0
  43. package/dist/es2019/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +19 -0
  44. package/dist/es2019/rules/use-primitives/transformers/emotion-css/index.js +4 -48
  45. package/dist/es2019/rules/use-primitives/transformers/emotion-css/supported.js +1 -43
  46. package/dist/es2019/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +30 -0
  47. package/dist/es2019/rules/use-primitives/transformers/index.js +2 -2
  48. package/dist/es2019/rules/use-primitives/utils/index.js +1 -7
  49. package/dist/es2019/rules/utils/is-supported-import.js +52 -0
  50. package/dist/esm/ast-nodes/index.js +1 -0
  51. package/dist/esm/ast-nodes/object.js +79 -0
  52. package/dist/esm/presets/all.codegen.js +2 -1
  53. package/dist/esm/presets/recommended.codegen.js +2 -1
  54. package/dist/esm/rules/consistent-css-prop-usage/index.js +25 -5
  55. package/dist/esm/rules/index.codegen.js +3 -1
  56. package/dist/esm/rules/local-cx-xcss/index.js +45 -0
  57. package/dist/esm/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.js +3 -1
  58. package/dist/esm/rules/no-css-tagged-template-expression/index.js +2 -2
  59. package/dist/esm/rules/use-primitives/index.js +4 -30
  60. package/dist/esm/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.js +30 -0
  61. package/dist/esm/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.js +38 -0
  62. package/dist/esm/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.js +2 -2
  63. package/dist/esm/rules/use-primitives/transformers/compiled-styled/index.js +107 -0
  64. package/dist/esm/rules/use-primitives/transformers/compiled-styled/supported.js +4 -0
  65. package/dist/esm/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +29 -0
  66. package/dist/esm/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +19 -0
  67. package/dist/esm/rules/use-primitives/transformers/emotion-css/index.js +4 -47
  68. package/dist/esm/rules/use-primitives/transformers/emotion-css/supported.js +1 -43
  69. package/dist/esm/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +29 -0
  70. package/dist/esm/rules/use-primitives/transformers/index.js +2 -2
  71. package/dist/esm/rules/use-primitives/utils/index.js +1 -7
  72. package/dist/esm/rules/utils/is-supported-import.js +54 -0
  73. package/dist/types/ast-nodes/index.d.ts +1 -0
  74. package/dist/types/ast-nodes/object.d.ts +39 -0
  75. package/dist/types/index.codegen.d.ts +2 -0
  76. package/dist/types/presets/all.codegen.d.ts +2 -1
  77. package/dist/types/presets/recommended.codegen.d.ts +2 -1
  78. package/dist/types/rules/index.codegen.d.ts +1 -0
  79. package/dist/types/rules/local-cx-xcss/index.d.ts +3 -0
  80. package/dist/types/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.d.ts +3 -4
  81. package/dist/types/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.d.ts +17 -0
  82. package/dist/types/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.d.ts +17 -0
  83. package/dist/types/rules/use-primitives/transformers/compiled-styled/index.d.ts +25 -0
  84. package/dist/types/rules/use-primitives/transformers/compiled-styled/supported.d.ts +2 -0
  85. package/dist/types/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.d.ts +14 -0
  86. package/dist/types/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.d.ts +7 -0
  87. package/dist/types/rules/use-primitives/transformers/emotion-css/index.d.ts +0 -19
  88. package/dist/types/rules/use-primitives/transformers/emotion-css/supported.d.ts +0 -7
  89. package/dist/types/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.d.ts +14 -0
  90. package/dist/types/rules/use-primitives/transformers/index.d.ts +2 -2
  91. package/dist/types/rules/use-primitives/utils/index.d.ts +0 -6
  92. package/dist/types/rules/utils/is-supported-import.d.ts +16 -0
  93. package/dist/types-ts4.5/ast-nodes/index.d.ts +1 -0
  94. package/dist/types-ts4.5/ast-nodes/object.d.ts +39 -0
  95. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  96. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  97. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
  98. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  99. package/dist/types-ts4.5/rules/local-cx-xcss/index.d.ts +3 -0
  100. package/dist/types-ts4.5/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.d.ts +3 -4
  101. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.d.ts +17 -0
  102. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.d.ts +17 -0
  103. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/index.d.ts +25 -0
  104. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/supported.d.ts +2 -0
  105. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.d.ts +14 -0
  106. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.d.ts +7 -0
  107. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/index.d.ts +0 -19
  108. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/supported.d.ts +0 -7
  109. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.d.ts +14 -0
  110. package/dist/types-ts4.5/rules/use-primitives/transformers/index.d.ts +2 -2
  111. package/dist/types-ts4.5/rules/use-primitives/utils/index.d.ts +0 -6
  112. package/dist/types-ts4.5/rules/utils/is-supported-import.d.ts +16 -0
  113. package/package.json +1 -1
  114. package/dist/cjs/rules/no-css-tagged-template-expression/is-supported-import.js +0 -29
  115. package/dist/cjs/rules/use-primitives/transformers/jsx-element-to-box.js +0 -26
  116. package/dist/cjs/rules/use-primitives/transformers/styled-component-to-primitive.js +0 -68
  117. package/dist/cjs/rules/use-primitives/utils/contains-only-supported-attrs.js +0 -19
  118. package/dist/cjs/rules/use-primitives/utils/is-valid-tag-name.js +0 -13
  119. package/dist/cjs/rules/use-primitives/utils/update-jsx-element-name.js +0 -16
  120. package/dist/cjs/rules/use-primitives/utils/upsert-import-declaration.js +0 -80
  121. package/dist/es2019/rules/no-css-tagged-template-expression/is-supported-import.js +0 -21
  122. package/dist/es2019/rules/use-primitives/transformers/jsx-element-to-box.js +0 -16
  123. package/dist/es2019/rules/use-primitives/transformers/styled-component-to-primitive.js +0 -59
  124. package/dist/es2019/rules/use-primitives/utils/contains-only-supported-attrs.js +0 -13
  125. package/dist/es2019/rules/use-primitives/utils/is-valid-tag-name.js +0 -7
  126. package/dist/es2019/rules/use-primitives/utils/update-jsx-element-name.js +0 -12
  127. package/dist/es2019/rules/use-primitives/utils/upsert-import-declaration.js +0 -76
  128. package/dist/esm/rules/no-css-tagged-template-expression/is-supported-import.js +0 -23
  129. package/dist/esm/rules/use-primitives/transformers/jsx-element-to-box.js +0 -19
  130. package/dist/esm/rules/use-primitives/transformers/styled-component-to-primitive.js +0 -61
  131. package/dist/esm/rules/use-primitives/utils/contains-only-supported-attrs.js +0 -13
  132. package/dist/esm/rules/use-primitives/utils/is-valid-tag-name.js +0 -7
  133. package/dist/esm/rules/use-primitives/utils/update-jsx-element-name.js +0 -10
  134. package/dist/esm/rules/use-primitives/utils/upsert-import-declaration.js +0 -75
  135. package/dist/types/rules/no-css-tagged-template-expression/is-supported-import.d.ts +0 -12
  136. package/dist/types/rules/use-primitives/transformers/jsx-element-to-box.d.ts +0 -3
  137. package/dist/types/rules/use-primitives/transformers/styled-component-to-primitive.d.ts +0 -13
  138. package/dist/types/rules/use-primitives/utils/contains-only-supported-attrs.d.ts +0 -2
  139. package/dist/types/rules/use-primitives/utils/is-valid-tag-name.d.ts +0 -3
  140. package/dist/types/rules/use-primitives/utils/update-jsx-element-name.d.ts +0 -3
  141. package/dist/types/rules/use-primitives/utils/upsert-import-declaration.d.ts +0 -11
  142. package/dist/types-ts4.5/rules/no-css-tagged-template-expression/is-supported-import.d.ts +0 -12
  143. package/dist/types-ts4.5/rules/use-primitives/transformers/jsx-element-to-box.d.ts +0 -3
  144. package/dist/types-ts4.5/rules/use-primitives/transformers/styled-component-to-primitive.d.ts +0 -13
  145. package/dist/types-ts4.5/rules/use-primitives/utils/contains-only-supported-attrs.d.ts +0 -2
  146. package/dist/types-ts4.5/rules/use-primitives/utils/is-valid-tag-name.d.ts +0 -3
  147. package/dist/types-ts4.5/rules/use-primitives/utils/update-jsx-element-name.d.ts +0 -3
  148. package/dist/types-ts4.5/rules/use-primitives/utils/upsert-import-declaration.d.ts +0 -11
  149. /package/dist/cjs/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.js +0 -0
  150. /package/dist/es2019/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.js +0 -0
  151. /package/dist/esm/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.js +0 -0
  152. /package/dist/types/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.d.ts +0 -0
  153. /package/dist/types/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.d.ts +0 -0
  154. /package/dist/types-ts4.5/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.d.ts +0 -0
  155. /package/dist/types-ts4.5/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.d.ts +0 -0
@@ -0,0 +1,19 @@
1
+ import { isNodeOfType } from 'eslint-codemod-utils';
2
+ import * as ast from '../../../../ast-nodes';
3
+ import * as supported from './supported';
4
+
5
+ /**
6
+ * Check that every attribute in the JSXElement is something we support.
7
+ * We do this via a whitelist in `this.attributes`. The result is we exclude
8
+ * dangerous attrs like `id` and `style`.
9
+ */
10
+ export var containsOnlySupportedAttrs = function containsOnlySupportedAttrs(node) {
11
+ var attrs = ast.JSXElement.getAttributes(node);
12
+ return attrs.every(function (attr) {
13
+ if (!isNodeOfType(attr, 'JSXAttribute')) {
14
+ return false;
15
+ }
16
+ var name = ast.JSXAttribute.getName(attr);
17
+ return supported.attributes.includes(name);
18
+ });
19
+ };
@@ -5,7 +5,9 @@ import { getIdentifierInParentScope, isNodeOfType } from 'eslint-codemod-utils';
5
5
  import * as ast from '../../../../ast-nodes';
6
6
  import { getVariableDefinitionValue, getVariableUsagesCount, isValidCssPropertiesToTransform } from '../../utils';
7
7
  import { cssToXcssTransformer } from '../css-to-xcss';
8
+ import { containsOnlySupportedAttrs } from './contains-only-supported-attrs';
8
9
  import * as supported from './supported';
10
+ import { upsertImportDeclaration } from './upsert-import-declaration';
9
11
  export var EmotionCSS = {
10
12
  lint: function lint(node, _ref) {
11
13
  var context = _ref.context,
@@ -53,7 +55,7 @@ export var EmotionCSS = {
53
55
  }
54
56
 
55
57
  // Ignore elements that contain dangerous attributes like `id`.
56
- if (!this._containsOnlySupportedAttributes(node)) {
58
+ if (!containsOnlySupportedAttrs(node)) {
57
59
  return false;
58
60
  }
59
61
 
@@ -95,10 +97,9 @@ export var EmotionCSS = {
95
97
  return true;
96
98
  },
97
99
  _fix: function _fix(node, _ref3) {
98
- var _this = this;
99
100
  var context = _ref3.context;
100
101
  return function (fixer) {
101
- var importFix = _this._upsertImportDeclaration({
102
+ var importFix = upsertImportDeclaration({
102
103
  module: '@atlaskit/primitives',
103
104
  specifiers: ['Box', 'xcss']
104
105
  }, context, fixer);
@@ -110,49 +111,5 @@ export var EmotionCSS = {
110
111
  return Boolean(fix);
111
112
  }); // Some of the transformers can return arrays with undefined, so filter them out
112
113
  };
113
- },
114
- /**
115
- * Check that every attribute in the JSXElement is something we support.
116
- * We do this via a whitelist in `this.attributes`. The result is we exclude
117
- * dangerous attrs like `id` and `style`.
118
- */
119
- _containsOnlySupportedAttributes: function _containsOnlySupportedAttributes(node) {
120
- var attrs = ast.JSXElement.getAttributes(node);
121
- return attrs.every(function (attr) {
122
- if (!isNodeOfType(attr, 'JSXAttribute')) {
123
- return false;
124
- }
125
- if (!isNodeOfType(attr.name, 'JSXIdentifier')) {
126
- return false;
127
- }
128
- return supported.attributes.includes(attr.name.name);
129
- });
130
- },
131
- /**
132
- * Currently this is defined here because it's not very general purpose.
133
- * If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
134
- * and the other half would be in `Import`.
135
- *
136
- * TODO: Refactor and move to `ast-nodes`
137
- *
138
- * Note: It does not handle default imports, namespace imports, or aliased imports.
139
- */
140
- _upsertImportDeclaration: function _upsertImportDeclaration(_ref4, context, fixer) {
141
- var module = _ref4.module,
142
- specifiers = _ref4.specifiers;
143
- // Find any imports that match the packageName
144
- var root = context.getSourceCode().ast.body;
145
- var importDeclarations = ast.Root.findImportsByModule(root, module);
146
-
147
- // The import doesn't exist yet, we can just insert a whole new one
148
- if (importDeclarations.length === 0) {
149
- return ast.Root.insertImport(root, {
150
- module: module,
151
- specifiers: specifiers
152
- }, fixer);
153
- }
154
-
155
- // The import exists so, modify the existing one
156
- return ast.Import.insertNamedSpecifiers(importDeclarations[0], specifiers, fixer);
157
114
  }
158
115
  };
@@ -1,46 +1,4 @@
1
1
  export var elements = ['div'];
2
2
  export var attributes = ['css'
3
3
  // 'data-testid'
4
- ];
5
-
6
- // TODO: https://product-fabric.atlassian.net/browse/DSP-16054
7
- var spaceTokenMap = {
8
- '0px': 'space.0',
9
- '2px': 'space.025',
10
- '4px': 'space.050',
11
- '6px': 'space.075',
12
- '8px': 'space.100',
13
- '12px': 'space.150',
14
- '16px': 'space.200',
15
- '20px': 'space.250',
16
- '24px': 'space.300',
17
- '32px': 'space.400',
18
- '40px': 'space.500',
19
- '48px': 'space.600',
20
- '64px': 'space.800',
21
- '80px': 'space.1000'
22
- };
23
- export var styles = {
24
- padding: spaceTokenMap,
25
- paddingBlock: spaceTokenMap,
26
- paddingBlockEnd: spaceTokenMap,
27
- paddingBlockStart: spaceTokenMap,
28
- paddingBottom: spaceTokenMap,
29
- paddingInline: spaceTokenMap,
30
- paddingInlineEnd: spaceTokenMap,
31
- paddingInlineStart: spaceTokenMap,
32
- paddingLeft: spaceTokenMap,
33
- paddingRight: spaceTokenMap,
34
- paddingTop: spaceTokenMap,
35
- margin: spaceTokenMap,
36
- marginBlock: spaceTokenMap,
37
- marginBlockEnd: spaceTokenMap,
38
- marginBlockStart: spaceTokenMap,
39
- marginBottom: spaceTokenMap,
40
- marginInline: spaceTokenMap,
41
- marginInlineEnd: spaceTokenMap,
42
- marginInlineStart: spaceTokenMap,
43
- marginLeft: spaceTokenMap,
44
- marginRight: spaceTokenMap,
45
- marginTop: spaceTokenMap
46
- };
4
+ ];
@@ -0,0 +1,29 @@
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 var upsertImportDeclaration = function upsertImportDeclaration(_ref, context, fixer) {
13
+ var module = _ref.module,
14
+ specifiers = _ref.specifiers;
15
+ // Find any imports that match the packageName
16
+ var root = context.getSourceCode().ast.body;
17
+ var importDeclarations = ast.Root.findImportsByModule(root, module);
18
+
19
+ // The import doesn't exist yet, we can just insert a whole new one
20
+ if (importDeclarations.length === 0) {
21
+ return ast.Root.insertImport(root, {
22
+ module: module,
23
+ specifiers: specifiers
24
+ }, fixer);
25
+ }
26
+
27
+ // The import exists so, modify the existing one
28
+ return ast.Import.insertNamedSpecifiers(importDeclarations[0], specifiers, fixer);
29
+ };
@@ -1,3 +1,3 @@
1
1
  export { cssToXcssTransformer, supportedStylesMap, spaceTokenMap } from './css-to-xcss';
2
- export { jsxElementToBoxTransformer } from './jsx-element-to-box';
3
- export { styledComponentToPrimitive } from './styled-component-to-primitive';
2
+ export { CompiledStyled } from './compiled-styled';
3
+ export { EmotionCSS } from './emotion-css';
@@ -1,7 +1,4 @@
1
- export { containsOnlySupportedAttrs } from './contains-only-supported-attrs';
2
1
  export { convertASTObjectExpressionToJSObject } from './convert-ast-object-expression-to-js-object';
3
- export { findValidJsxUsageToTransform } from './find-valid-jsx-usage-to-transform';
4
- export { findValidStyledComponentCall } from './find-valid-styled-component-call';
5
2
  export { getAttributeValueIdentifier } from './get-attribute-value-identifier';
6
3
  export { getFunctionArgumentAtPos } from './get-function-argument-at-pos';
7
4
  export { getJSXAttributeByName } from './get-jsx-attribute-by-name';
@@ -9,7 +6,4 @@ export { getVariableDefinitionValue } from './get-variable-definition-value';
9
6
  export { getVariableUsagesCount } from './get-variable-usage-count';
10
7
  export { isFunctionNamed } from './is-function-named';
11
8
  export { isValidCssPropertiesToTransform } from './is-valid-css-properties-to-transform';
12
- export { isValidTagName } from './is-valid-tag-name';
13
- export { updateJSXAttributeByName } from './update-jsx-attribute-by-name';
14
- export { updateJSXElementName } from './update-jsx-element-name';
15
- export { upsertImportDeclaration } from './upsert-import-declaration';
9
+ export { updateJSXAttributeByName } from './update-jsx-attribute-by-name';
@@ -0,0 +1,54 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
+
3
+ export var CSS_IN_JS_IMPORTS = {
4
+ compiled: '@compiled/react',
5
+ emotionReact: '@emotion/react',
6
+ emotionCore: '@emotion/core',
7
+ styledComponents: 'styled-components',
8
+ atlaskitCss: '@atlaskit/css'
9
+ };
10
+
11
+ // List of CSS-in-JS libraries an import of a valid css, cx, cssMap, etc.
12
+ // function might originate from, e.g. @compiled/react, @emotion/core.
13
+ var isSupportedImportWrapper = function isSupportedImportWrapper(functionName) {
14
+ // This will need to be extended to support default imports once we start
15
+ // checking cases like `import css from '@emotion/css'`
16
+ var checkDefinitionHasImport = function checkDefinitionHasImport(def, importSources) {
17
+ var _def$parent, _def$parent2;
18
+ return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && def.node.imported.name === functionName && ((_def$parent = def.parent) === null || _def$parent === void 0 ? void 0 : _def$parent.type) === 'ImportDeclaration' && importSources.includes((_def$parent2 = def.parent) === null || _def$parent2 === void 0 ? void 0 : _def$parent2.source.value);
19
+ };
20
+
21
+ /**
22
+ * Checks whether:
23
+ *
24
+ * 1. a function name `nodeToCheck` matches the name of the function we
25
+ * want to check for (e.g. `cx`, `css`, `cssMap`, or `keyframes`), and
26
+ * 2. whether `nodeToCheck` originates from one of the libraries listed
27
+ * in `importSources`.
28
+ *
29
+ * @param nodeToCheck the function callee we are checking (e.g. the `css` in `css()`)
30
+ * @param referencesInScope list of references that are in scope. We'll use this
31
+ * to check where the function callee is imported from.
32
+ * @param importSources list of libraries that we want to ensure `nodeToCheck`
33
+ * comes from
34
+ *
35
+ * @returns whether the above conditions are true
36
+ */
37
+ var isSupportedImport = function isSupportedImport(nodeToCheck, referencesInScope, importSources) {
38
+ return nodeToCheck.type === 'Identifier' && referencesInScope.some(function (reference) {
39
+ var _reference$resolved;
40
+ return reference.identifier === nodeToCheck && ((_reference$resolved = reference.resolved) === null || _reference$resolved === void 0 ? void 0 : _reference$resolved.defs.some(function (def) {
41
+ return checkDefinitionHasImport(def, importSources);
42
+ }));
43
+ });
44
+ };
45
+ return isSupportedImport;
46
+ };
47
+
48
+ // Unused functions have been commented out until we implement corresponding
49
+ // eslint rules which use them
50
+ //
51
+ export var isCss = isSupportedImportWrapper('css');
52
+ export var isCxFunction = isSupportedImportWrapper('cx');
53
+ // export const isCssMap = isLibraryImportWrapper('cssMap');
54
+ // export const isKeyframes = isLibraryImportWrapper('keyframes');
@@ -2,4 +2,5 @@ export { FunctionCall } from './function-call';
2
2
  export { Import } from './import';
3
3
  export { JSXAttribute } from './jsx-attribute';
4
4
  export { JSXElement } from './jsx-element';
5
+ export { Object } from './object';
5
6
  export { Root } from './root';
@@ -0,0 +1,39 @@
1
+ import type { Rule } from 'eslint';
2
+ import { ObjectExpression, Property } from 'eslint-codemod-utils';
3
+ declare const ASTObjectExpression: {
4
+ /**
5
+ * Returns `true` if an object contains a property with the specified name, `false` otherwise.
6
+ */
7
+ hasProperty(node: ObjectExpression, name: string): boolean;
8
+ /**
9
+ * Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`
10
+ */
11
+ getEntryByPropertyName(node: ObjectExpression, name: string): Property | undefined;
12
+ deleteEntry(node: ObjectExpression, name: string, fixer: Rule.RuleFixer): Rule.Fix[];
13
+ /**
14
+ * Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`
15
+ */
16
+ getProperty(node: ObjectExpression, name: string): Property['key'] | undefined;
17
+ /**
18
+ * Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`
19
+ *
20
+ * Values can be basically anything, so be careful with this
21
+ */
22
+ getValueByPropertyName(node: ObjectExpression, name: string): Property['value'] | undefined;
23
+ containsSpreadProps(node: ObjectExpression): boolean;
24
+ updateValue(node: ObjectExpression, propertyName: string, newValue: string, fixer: Rule.RuleFixer): Rule.Fix;
25
+ /**
26
+ * Appends a key-value pair to the end of an object. For example:
27
+ * ```
28
+ * ast.Object.appendEntry(
29
+ * node, // { padding: 'space.100' }
30
+ * key, // 'margin',
31
+ * value, // 'space.200'
32
+ * fixer,
33
+ * )
34
+ * ```
35
+ * Will result in `{ padding: 'space.100', margin: 'space.200'}`
36
+ */
37
+ appendEntry(node: ObjectExpression, key: string, value: string, fixer: Rule.RuleFixer): Rule.Fix;
38
+ };
39
+ export { ASTObjectExpression as Object };
@@ -7,6 +7,7 @@ export declare const configs: {
7
7
  '@atlaskit/design-system/ensure-design-token-usage': string;
8
8
  '@atlaskit/design-system/ensure-design-token-usage/preview': string;
9
9
  '@atlaskit/design-system/icon-label': string;
10
+ '@atlaskit/design-system/local-cx-xcss': string;
10
11
  '@atlaskit/design-system/no-banned-imports': string;
11
12
  '@atlaskit/design-system/no-css-tagged-template-expression': string;
12
13
  '@atlaskit/design-system/no-deprecated-apis': string;
@@ -33,6 +34,7 @@ export declare const configs: {
33
34
  '@atlaskit/design-system/consistent-css-prop-usage': string;
34
35
  '@atlaskit/design-system/ensure-design-token-usage': string;
35
36
  '@atlaskit/design-system/icon-label': string;
37
+ '@atlaskit/design-system/local-cx-xcss': string;
36
38
  '@atlaskit/design-system/no-banned-imports': string;
37
39
  '@atlaskit/design-system/no-deprecated-apis': string;
38
40
  '@atlaskit/design-system/no-deprecated-design-token-usage': string;
@@ -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::d1a459e1ea71650f65b2890dc86cc398>>
3
+ * @codegen <<SignedSource::5026ba2cb55b3c1bcacbfe7fb7728a6c>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -10,6 +10,7 @@ declare const _default: {
10
10
  '@atlaskit/design-system/ensure-design-token-usage': string;
11
11
  '@atlaskit/design-system/ensure-design-token-usage/preview': string;
12
12
  '@atlaskit/design-system/icon-label': string;
13
+ '@atlaskit/design-system/local-cx-xcss': string;
13
14
  '@atlaskit/design-system/no-banned-imports': string;
14
15
  '@atlaskit/design-system/no-css-tagged-template-expression': string;
15
16
  '@atlaskit/design-system/no-deprecated-apis': string;
@@ -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::3b93cfbbe0ea14514b9600509632394b>>
3
+ * @codegen <<SignedSource::839224bfab98c1ddf6018dec5320968e>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -9,6 +9,7 @@ declare const _default: {
9
9
  '@atlaskit/design-system/consistent-css-prop-usage': string;
10
10
  '@atlaskit/design-system/ensure-design-token-usage': string;
11
11
  '@atlaskit/design-system/icon-label': string;
12
+ '@atlaskit/design-system/local-cx-xcss': string;
12
13
  '@atlaskit/design-system/no-banned-imports': string;
13
14
  '@atlaskit/design-system/no-deprecated-apis': string;
14
15
  '@atlaskit/design-system/no-deprecated-design-token-usage': string;
@@ -3,6 +3,7 @@ declare const _default: {
3
3
  'ensure-design-token-usage': import("eslint").Rule.RuleModule;
4
4
  'ensure-design-token-usage/preview': import("eslint").Rule.RuleModule;
5
5
  'icon-label': import("eslint").Rule.RuleModule;
6
+ 'local-cx-xcss': import("eslint").Rule.RuleModule;
6
7
  'no-banned-imports': import("eslint").Rule.RuleModule;
7
8
  'no-css-tagged-template-expression': import("eslint").Rule.RuleModule;
8
9
  'no-deprecated-apis': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<string, [{
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ export declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -1,6 +1,5 @@
1
- import type { Rule, Scope } from 'eslint';
2
- type Node = Rule.Node;
3
- type Reference = Scope.Reference;
1
+ import type { Rule } from 'eslint';
2
+ import { SupportedNameChecker } from '../../utils/is-supported-import';
4
3
  type RuleModule = Rule.RuleModule;
5
- export declare const createNoTaggedTemplateExpressionRule: (isUsage: (node: Node, references: Reference[]) => boolean, messageId: string) => RuleModule['create'];
4
+ export declare const createNoTaggedTemplateExpressionRule: (isUsage: SupportedNameChecker, messageId: string) => RuleModule['create'];
6
5
  export {};
@@ -0,0 +1,17 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ /**
4
+ * Transforms a JSXElement from:
5
+ * ```
6
+ * <div>
7
+ * // ...
8
+ * </div>
9
+ * ```
10
+ * to
11
+ * ```
12
+ * <Box xcss={myStyles}>
13
+ * // ...
14
+ * </Box>
15
+ * ```
16
+ */
17
+ export declare const convertJsxCallSite: (jsxElement: JSXElement, newStylesVariableName: string, fixer: Rule.RuleFixer) => Rule.Fix[];
@@ -0,0 +1,17 @@
1
+ import type { Rule } from 'eslint';
2
+ import { VariableDeclarator } from 'eslint-codemod-utils';
3
+ /**
4
+ * Transforms a variable like:
5
+ * ```
6
+ * const MyComponent = styled.div({
7
+ * padding: '8px',
8
+ * })
9
+ * ```
10
+ * to
11
+ * ```
12
+ * const myComponentStyles = xcss({
13
+ * padding: 'space.100',
14
+ * })
15
+ * ```
16
+ */
17
+ export declare const convertStyledComponentToXcss: (styles: VariableDeclarator, newStylesVariableName: string, fixer: Rule.RuleFixer) => (Rule.Fix | undefined)[];
@@ -0,0 +1,25 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement, VariableDeclarator } from 'eslint-codemod-utils';
3
+ import { RuleConfig } from '../../config';
4
+ interface MetaData {
5
+ context: Rule.RuleContext;
6
+ config: RuleConfig;
7
+ }
8
+ interface Refs {
9
+ styles: VariableDeclarator;
10
+ jsxElement: JSXElement;
11
+ }
12
+ type Check = {
13
+ success: boolean;
14
+ refs?: Refs;
15
+ };
16
+ export declare const CompiledStyled: {
17
+ lint(node: Rule.Node, { context, config }: MetaData): void;
18
+ _check(node: Rule.Node, { context, config }: MetaData): Check;
19
+ /**
20
+ * All required validation steps have been taken care of before this
21
+ * transformer is called, so it just goes ahead providing all necessary fixes
22
+ */
23
+ _fix(refs: Refs, context: Rule.RuleContext): (fixer: Rule.RuleFixer) => Rule.Fix[];
24
+ };
25
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const elements: string[];
2
+ export declare const attributes: string[];
@@ -0,0 +1,14 @@
1
+ import type { Rule } from 'eslint';
2
+ /**
3
+ * Currently this is defined here because it's not very general purpose.
4
+ * If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
5
+ * and the other half would be in `Import`.
6
+ *
7
+ * TODO: Refactor and move to `ast-nodes`
8
+ *
9
+ * Note: It does not handle default imports, namespace imports, or aliased imports.
10
+ */
11
+ export declare const upsertImportDeclaration: ({ module, specifiers, }: {
12
+ module: string;
13
+ specifiers: string[];
14
+ }, context: Rule.RuleContext, fixer: Rule.RuleFixer) => Rule.Fix | undefined;
@@ -0,0 +1,7 @@
1
+ import { JSXElement } from 'eslint-codemod-utils';
2
+ /**
3
+ * Check that every attribute in the JSXElement is something we support.
4
+ * We do this via a whitelist in `this.attributes`. The result is we exclude
5
+ * dangerous attrs like `id` and `style`.
6
+ */
7
+ export declare const containsOnlySupportedAttrs: (node: JSXElement) => boolean;
@@ -12,24 +12,5 @@ export declare const EmotionCSS: {
12
12
  _fix(node: JSXElement, { context }: {
13
13
  context: Rule.RuleContext;
14
14
  }): FixFunction;
15
- /**
16
- * Check that every attribute in the JSXElement is something we support.
17
- * We do this via a whitelist in `this.attributes`. The result is we exclude
18
- * dangerous attrs like `id` and `style`.
19
- */
20
- _containsOnlySupportedAttributes(node: JSXElement): boolean;
21
- /**
22
- * Currently this is defined here because it's not very general purpose.
23
- * If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
24
- * and the other half would be in `Import`.
25
- *
26
- * TODO: Refactor and move to `ast-nodes`
27
- *
28
- * Note: It does not handle default imports, namespace imports, or aliased imports.
29
- */
30
- _upsertImportDeclaration({ module, specifiers, }: {
31
- module: string;
32
- specifiers: string[];
33
- }, context: Rule.RuleContext, fixer: Rule.RuleFixer): Rule.Fix | undefined;
34
15
  };
35
16
  export {};
@@ -1,9 +1,2 @@
1
1
  export declare const elements: string[];
2
2
  export declare const attributes: string[];
3
- declare const spaceTokenMap: {
4
- [key: string]: string;
5
- };
6
- export declare const styles: {
7
- [key: string]: typeof spaceTokenMap;
8
- };
9
- export {};
@@ -0,0 +1,14 @@
1
+ import type { Rule } from 'eslint';
2
+ /**
3
+ * Currently this is defined here because it's not very general purpose.
4
+ * If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
5
+ * and the other half would be in `Import`.
6
+ *
7
+ * TODO: Refactor and move to `ast-nodes`
8
+ *
9
+ * Note: It does not handle default imports, namespace imports, or aliased imports.
10
+ */
11
+ export declare const upsertImportDeclaration: ({ module, specifiers, }: {
12
+ module: string;
13
+ specifiers: string[];
14
+ }, context: Rule.RuleContext, fixer: Rule.RuleFixer) => Rule.Fix | undefined;
@@ -1,3 +1,3 @@
1
1
  export { cssToXcssTransformer, supportedStylesMap, spaceTokenMap, } from './css-to-xcss';
2
- export { jsxElementToBoxTransformer } from './jsx-element-to-box';
3
- export { styledComponentToPrimitive } from './styled-component-to-primitive';
2
+ export { CompiledStyled } from './compiled-styled';
3
+ export { EmotionCSS } from './emotion-css';
@@ -1,7 +1,4 @@
1
- export { containsOnlySupportedAttrs } from './contains-only-supported-attrs';
2
1
  export { convertASTObjectExpressionToJSObject } from './convert-ast-object-expression-to-js-object';
3
- export { findValidJsxUsageToTransform } from './find-valid-jsx-usage-to-transform';
4
- export { findValidStyledComponentCall } from './find-valid-styled-component-call';
5
2
  export { getAttributeValueIdentifier } from './get-attribute-value-identifier';
6
3
  export { getFunctionArgumentAtPos } from './get-function-argument-at-pos';
7
4
  export { getJSXAttributeByName } from './get-jsx-attribute-by-name';
@@ -9,7 +6,4 @@ export { getVariableDefinitionValue } from './get-variable-definition-value';
9
6
  export { getVariableUsagesCount } from './get-variable-usage-count';
10
7
  export { isFunctionNamed } from './is-function-named';
11
8
  export { isValidCssPropertiesToTransform } from './is-valid-css-properties-to-transform';
12
- export { isValidTagName } from './is-valid-tag-name';
13
9
  export { updateJSXAttributeByName } from './update-jsx-attribute-by-name';
14
- export { updateJSXElementName } from './update-jsx-element-name';
15
- export { upsertImportDeclaration } from './upsert-import-declaration';
@@ -0,0 +1,16 @@
1
+ import type { Scope } from 'eslint';
2
+ import type { CallExpression } from 'estree';
3
+ type Callee = CallExpression['callee'];
4
+ type Reference = Scope.Reference;
5
+ export declare const CSS_IN_JS_IMPORTS: {
6
+ compiled: string;
7
+ emotionReact: string;
8
+ emotionCore: string;
9
+ styledComponents: string;
10
+ atlaskitCss: string;
11
+ };
12
+ type ValidImportSources = string[];
13
+ export type SupportedNameChecker = (nodeToCheck: Callee, referencesInScope: Reference[], importSources: ValidImportSources) => boolean;
14
+ export declare const isCss: SupportedNameChecker;
15
+ export declare const isCxFunction: SupportedNameChecker;
16
+ export {};
@@ -2,4 +2,5 @@ export { FunctionCall } from './function-call';
2
2
  export { Import } from './import';
3
3
  export { JSXAttribute } from './jsx-attribute';
4
4
  export { JSXElement } from './jsx-element';
5
+ export { Object } from './object';
5
6
  export { Root } from './root';
@@ -0,0 +1,39 @@
1
+ import type { Rule } from 'eslint';
2
+ import { ObjectExpression, Property } from 'eslint-codemod-utils';
3
+ declare const ASTObjectExpression: {
4
+ /**
5
+ * Returns `true` if an object contains a property with the specified name, `false` otherwise.
6
+ */
7
+ hasProperty(node: ObjectExpression, name: string): boolean;
8
+ /**
9
+ * Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`
10
+ */
11
+ getEntryByPropertyName(node: ObjectExpression, name: string): Property | undefined;
12
+ deleteEntry(node: ObjectExpression, name: string, fixer: Rule.RuleFixer): Rule.Fix[];
13
+ /**
14
+ * Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`
15
+ */
16
+ getProperty(node: ObjectExpression, name: string): Property['key'] | undefined;
17
+ /**
18
+ * Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`
19
+ *
20
+ * Values can be basically anything, so be careful with this
21
+ */
22
+ getValueByPropertyName(node: ObjectExpression, name: string): Property['value'] | undefined;
23
+ containsSpreadProps(node: ObjectExpression): boolean;
24
+ updateValue(node: ObjectExpression, propertyName: string, newValue: string, fixer: Rule.RuleFixer): Rule.Fix;
25
+ /**
26
+ * Appends a key-value pair to the end of an object. For example:
27
+ * ```
28
+ * ast.Object.appendEntry(
29
+ * node, // { padding: 'space.100' }
30
+ * key, // 'margin',
31
+ * value, // 'space.200'
32
+ * fixer,
33
+ * )
34
+ * ```
35
+ * Will result in `{ padding: 'space.100', margin: 'space.200'}`
36
+ */
37
+ appendEntry(node: ObjectExpression, key: string, value: string, fixer: Rule.RuleFixer): Rule.Fix;
38
+ };
39
+ export { ASTObjectExpression as Object };
@@ -7,6 +7,7 @@ export declare const configs: {
7
7
  '@atlaskit/design-system/ensure-design-token-usage': string;
8
8
  '@atlaskit/design-system/ensure-design-token-usage/preview': string;
9
9
  '@atlaskit/design-system/icon-label': string;
10
+ '@atlaskit/design-system/local-cx-xcss': string;
10
11
  '@atlaskit/design-system/no-banned-imports': string;
11
12
  '@atlaskit/design-system/no-css-tagged-template-expression': string;
12
13
  '@atlaskit/design-system/no-deprecated-apis': string;
@@ -33,6 +34,7 @@ export declare const configs: {
33
34
  '@atlaskit/design-system/consistent-css-prop-usage': string;
34
35
  '@atlaskit/design-system/ensure-design-token-usage': string;
35
36
  '@atlaskit/design-system/icon-label': string;
37
+ '@atlaskit/design-system/local-cx-xcss': string;
36
38
  '@atlaskit/design-system/no-banned-imports': string;
37
39
  '@atlaskit/design-system/no-deprecated-apis': string;
38
40
  '@atlaskit/design-system/no-deprecated-design-token-usage': string;