@atlaskit/eslint-plugin-ui-styling-standard 0.11.4 → 0.11.6

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 (59) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +33 -3
  3. package/constellation/atlaskit-theme/usage.mdx +113 -0
  4. package/constellation/convert-props-syntax/usage.mdx +32 -22
  5. package/constellation/enforce-style-prop/usage.mdx +21 -18
  6. package/constellation/index/overview.mdx +91 -76
  7. package/constellation/index/props.mdx +2 -9
  8. package/constellation/local-cx-xcss/usage.mdx +10 -6
  9. package/constellation/no-array-arguments/usage.mdx +10 -9
  10. package/constellation/no-classname-prop/usage.mdx +7 -4
  11. package/constellation/no-container-queries/usage.mdx +17 -15
  12. package/constellation/no-dynamic-styles/usage.mdx +26 -29
  13. package/constellation/no-exported-styles/usage.mdx +23 -18
  14. package/constellation/no-important-styles/usage.mdx +5 -3
  15. package/constellation/no-imported-style-values/usage.mdx +30 -22
  16. package/constellation/no-nested-selectors/usage.mdx +22 -20
  17. package/constellation/no-unsafe-values/usage.mdx +45 -51
  18. package/dist/cjs/index.codegen.js +1 -1
  19. package/dist/cjs/presets/all.codegen.js +2 -1
  20. package/dist/cjs/presets/recommended.codegen.js +2 -1
  21. package/dist/cjs/rules/atlaskit-theme/index.js +95 -0
  22. package/dist/cjs/rules/enforce-style-prop/index.js +39 -26
  23. package/dist/cjs/rules/index.codegen.js +3 -1
  24. package/dist/es2019/index.codegen.js +1 -1
  25. package/dist/es2019/presets/all.codegen.js +2 -1
  26. package/dist/es2019/presets/recommended.codegen.js +2 -1
  27. package/dist/es2019/rules/atlaskit-theme/index.js +85 -0
  28. package/dist/es2019/rules/enforce-style-prop/index.js +34 -19
  29. package/dist/es2019/rules/index.codegen.js +3 -1
  30. package/dist/esm/index.codegen.js +1 -1
  31. package/dist/esm/presets/all.codegen.js +2 -1
  32. package/dist/esm/presets/recommended.codegen.js +2 -1
  33. package/dist/esm/rules/atlaskit-theme/index.js +89 -0
  34. package/dist/esm/rules/enforce-style-prop/index.js +39 -26
  35. package/dist/esm/rules/index.codegen.js +3 -1
  36. package/dist/types/index.codegen.d.ts +2 -0
  37. package/dist/types/presets/all.codegen.d.ts +2 -1
  38. package/dist/types/presets/recommended.codegen.d.ts +2 -1
  39. package/dist/types/rules/atlaskit-theme/index.d.ts +3 -0
  40. package/dist/types/rules/index.codegen.d.ts +1 -0
  41. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  42. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  43. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
  44. package/dist/types-ts4.5/rules/atlaskit-theme/index.d.ts +3 -0
  45. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  46. package/package.json +3 -3
  47. package/scripts/codegen.tsx +3 -10
  48. package/src/index.codegen.tsx +3 -3
  49. package/src/presets/all.codegen.tsx +66 -69
  50. package/src/presets/recommended.codegen.tsx +66 -69
  51. package/src/rules/atlaskit-theme/README.md +109 -0
  52. package/src/rules/atlaskit-theme/__tests__/test.ts +122 -0
  53. package/src/rules/atlaskit-theme/index.ts +136 -0
  54. package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +18 -0
  55. package/src/rules/enforce-style-prop/index.tsx +42 -23
  56. package/src/rules/index.codegen.tsx +15 -13
  57. package/src/rules/no-exported-styles/index.tsx +1 -1
  58. package/src/rules/no-imported-style-values/index.tsx +1 -1
  59. package/tsconfig.app.json +3 -0
@@ -8,14 +8,14 @@ This rule prevents the usage of styles that are difficult/impossible to statical
8
8
 
9
9
  **Function calls**
10
10
 
11
- Function calls are not allowed as arguments or as values,
12
- unless they are specified in `allowedFunctionCalls` (or in the default list).
11
+ Function calls are not allowed as arguments or as values, unless they are specified in
12
+ `allowedFunctionCalls` (or in the default list).
13
13
 
14
14
  ```tsx
15
15
  import { css } from '@compiled/react';
16
16
 
17
17
  function getStyles() {
18
- return { width: 100 };
18
+ return { width: 100 };
19
19
  }
20
20
 
21
21
  const styles = css(getStyles());
@@ -25,30 +25,30 @@ const styles = css(getStyles());
25
25
  import { css } from '@compiled/react';
26
26
 
27
27
  function getWidth() {
28
- return 100;
28
+ return 100;
29
29
  }
30
30
 
31
31
  const styles = css({
32
- width: getWidth(),
32
+ width: getWidth(),
33
33
  });
34
34
  ```
35
35
 
36
36
  **Dynamic keys**
37
37
 
38
- Dynamic keys are not allowed,
39
- unless they are specified in `allowedDynamicKeys` (or in the default list).
38
+ Dynamic keys are not allowed, unless they are specified in `allowedDynamicKeys` (or in the default
39
+ list).
40
40
 
41
41
  ```tsx
42
42
  import { css } from '@compiled/react';
43
43
  import { SELECTOR } from 'my-package';
44
44
 
45
45
  const styles = css({
46
- [SELECTOR]: {
47
- color: 'red',
48
- },
49
- [`${SELECTOR} > p`]: {
50
- width: 100,
51
- },
46
+ [SELECTOR]: {
47
+ color: 'red',
48
+ },
49
+ [`${SELECTOR} > p`]: {
50
+ width: 100,
51
+ },
52
52
  });
53
53
  ```
54
54
 
@@ -56,19 +56,19 @@ const styles = css({
56
56
 
57
57
  Variables are not allowed as values, unless they:
58
58
 
59
- - Have a simple, static value
60
- - Are defined in the same file
59
+ - Have a simple, static value
60
+ - Are defined in the same file
61
61
 
62
62
  ```tsx
63
63
  import { css } from '@compiled/react';
64
64
  import { SELECTOR } from 'my-package';
65
65
 
66
66
  function myFunction() {
67
- return '5px';
67
+ return '5px';
68
68
  }
69
69
 
70
70
  const styles = css({
71
- height: myFunction,
71
+ height: myFunction,
72
72
  });
73
73
  ```
74
74
 
@@ -81,11 +81,11 @@ import { css } from '@compiled/react';
81
81
  import { token } from '@atlaskit/tokens';
82
82
 
83
83
  const colors = {
84
- text: token('color.text'),
84
+ text: token('color.text'),
85
85
  };
86
86
 
87
87
  const styles = css({
88
- color: colors.text,
88
+ color: colors.text,
89
89
  });
90
90
  ```
91
91
 
@@ -97,24 +97,23 @@ Spread elements are not allowed.
97
97
  import { css } from '@compiled/react';
98
98
 
99
99
  const buttonStyles = {
100
- color: 'blue',
100
+ color: 'blue',
101
101
  };
102
102
 
103
103
  const styles = css({
104
- ...buttonStyles,
104
+ ...buttonStyles,
105
105
  });
106
106
  ```
107
107
 
108
108
  **Array values**
109
109
 
110
- Array values are not allowed.
111
- This syntax is not supported by most styling libraries.
110
+ Array values are not allowed. This syntax is not supported by most styling libraries.
112
111
 
113
112
  ```tsx
114
113
  import { css } from '@compiled/react';
115
114
 
116
115
  const styles = css({
117
- '::before': [{ fontWeight: 'bold' }, { color: 'red' }],
116
+ '::before': [{ fontWeight: 'bold' }, { color: 'red' }],
118
117
  });
119
118
  ```
120
119
 
@@ -122,33 +121,26 @@ const styles = css({
122
121
 
123
122
  Things to note about the following example:
124
123
 
125
- - The `warningStyles` are conditionally applied using the `css` prop
126
- - The dynamic `width` is applied using the `style` prop
127
- - The `token()` calls are allowed because they are statically analyzable (and in the default allow-list)
124
+ - The `warningStyles` are conditionally applied using the `css` prop
125
+ - The dynamic `width` is applied using the `style` prop
126
+ - The `token()` calls are allowed because they are statically analyzable (and in the default
127
+ allow-list)
128
128
 
129
129
  ```tsx
130
130
  import { css } from '@compiled/react';
131
131
  import { token } from '@atlaskit/tokens';
132
132
 
133
133
  const baseStyles = css({
134
- height: 100,
134
+ height: 100,
135
135
  });
136
136
 
137
137
  const warningStyles = css({
138
- color: token('color.text.warning'),
139
- backgroundColor: token('color.background.warning'),
138
+ color: token('color.text.warning'),
139
+ backgroundColor: token('color.background.warning'),
140
140
  });
141
141
 
142
- const Component = ({
143
- isWarning,
144
- width,
145
- }: {
146
- isWarning: boolean;
147
- width: number;
148
- }) => {
149
- return (
150
- <div style={{ width }} css={[baseStyles, isWarning && warningStyles]} />
151
- );
142
+ const Component = ({ isWarning, width }: { isWarning: boolean; width: number }) => {
143
+ return <div style={{ width }} css={[baseStyles, isWarning && warningStyles]} />;
152
144
  };
153
145
  ```
154
146
 
@@ -158,7 +150,8 @@ const Component = ({
158
150
 
159
151
  Use this to allow specified imports as dynamic keys, in addition to the built-in allow-list.
160
152
 
161
- Each value should be a two-element array. The first item is the entrypoint, and the second item is a named export.
153
+ Each value should be a two-element array. The first item is the entrypoint, and the second item is a
154
+ named export.
162
155
 
163
156
  Default imports are not supported.
164
157
 
@@ -184,7 +177,8 @@ Default imports are not supported.
184
177
 
185
178
  Use this to allow specific functions to be called, in addition to the built-in allow-list.
186
179
 
187
- Each value should be a two-element array. The first item is the entrypoint, and the second item is a named export.
180
+ Each value should be a two-element array. The first item is the entrypoint, and the second item is a
181
+ named export.
188
182
 
189
183
  Default imports are not currently supported.
190
184
 
@@ -210,13 +204,13 @@ Default imports are not currently supported.
210
204
 
211
205
  By default, this rule will check `css` usages from:
212
206
 
213
- - `@atlaskit/css`
214
- - `@atlaskit/primitives`
215
- - `@compiled/react`
216
- - `@emotion/react`
217
- - `@emotion/core`
218
- - `@emotion/styled`
219
- - `styled-components`
207
+ - `@atlaskit/css`
208
+ - `@atlaskit/primitives`
209
+ - `@compiled/react`
210
+ - `@emotion/react`
211
+ - `@emotion/core`
212
+ - `@emotion/styled`
213
+ - `styled-components`
220
214
 
221
- To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
222
- This will override the built-in allow-list.
215
+ To change this list of libraries, you can define a custom set of `importSources`, which accepts an
216
+ array of package names (strings). This will override the built-in allow-list.
@@ -16,7 +16,7 @@ var _recommended = _interopRequireDefault(require("./presets/recommended.codegen
16
16
  var _index = _interopRequireDefault(require("./rules/index.codegen"));
17
17
  /**
18
18
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
19
- * @codegen <<SignedSource::3fd41935576c9346ca1f1e0c787a0a48>>
19
+ * @codegen <<SignedSource::16a3441765e5a97f9f32de7fd0de17f0>>
20
20
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
21
21
  */
22
22
 
@@ -6,12 +6,13 @@ 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::96336e6094dbcbf456aaef313b624fbf>>
9
+ * @codegen <<SignedSource::a0c326baf3aa4e87ac809b303ba34682>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
  var _default = exports.default = {
13
13
  plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
14
14
  rules: {
15
+ '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
15
16
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
16
17
  '@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
17
18
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
@@ -6,12 +6,13 @@ 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::96336e6094dbcbf456aaef313b624fbf>>
9
+ * @codegen <<SignedSource::a0c326baf3aa4e87ac809b303ba34682>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
  var _default = exports.default = {
13
13
  plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
14
14
  rules: {
15
+ '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
15
16
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
16
17
  '@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
17
18
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.rule = exports.default = void 0;
7
+ var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
8
+ var _createRule = require("../utils/create-rule");
9
+ var isIdentifierReferenced = function isIdentifierReferenced(hasImportSpecifier, node, references) {
10
+ return references.some(function (reference) {
11
+ var _reference$resolved;
12
+ return reference.identifier === node && ((_reference$resolved = reference.resolved) === null || _reference$resolved === void 0 ? void 0 : _reference$resolved.defs.some(hasImportSpecifier));
13
+ });
14
+ };
15
+ var isTypographyImportSpecifier = function isTypographyImportSpecifier(def) {
16
+ var _def$parent, _def$parent2, _def$parent3;
17
+ return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && ((_def$parent = def.parent) === null || _def$parent === void 0 ? void 0 : _def$parent.type) === 'ImportDeclaration' && (def.node.imported.name === 'typography' && ((_def$parent2 = def.parent) === null || _def$parent2 === void 0 ? void 0 : _def$parent2.source.value) === '@atlaskit/theme' || ((_def$parent3 = def.parent) === null || _def$parent3 === void 0 ? void 0 : _def$parent3.source.value) === '@atlaskit/theme/typography');
18
+ };
19
+ var isElevationImportSpecifier = function isElevationImportSpecifier(def) {
20
+ var _def$parent4, _def$parent5, _def$parent6;
21
+ return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && ((_def$parent4 = def.parent) === null || _def$parent4 === void 0 ? void 0 : _def$parent4.type) === 'ImportDeclaration' && (def.node.imported.name === 'elevation' && ((_def$parent5 = def.parent) === null || _def$parent5 === void 0 ? void 0 : _def$parent5.source.value) === '@atlaskit/theme' || ((_def$parent6 = def.parent) === null || _def$parent6 === void 0 ? void 0 : _def$parent6.source.value) === '@atlaskit/theme/elevation');
22
+ };
23
+ var isSkeletonShimmerImportSpecifier = function isSkeletonShimmerImportSpecifier(def) {
24
+ var _def$parent7, _def$parent8, _def$parent9;
25
+ return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && ((_def$parent7 = def.parent) === null || _def$parent7 === void 0 ? void 0 : _def$parent7.type) === 'ImportDeclaration' && def.node.imported.name === 'skeletonShimmer' && typeof ((_def$parent8 = def.parent) === null || _def$parent8 === void 0 ? void 0 : _def$parent8.source.value) === 'string' && ((_def$parent9 = def.parent) === null || _def$parent9 === void 0 || (_def$parent9 = _def$parent9.source.value) === null || _def$parent9 === void 0 ? void 0 : _def$parent9.startsWith('@atlaskit/theme'));
26
+ };
27
+ var checkIdentifier = function checkIdentifier(node, context, references) {
28
+ if (isIdentifierReferenced(isTypographyImportSpecifier, node, references)) {
29
+ context.report({
30
+ messageId: 'usingTypography',
31
+ node: node
32
+ });
33
+ }
34
+ if (isIdentifierReferenced(isElevationImportSpecifier, node, references)) {
35
+ context.report({
36
+ messageId: 'usingElevation',
37
+ node: node
38
+ });
39
+ }
40
+ if (isIdentifierReferenced(isSkeletonShimmerImportSpecifier, node, references)) {
41
+ context.report({
42
+ messageId: 'usingSkeletonShimmer',
43
+ node: node
44
+ });
45
+ }
46
+ };
47
+ var rule = exports.rule = (0, _createRule.createLintRule)({
48
+ meta: {
49
+ name: 'atlaskit-theme',
50
+ docs: {
51
+ description: 'Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand',
52
+ recommended: true,
53
+ severity: 'error'
54
+ },
55
+ messages: {
56
+ usingTypography: 'Typography does not work with Compiled. Please utilise alternatives like Heading or tokens instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage',
57
+ usingElevation: 'Elevation does not work with Compiled. Please use a token with a fallback instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage',
58
+ usingSkeletonShimmer: 'Skeleton Shimmer does not work with Compiled. Please use an SVG skeleton instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage'
59
+ },
60
+ schema: [],
61
+ type: 'problem'
62
+ },
63
+ create: function create(context) {
64
+ var importSources = (0, _isSupportedImport.getImportSources)(context);
65
+ return {
66
+ 'CallExpression Identifier': function CallExpressionIdentifier(node) {
67
+ var _context$getScope = context.getScope(),
68
+ references = _context$getScope.references;
69
+ var ancestors = context.getAncestors();
70
+
71
+ // Check if ancestor node is a call expression to Compiled
72
+ if (ancestors.some(function (ancestor) {
73
+ return ancestor.type === 'CallExpression' && ancestor.callee && (0, _isSupportedImport.isCompiled)(ancestor.callee, references, importSources);
74
+ })) {
75
+ // Check identifier for violations
76
+ checkIdentifier(node, context, references);
77
+ }
78
+ },
79
+ 'TaggedTemplateExpression Identifier': function TaggedTemplateExpressionIdentifier(node) {
80
+ var _context$getScope2 = context.getScope(),
81
+ references = _context$getScope2.references;
82
+ var ancestors = context.getAncestors();
83
+
84
+ // Check if ancestor node is a tagged template expression to Compiled
85
+ if (ancestors.some(function (ancestor) {
86
+ return ancestor.type === 'TaggedTemplateExpression' && ancestor.tag && (0, _isSupportedImport.isCompiled)(ancestor.tag, references, importSources);
87
+ })) {
88
+ // Check identifier for violations
89
+ checkIdentifier(node, context, references);
90
+ }
91
+ }
92
+ };
93
+ }
94
+ });
95
+ var _default = exports.default = rule;
@@ -6,24 +6,26 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.rule = exports.default = void 0;
7
7
  var _eslintCodemodUtils = require("eslint-codemod-utils");
8
8
  var _createRule = require("../utils/create-rule");
9
- var findVariable = function findVariable(context, name) {
10
- return context.getScope().variables.find(function (varb) {
11
- return varb.name === name;
12
- });
13
- };
14
- var isParameter = function isParameter(context, variableName) {
9
+ var _allowedFunctionCalls = require("@atlaskit/eslint-utils/allowed-function-calls");
10
+ var _findVariable3 = require("@atlaskit/eslint-utils/find-variable");
11
+ var isParameter = function isParameter(context, identifier) {
15
12
  var _findVariable;
16
- var definitions = (_findVariable = findVariable(context, variableName)) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
13
+ var definitions = (_findVariable = (0, _findVariable3.findVariable)({
14
+ sourceCode: context.sourceCode,
15
+ identifier: identifier
16
+ })) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
17
17
  if (!definitions || !definitions.length) {
18
18
  return false;
19
19
  }
20
20
  var result = definitions[0];
21
21
  return result.type === 'Parameter';
22
22
  };
23
- var checkIdentifier = function checkIdentifier(context, identifier) {
23
+ var isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
24
24
  var _parent;
25
- var val = identifier.name;
26
- var variable = findVariable(context, val);
25
+ var variable = (0, _findVariable3.findVariable)({
26
+ sourceCode: context.sourceCode,
27
+ identifier: identifier
28
+ });
27
29
  if (!variable) {
28
30
  return false;
29
31
  }
@@ -36,7 +38,7 @@ var checkIdentifier = function checkIdentifier(context, identifier) {
36
38
 
37
39
  // Checking if identifier has been destructured from props within function
38
40
  if (variableDefinition.type === 'VariableDeclarator') {
39
- var _variableDefinition$i, _variableDefinition$i2, _variableDefinition$i3;
41
+ var _variableDefinition$i, _variableDefinition$i2;
40
42
  // If it's a let variable, ignore
41
43
  if (variableDefinition.parent.kind === 'let') {
42
44
  return true;
@@ -48,16 +50,14 @@ var checkIdentifier = function checkIdentifier(context, identifier) {
48
50
  // Destructured from member expression
49
51
  // e.g. const width = props.width
50
52
  if (((_variableDefinition$i2 = variableDefinition.init) === null || _variableDefinition$i2 === void 0 ? void 0 : _variableDefinition$i2.type) === 'MemberExpression') {
51
- var memberIdentifierName = variableDefinition.init.object.name;
52
- return isParameter(context, memberIdentifierName);
53
+ return isParameter(context, variableDefinition.init.object);
53
54
  }
54
55
  // Destructured from object pattern
55
56
  // e.g. const { width } = props
56
- var propName = (_variableDefinition$i3 = variableDefinition.init) === null || _variableDefinition$i3 === void 0 ? void 0 : _variableDefinition$i3.name;
57
- return isParameter(context, propName);
57
+ return isParameter(context, variableDefinition.init);
58
58
  }
59
59
  // If identifier has not been deconstructed from parameter or is a RestElement, report warning
60
- return isParameter(context, val);
60
+ return isParameter(context, identifier);
61
61
  };
62
62
  function isPropertyValueAllowed(property, context) {
63
63
  if (property.type === 'SpreadElement') {
@@ -67,26 +67,39 @@ function isPropertyValueAllowed(property, context) {
67
67
  if (property.value.type === 'Literal') {
68
68
  return false;
69
69
  } else if (property.value.type === 'Identifier') {
70
- return checkIdentifier(context, property.value);
71
- } else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier' && property.value.callee.name === 'token') {
72
- return false;
70
+ return isIdentifierAllowed(context, property.value);
71
+ } else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier') {
72
+ var variable = (0, _findVariable3.findVariable)({
73
+ sourceCode: context.sourceCode,
74
+ identifier: property.value.callee
75
+ });
76
+ // Anything returned by getAllowedFunctionCalls should be used in css prop instead
77
+ var functionAllowList = (0, _allowedFunctionCalls.getAllowedFunctionCalls)(context.options);
78
+ if (!variable || (0, _allowedFunctionCalls.isAllowListedVariable)({
79
+ allowList: functionAllowList,
80
+ variable: variable
81
+ })) {
82
+ return false;
83
+ }
73
84
  } else if (property.value.type === 'MemberExpression' && property.value.object.type === 'Identifier') {
74
85
  var _findVariable2;
75
- var val = property.value.object.name;
76
- var definitions = (_findVariable2 = findVariable(context, val)) === null || _findVariable2 === void 0 ? void 0 : _findVariable2.defs;
86
+ var definitions = (_findVariable2 = (0, _findVariable3.findVariable)({
87
+ sourceCode: context.sourceCode,
88
+ identifier: property.value.object
89
+ })) === null || _findVariable2 === void 0 ? void 0 : _findVariable2.defs;
77
90
  if (!definitions || !definitions.length) {
78
91
  return false;
79
92
  }
80
- var variable = definitions[0];
81
- if (!variable) {
93
+ var _variable = definitions[0];
94
+ if (!_variable) {
82
95
  return false;
83
96
  }
84
- var varType = variable.type;
97
+ var varType = _variable.type;
85
98
  if (varType === 'Variable') {
86
- if (!variable.node.init) {
99
+ if (!_variable.node.init) {
87
100
  return false;
88
101
  }
89
- var varSource = variable.node.init.type;
102
+ var varSource = _variable.node.init.type;
90
103
  // Variables initialised by a call expression or object expression are ok
91
104
  if (varSource === 'CallExpression' || varSource === 'ObjectExpression') {
92
105
  return true;
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _atlaskitTheme = _interopRequireDefault(require("./atlaskit-theme"));
8
9
  var _convertPropsSyntax = _interopRequireDefault(require("./convert-props-syntax"));
9
10
  var _enforceStyleProp = _interopRequireDefault(require("./enforce-style-prop"));
10
11
  var _localCxXcss = _interopRequireDefault(require("./local-cx-xcss"));
@@ -19,10 +20,11 @@ var _noNestedSelectors = _interopRequireDefault(require("./no-nested-selectors")
19
20
  var _noUnsafeValues = _interopRequireDefault(require("./no-unsafe-values"));
20
21
  /**
21
22
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
22
- * @codegen <<SignedSource::648acb81f0f43d8ce56f7d6c22db8856>>
23
+ * @codegen <<SignedSource::78ffc29d20fd2fe3727a620cb4ddf192>>
23
24
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
24
25
  */
25
26
  var _default = exports.default = {
27
+ 'atlaskit-theme': _atlaskitTheme.default,
26
28
  'convert-props-syntax': _convertPropsSyntax.default,
27
29
  'enforce-style-prop': _enforceStyleProp.default,
28
30
  'local-cx-xcss': _localCxXcss.default,
@@ -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::3fd41935576c9346ca1f1e0c787a0a48>>
3
+ * @codegen <<SignedSource::16a3441765e5a97f9f32de7fd0de17f0>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import all from './presets/all.codegen';
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::96336e6094dbcbf456aaef313b624fbf>>
3
+ * @codegen <<SignedSource::a0c326baf3aa4e87ac809b303ba34682>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
7
7
  plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
8
8
  rules: {
9
+ '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
9
10
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
10
11
  '@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
11
12
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::96336e6094dbcbf456aaef313b624fbf>>
3
+ * @codegen <<SignedSource::a0c326baf3aa4e87ac809b303ba34682>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
7
7
  plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
8
8
  rules: {
9
+ '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
9
10
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
10
11
  '@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
11
12
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
@@ -0,0 +1,85 @@
1
+ import { getImportSources, isCompiled } from '@atlaskit/eslint-utils/is-supported-import';
2
+ import { createLintRule } from '../utils/create-rule';
3
+ const isIdentifierReferenced = (hasImportSpecifier, node, references) => references.some(reference => {
4
+ var _reference$resolved;
5
+ return reference.identifier === node && ((_reference$resolved = reference.resolved) === null || _reference$resolved === void 0 ? void 0 : _reference$resolved.defs.some(hasImportSpecifier));
6
+ });
7
+ const isTypographyImportSpecifier = def => {
8
+ var _def$parent, _def$parent2, _def$parent3;
9
+ return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && ((_def$parent = def.parent) === null || _def$parent === void 0 ? void 0 : _def$parent.type) === 'ImportDeclaration' && (def.node.imported.name === 'typography' && ((_def$parent2 = def.parent) === null || _def$parent2 === void 0 ? void 0 : _def$parent2.source.value) === '@atlaskit/theme' || ((_def$parent3 = def.parent) === null || _def$parent3 === void 0 ? void 0 : _def$parent3.source.value) === '@atlaskit/theme/typography');
10
+ };
11
+ const isElevationImportSpecifier = def => {
12
+ var _def$parent4, _def$parent5, _def$parent6;
13
+ return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && ((_def$parent4 = def.parent) === null || _def$parent4 === void 0 ? void 0 : _def$parent4.type) === 'ImportDeclaration' && (def.node.imported.name === 'elevation' && ((_def$parent5 = def.parent) === null || _def$parent5 === void 0 ? void 0 : _def$parent5.source.value) === '@atlaskit/theme' || ((_def$parent6 = def.parent) === null || _def$parent6 === void 0 ? void 0 : _def$parent6.source.value) === '@atlaskit/theme/elevation');
14
+ };
15
+ const isSkeletonShimmerImportSpecifier = def => {
16
+ var _def$parent7, _def$parent8, _def$parent9, _def$parent9$source$v;
17
+ return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && ((_def$parent7 = def.parent) === null || _def$parent7 === void 0 ? void 0 : _def$parent7.type) === 'ImportDeclaration' && def.node.imported.name === 'skeletonShimmer' && typeof ((_def$parent8 = def.parent) === null || _def$parent8 === void 0 ? void 0 : _def$parent8.source.value) === 'string' && ((_def$parent9 = def.parent) === null || _def$parent9 === void 0 ? void 0 : (_def$parent9$source$v = _def$parent9.source.value) === null || _def$parent9$source$v === void 0 ? void 0 : _def$parent9$source$v.startsWith('@atlaskit/theme'));
18
+ };
19
+ const checkIdentifier = (node, context, references) => {
20
+ if (isIdentifierReferenced(isTypographyImportSpecifier, node, references)) {
21
+ context.report({
22
+ messageId: 'usingTypography',
23
+ node
24
+ });
25
+ }
26
+ if (isIdentifierReferenced(isElevationImportSpecifier, node, references)) {
27
+ context.report({
28
+ messageId: 'usingElevation',
29
+ node
30
+ });
31
+ }
32
+ if (isIdentifierReferenced(isSkeletonShimmerImportSpecifier, node, references)) {
33
+ context.report({
34
+ messageId: 'usingSkeletonShimmer',
35
+ node
36
+ });
37
+ }
38
+ };
39
+ export const rule = createLintRule({
40
+ meta: {
41
+ name: 'atlaskit-theme',
42
+ docs: {
43
+ description: 'Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand',
44
+ recommended: true,
45
+ severity: 'error'
46
+ },
47
+ messages: {
48
+ usingTypography: 'Typography does not work with Compiled. Please utilise alternatives like Heading or tokens instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage',
49
+ usingElevation: 'Elevation does not work with Compiled. Please use a token with a fallback instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage',
50
+ usingSkeletonShimmer: 'Skeleton Shimmer does not work with Compiled. Please use an SVG skeleton instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage'
51
+ },
52
+ schema: [],
53
+ type: 'problem'
54
+ },
55
+ create(context) {
56
+ const importSources = getImportSources(context);
57
+ return {
58
+ 'CallExpression Identifier': node => {
59
+ const {
60
+ references
61
+ } = context.getScope();
62
+ const ancestors = context.getAncestors();
63
+
64
+ // Check if ancestor node is a call expression to Compiled
65
+ if (ancestors.some(ancestor => ancestor.type === 'CallExpression' && ancestor.callee && isCompiled(ancestor.callee, references, importSources))) {
66
+ // Check identifier for violations
67
+ checkIdentifier(node, context, references);
68
+ }
69
+ },
70
+ 'TaggedTemplateExpression Identifier': node => {
71
+ const {
72
+ references
73
+ } = context.getScope();
74
+ const ancestors = context.getAncestors();
75
+
76
+ // Check if ancestor node is a tagged template expression to Compiled
77
+ if (ancestors.some(ancestor => ancestor.type === 'TaggedTemplateExpression' && ancestor.tag && isCompiled(ancestor.tag, references, importSources))) {
78
+ // Check identifier for violations
79
+ checkIdentifier(node, context, references);
80
+ }
81
+ }
82
+ };
83
+ }
84
+ });
85
+ export default rule;