@atlaskit/eslint-plugin-ui-styling-standard 0.11.0 → 0.11.2

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 (42) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +2 -0
  3. package/constellation/index/overview.mdx +2 -0
  4. package/constellation/no-exported-styles/usage.mdx +87 -0
  5. package/constellation/no-imported-style-values/usage.mdx +146 -0
  6. package/dist/cjs/presets/all.codegen.js +3 -1
  7. package/dist/cjs/presets/recommended.codegen.js +3 -1
  8. package/dist/cjs/rules/index.codegen.js +5 -1
  9. package/dist/cjs/rules/no-exported-styles/index.js +39 -0
  10. package/dist/cjs/rules/no-imported-style-values/index.js +145 -0
  11. package/dist/es2019/presets/all.codegen.js +3 -1
  12. package/dist/es2019/presets/recommended.codegen.js +3 -1
  13. package/dist/es2019/rules/index.codegen.js +5 -1
  14. package/dist/es2019/rules/no-exported-styles/index.js +33 -0
  15. package/dist/es2019/rules/no-imported-style-values/index.js +125 -0
  16. package/dist/esm/presets/all.codegen.js +3 -1
  17. package/dist/esm/presets/recommended.codegen.js +3 -1
  18. package/dist/esm/rules/index.codegen.js +5 -1
  19. package/dist/esm/rules/no-exported-styles/index.js +33 -0
  20. package/dist/esm/rules/no-imported-style-values/index.js +138 -0
  21. package/dist/types/index.codegen.d.ts +4 -0
  22. package/dist/types/presets/all.codegen.d.ts +3 -1
  23. package/dist/types/presets/recommended.codegen.d.ts +3 -1
  24. package/dist/types/rules/index.codegen.d.ts +2 -0
  25. package/dist/types/rules/no-exported-styles/index.d.ts +2 -0
  26. package/dist/types/rules/no-imported-style-values/index.d.ts +3 -0
  27. package/dist/types-ts4.5/index.codegen.d.ts +4 -0
  28. package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -1
  29. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +3 -1
  30. package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
  31. package/dist/types-ts4.5/rules/no-exported-styles/index.d.ts +2 -0
  32. package/dist/types-ts4.5/rules/no-imported-style-values/index.d.ts +3 -0
  33. package/package.json +2 -2
  34. package/src/presets/all.codegen.tsx +3 -1
  35. package/src/presets/recommended.codegen.tsx +3 -1
  36. package/src/rules/index.codegen.tsx +5 -1
  37. package/src/rules/no-exported-styles/README.md +85 -0
  38. package/src/rules/no-exported-styles/__tests__/rule.test.tsx +225 -0
  39. package/src/rules/no-exported-styles/index.tsx +52 -0
  40. package/src/rules/no-imported-style-values/README.md +144 -0
  41. package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +265 -0
  42. package/src/rules/no-imported-style-values/index.tsx +154 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 0.11.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#94765](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/94765) [`8e5a3bddb686`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8e5a3bddb686) - Adding no imported style values ESlint rule
8
+
9
+ ## 0.11.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#92963](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/92963) [`1bb8557fb0b6`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/1bb8557fb0b6) - Added no-exported-styles eslint rule to disallow exports of css, cssMap, keyframes, styled and xcss styling
14
+
3
15
  ## 0.11.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -20,7 +20,9 @@ Not intended for use outside the Atlassian frontend repository.
20
20
  | <a href="./src/rules/no-classname-prop/README.md">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
21
21
  | <a href="./src/rules/no-container-queries/README.md">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
22
22
  | <a href="./src/rules/no-dynamic-styles/README.md">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
23
+ | <a href="./src/rules/no-exported-styles/README.md">no-exported-styles</a> | Disallows exports of css, keyframes, styled and xcss | Yes | | |
23
24
  | <a href="./src/rules/no-important-styles/README.md">no-important-styles</a> | Disallows important style declarations | Yes | | |
25
+ | <a href="./src/rules/no-imported-style-values/README.md">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
24
26
  | <a href="./src/rules/no-nested-selectors/README.md">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
25
27
  | <a href="./src/rules/no-unsafe-values/README.md">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
26
28
  | <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/consistent-css-prop-usage/usage">@atlaskit/design-system/consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
@@ -18,7 +18,9 @@ but more are planned to support the standard over time.
18
18
  | <a href="no-classname-prop/usage">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
19
19
  | <a href="no-container-queries/usage">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
20
20
  | <a href="no-dynamic-styles/usage">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
21
+ | <a href="no-exported-styles/usage">no-exported-styles</a> | Disallows exports of css, keyframes, styled and xcss | Yes | | |
21
22
  | <a href="no-important-styles/usage">no-important-styles</a> | Disallows important style declarations | Yes | | |
23
+ | <a href="no-imported-style-values/usage">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
22
24
  | <a href="no-nested-selectors/usage">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
23
25
  | <a href="no-unsafe-values/usage">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
24
26
  | <a href="consistent-css-prop-usage/usage">@atlaskit/design-system/consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
@@ -0,0 +1,87 @@
1
+ # no-exported-styles
2
+
3
+ This rule disallows exports of `css`, `cssMap`, `keyframes`, `styled`, `xcss` styles.
4
+
5
+ Exporting style declarations from these libraries may result in unexpected errors when imported, because its value will be null at runtime. Additionally, co-locating style definitions with their usage is considered best practice in order to improve code readability and build performance.
6
+
7
+ ## Examples
8
+
9
+ ### Incorrect
10
+
11
+ ```js
12
+ import { css } from '@compiled/react';
13
+
14
+ export const styles = css({});
15
+
16
+ export default css({});
17
+ ```
18
+
19
+ ```js
20
+ import { keyframes } from '@compiled/react';
21
+
22
+ export const animation = keyframes({});
23
+
24
+ export default keyframes({});
25
+ ```
26
+
27
+ Avoid exporting any style-like objects or values for consumption as well as these will violate our `no-imported-style-values` rule which blocks consumption of imported styles.
28
+
29
+ ```js
30
+ export default {
31
+ color: 'red',
32
+ margin: '0px',
33
+ };
34
+ ```
35
+
36
+ ```js
37
+ import { css } from '@compiled/react';
38
+
39
+ const color = css({
40
+ /* */
41
+ });
42
+
43
+ const styles = {
44
+ primary: {
45
+ text: {
46
+ color,
47
+ },
48
+ },
49
+ };
50
+
51
+ export default styles.primary.text.color;
52
+ ```
53
+
54
+ ### Correct
55
+
56
+ Co-locate your styles next to your components to improve code readability, linting, and build performance.
57
+
58
+ ```js
59
+ import { css } from '@compiled/react';
60
+
61
+ const styles = css({});
62
+ export const Component = ({ children }) => <div css={styles}>{children}></div>;
63
+ ```
64
+
65
+ ```js
66
+ import { keyframes } from '@compiled/react';
67
+
68
+ const animation = keyframes({});
69
+ const styles = css({ animate: `${animation} 1s ease-in` });
70
+ export const Component = ({ children }) => <div css={styles}>{children}></div>;
71
+ ```
72
+
73
+ ## Options
74
+
75
+ ### importSources
76
+
77
+ By default, this rule will check `css` usages from:
78
+
79
+ - `@atlaskit/css`
80
+ - `@atlaskit/primitives`
81
+ - `@compiled/react`
82
+ - `@emotion/react`
83
+ - `@emotion/core`
84
+ - `@emotion/styled`
85
+ - `styled-components`
86
+
87
+ To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
@@ -0,0 +1,146 @@
1
+ # no-imported-style-values
2
+
3
+ This rule disallows using imported style values in `css`, `cssMap`, `styled`, `keyframes` and `xcss` calls.
4
+
5
+ Importing style values may result in unexpected errors when used in these APIs, because its value will be null at runtime when using `@compiled/react`. Additionally, co-locating style definitions with their usage is considered best practice in order to improve code readability and build performance.
6
+
7
+ ## Examples
8
+
9
+ ### Incorrect
10
+
11
+ ```js
12
+ import { css } from '@compiled/react';
13
+ import { colors, getColor } from '@mui/theme';
14
+
15
+ const styles = css({
16
+ [colorKey]: getColor('red'),
17
+ background: colors['red'],
18
+ });
19
+ ```
20
+
21
+ ```js
22
+ import { css } from '@compiled/react';
23
+ import { buttonStyles, cssShared, HEIGHT, colorKey } from '../shared';
24
+ import { ff } from '@atlaskit/ff';
25
+
26
+ const sharedObject = { padding: 0 };
27
+
28
+ const styles = css({
29
+ ...cssShared,
30
+ ...sharedObject,
31
+ height: `${HEIGHT}px`,
32
+ width: ff('…') ? `${HEIGHT}px` : undefined,
33
+ });
34
+ ```
35
+
36
+ Importing styles to use in style composition is not allowed.
37
+
38
+ ```js
39
+ import { css } from '@compiled/react';
40
+ import { buttonStyles } from '../shared';
41
+
42
+ const styles = css({
43
+ color: 'red',
44
+ });
45
+
46
+ export default () => <div css={[styles, buttonStyles]} />;
47
+ ```
48
+
49
+ Importing styles to pass to the style prop is also not allowed.
50
+
51
+ ```js
52
+ import { importedWidth } from '../shared';
53
+
54
+ export default () => <div style={{ width: importedWidth }} />;
55
+ ```
56
+
57
+ ### Correct
58
+
59
+ Co-locate your styles next to your components to improve code readability, linting, and build performance.
60
+
61
+ ```js
62
+ import { css } from '@compiled/react';
63
+ import { token } from '@atlaskit/tokens';
64
+
65
+ const styles = css({
66
+ color: 'red',
67
+ padding: token('space.150'),
68
+ });
69
+ export const Component = ({ children }) => <div css={styles}>{children}></div>;
70
+ ```
71
+
72
+ ```js
73
+ import { keyframes } from '@compiled/react';
74
+
75
+ const animation = keyframes({});
76
+ const styles = css({ animate: `${animation} 1s ease-in` });
77
+ export const Component = ({ children }) => <div css={styles}>{children}></div>;
78
+ ```
79
+
80
+ ## Options
81
+
82
+ ### `allowedDynamicKeys: [string, string][]`
83
+
84
+ Use this to allow specified imports as dynamic keys, in addition to the built-in allow-list.
85
+
86
+ Each value should be a two-element array. The first item is the entrypoint, and the second item is a named export.
87
+
88
+ Default imports are not supported.
89
+
90
+ ```tsx
91
+ // .eslintrc.js
92
+
93
+ // ...
94
+ rules: {
95
+ '@atlaskit/eslint-plugin-ui-styling-standard/no-unsafe-values': [
96
+ 'error',
97
+ {
98
+ allowedDynamicKeys: [
99
+ ['@atlaskit/primitives/responsive', 'media'],
100
+ ]
101
+ },
102
+ ],
103
+ // ...
104
+ },
105
+ // ...
106
+ ```
107
+
108
+ ### `allowedFunctionCalls: [string, string][]`
109
+
110
+ Use this to allow specific functions to be called, in addition to the built-in allow-list.
111
+
112
+ Each value should be a two-element array. The first item is the entrypoint, and the second item is a named export.
113
+
114
+ Default imports are not currently supported.
115
+
116
+ ```tsx
117
+ // .eslintrc.js
118
+
119
+ // ...
120
+ rules: {
121
+ '@atlaskit/eslint-plugin-ui-styling-standard/no-unsafe-values': [
122
+ 'error',
123
+ {
124
+ allowedFunctionCalls: [
125
+ ['@atlaskit/tokens', 'token'],
126
+ ]
127
+ },
128
+ ],
129
+ // ...
130
+ },
131
+ // ...
132
+ ```
133
+
134
+ ### `importSources: string[]`
135
+
136
+ By default, this rule will check `css` usages from:
137
+
138
+ - `@atlaskit/css`
139
+ - `@atlaskit/primitives`
140
+ - `@compiled/react`
141
+ - `@emotion/react`
142
+ - `@emotion/core`
143
+ - `@emotion/styled`
144
+ - `styled-components`
145
+
146
+ To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::544c8b1c0eb0d6329064dcf92e18e45e>>
9
+ * @codegen <<SignedSource::96336e6094dbcbf456aaef313b624fbf>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -19,7 +19,9 @@ var _default = exports.default = {
19
19
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
20
20
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
21
21
  '@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
22
+ '@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
22
23
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
24
+ '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
23
25
  '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
24
26
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
25
27
  '@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::544c8b1c0eb0d6329064dcf92e18e45e>>
9
+ * @codegen <<SignedSource::96336e6094dbcbf456aaef313b624fbf>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -19,7 +19,9 @@ var _default = exports.default = {
19
19
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
20
20
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
21
21
  '@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
22
+ '@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
22
23
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
24
+ '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
23
25
  '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
24
26
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
25
27
  '@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
@@ -12,12 +12,14 @@ var _noArrayArguments = _interopRequireDefault(require("./no-array-arguments"));
12
12
  var _noClassnameProp = _interopRequireDefault(require("./no-classname-prop"));
13
13
  var _noContainerQueries = _interopRequireDefault(require("./no-container-queries"));
14
14
  var _noDynamicStyles = _interopRequireDefault(require("./no-dynamic-styles"));
15
+ var _noExportedStyles = _interopRequireDefault(require("./no-exported-styles"));
15
16
  var _noImportantStyles = _interopRequireDefault(require("./no-important-styles"));
17
+ var _noImportedStyleValues = _interopRequireDefault(require("./no-imported-style-values"));
16
18
  var _noNestedSelectors = _interopRequireDefault(require("./no-nested-selectors"));
17
19
  var _noUnsafeValues = _interopRequireDefault(require("./no-unsafe-values"));
18
20
  /**
19
21
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
20
- * @codegen <<SignedSource::edaedcad824fed1e108f90d909287584>>
22
+ * @codegen <<SignedSource::648acb81f0f43d8ce56f7d6c22db8856>>
21
23
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
22
24
  */
23
25
  var _default = exports.default = {
@@ -28,7 +30,9 @@ var _default = exports.default = {
28
30
  'no-classname-prop': _noClassnameProp.default,
29
31
  'no-container-queries': _noContainerQueries.default,
30
32
  'no-dynamic-styles': _noDynamicStyles.default,
33
+ 'no-exported-styles': _noExportedStyles.default,
31
34
  'no-important-styles': _noImportantStyles.default,
35
+ 'no-imported-style-values': _noImportedStyleValues.default,
32
36
  'no-nested-selectors': _noNestedSelectors.default,
33
37
  'no-unsafe-values': _noUnsafeValues.default
34
38
  };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.rule = exports.default = void 0;
7
+ var _createRule = require("../utils/create-rule");
8
+ var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
9
+ var _createNoExportedRule = require("@atlaskit/eslint-utils/create-no-exported-rule");
10
+ var schema = [{
11
+ type: 'object',
12
+ properties: {
13
+ importSources: {
14
+ type: 'array',
15
+ items: {
16
+ type: 'string'
17
+ },
18
+ uniqueItems: true
19
+ }
20
+ }
21
+ }];
22
+ var supportedImports = [_isSupportedImport.isCss, _isSupportedImport.isCssMap, _isSupportedImport.isKeyframes, _isSupportedImport.isXcss, _isSupportedImport.isStyled];
23
+ var rule = exports.rule = (0, _createRule.createLintRule)({
24
+ meta: {
25
+ name: 'no-exported-styles',
26
+ docs: {
27
+ description: 'Disallows exports of css, keyframes, styled and xcss',
28
+ recommended: true,
29
+ severity: 'warn'
30
+ },
31
+ messages: {
32
+ 'no-exported-styles': 'Styles from css, cssMap, keyframes, styled and xcss should not be exported. All styles should be defined and used in the same file instead.'
33
+ },
34
+ type: 'problem',
35
+ schema: schema
36
+ },
37
+ create: (0, _createNoExportedRule.createNoExportedRule)(supportedImports, 'no-exported-styles')
38
+ });
39
+ var _default = exports.default = rule;
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.rule = exports.default = void 0;
8
+ var _createRule = require("../utils/create-rule");
9
+ var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
10
+ var _findVariable = require("@atlaskit/eslint-utils/find-variable");
11
+ var _allowedFunctionCalls = require("@atlaskit/eslint-utils/allowed-function-calls");
12
+ var _esquery = _interopRequireDefault(require("esquery"));
13
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
14
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
15
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
16
+ var schema = [{
17
+ type: 'object',
18
+ properties: {
19
+ importSources: {
20
+ type: 'array',
21
+ items: {
22
+ type: 'string'
23
+ },
24
+ uniqueItems: true
25
+ },
26
+ allowedFunctionCalls: {
27
+ type: 'array',
28
+ items: {
29
+ type: 'array',
30
+ minItems: 2,
31
+ maxItems: 2,
32
+ items: [{
33
+ type: 'string'
34
+ }, {
35
+ type: 'string'
36
+ }]
37
+ },
38
+ uniqueItems: true
39
+ },
40
+ allowedDynamicKeys: {
41
+ type: 'array',
42
+ items: {
43
+ type: 'array',
44
+ minItems: 2,
45
+ maxItems: 2,
46
+ items: [{
47
+ type: 'string'
48
+ }, {
49
+ type: 'string'
50
+ }]
51
+ },
52
+ uniqueItems: true
53
+ }
54
+ }
55
+ }];
56
+ var isIdentifierImported = function isIdentifierImported(identifier, context, functionAllowList, keysAllowList) {
57
+ var variable = (0, _findVariable.findVariable)({
58
+ identifier: identifier,
59
+ sourceCode: context.sourceCode
60
+ });
61
+ if (!variable) {
62
+ return false;
63
+ }
64
+ var isImported = variable.defs.some(function (definition) {
65
+ return definition.type === 'ImportBinding';
66
+ });
67
+
68
+ // check if imported variable is allowed
69
+ return isImported && !(0, _allowedFunctionCalls.isAllowListedVariable)({
70
+ allowList: functionAllowList,
71
+ variable: variable
72
+ }) && !(0, _allowedFunctionCalls.isAllowListedVariable)({
73
+ allowList: keysAllowList,
74
+ variable: variable
75
+ });
76
+ };
77
+ var checkIdentifier = function checkIdentifier(identifier, context, functionAllowList, keysAllowList) {
78
+ if (isIdentifierImported(identifier, context, functionAllowList, keysAllowList)) {
79
+ context.report({
80
+ node: identifier,
81
+ messageId: 'no-imported-style-values'
82
+ });
83
+ }
84
+ };
85
+ var rule = exports.rule = (0, _createRule.createLintRule)({
86
+ meta: {
87
+ name: 'no-imported-style-values',
88
+ docs: {
89
+ description: 'Disallows imports of style values',
90
+ recommended: true,
91
+ severity: 'warn'
92
+ },
93
+ messages: {
94
+ 'no-imported-style-values': 'Styles should not be imported to use in css, cssMap, styled, keyframes or xcss calls. All styles should be defined and used in the same file instead.'
95
+ },
96
+ type: 'problem',
97
+ schema: schema
98
+ },
99
+ create: function create(context) {
100
+ var importSources = (0, _isSupportedImport.getImportSources)(context);
101
+ var functionAllowList = (0, _allowedFunctionCalls.getAllowedFunctionCalls)(context.options);
102
+ var keysAllowList = (0, _allowedFunctionCalls.getAllowedDynamicKeys)(context.options);
103
+ var checkForIdentifiers = function checkForIdentifiers(node) {
104
+ var matches = (0, _esquery.default)(node, 'Identifier');
105
+ var _iterator = _createForOfIteratorHelper(matches),
106
+ _step;
107
+ try {
108
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
109
+ var match = _step.value;
110
+ if (match.type === 'Identifier') {
111
+ checkIdentifier(match, context, functionAllowList, keysAllowList);
112
+ }
113
+ }
114
+ } catch (err) {
115
+ _iterator.e(err);
116
+ } finally {
117
+ _iterator.f();
118
+ }
119
+ };
120
+ return {
121
+ // Checking css/cssMap/keyframes/styled/xcss calls
122
+ CallExpression: function CallExpression(node) {
123
+ var _context$sourceCode$g = context.sourceCode.getScope(node.callee),
124
+ references = _context$sourceCode$g.references;
125
+ if (!(0, _isSupportedImport.hasStyleObjectArguments)(node.callee, references, importSources)) {
126
+ return;
127
+ }
128
+ node.arguments.forEach(checkForIdentifiers);
129
+ },
130
+ 'JSXAttribute[name.name="css"] Identifier': function JSXAttributeNameNameCssIdentifier(node) {
131
+ if (node.type !== 'Identifier') {
132
+ return;
133
+ }
134
+ checkIdentifier(node, context, functionAllowList, keysAllowList);
135
+ },
136
+ 'JSXAttribute[name.name="style"] Identifier': function JSXAttributeNameNameStyleIdentifier(node) {
137
+ if (node.type !== 'Identifier') {
138
+ return;
139
+ }
140
+ checkIdentifier(node, context, functionAllowList, keysAllowList);
141
+ }
142
+ };
143
+ }
144
+ });
145
+ var _default = exports.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::544c8b1c0eb0d6329064dcf92e18e45e>>
3
+ * @codegen <<SignedSource::96336e6094dbcbf456aaef313b624fbf>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -13,7 +13,9 @@ export default {
13
13
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
14
14
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
15
15
  '@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
16
+ '@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
16
17
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
18
+ '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
17
19
  '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
18
20
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
19
21
  '@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
@@ -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::544c8b1c0eb0d6329064dcf92e18e45e>>
3
+ * @codegen <<SignedSource::96336e6094dbcbf456aaef313b624fbf>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -13,7 +13,9 @@ export default {
13
13
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
14
14
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
15
15
  '@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
16
+ '@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
16
17
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
18
+ '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
17
19
  '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
18
20
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
19
21
  '@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
@@ -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::edaedcad824fed1e108f90d909287584>>
3
+ * @codegen <<SignedSource::648acb81f0f43d8ce56f7d6c22db8856>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import convertPropsSyntax from './convert-props-syntax';
@@ -10,7 +10,9 @@ import noArrayArguments from './no-array-arguments';
10
10
  import noClassnameProp from './no-classname-prop';
11
11
  import noContainerQueries from './no-container-queries';
12
12
  import noDynamicStyles from './no-dynamic-styles';
13
+ import noExportedStyles from './no-exported-styles';
13
14
  import noImportantStyles from './no-important-styles';
15
+ import noImportedStyleValues from './no-imported-style-values';
14
16
  import noNestedSelectors from './no-nested-selectors';
15
17
  import noUnsafeValues from './no-unsafe-values';
16
18
  export default {
@@ -21,7 +23,9 @@ export default {
21
23
  'no-classname-prop': noClassnameProp,
22
24
  'no-container-queries': noContainerQueries,
23
25
  'no-dynamic-styles': noDynamicStyles,
26
+ 'no-exported-styles': noExportedStyles,
24
27
  'no-important-styles': noImportantStyles,
28
+ 'no-imported-style-values': noImportedStyleValues,
25
29
  'no-nested-selectors': noNestedSelectors,
26
30
  'no-unsafe-values': noUnsafeValues
27
31
  };
@@ -0,0 +1,33 @@
1
+ import { createLintRule } from '../utils/create-rule';
2
+ import { isCss, isStyled, isKeyframes, isCssMap, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
3
+ import { createNoExportedRule } from '@atlaskit/eslint-utils/create-no-exported-rule';
4
+ const schema = [{
5
+ type: 'object',
6
+ properties: {
7
+ importSources: {
8
+ type: 'array',
9
+ items: {
10
+ type: 'string'
11
+ },
12
+ uniqueItems: true
13
+ }
14
+ }
15
+ }];
16
+ const supportedImports = [isCss, isCssMap, isKeyframes, isXcss, isStyled];
17
+ export const rule = createLintRule({
18
+ meta: {
19
+ name: 'no-exported-styles',
20
+ docs: {
21
+ description: 'Disallows exports of css, keyframes, styled and xcss',
22
+ recommended: true,
23
+ severity: 'warn'
24
+ },
25
+ messages: {
26
+ 'no-exported-styles': 'Styles from css, cssMap, keyframes, styled and xcss should not be exported. All styles should be defined and used in the same file instead.'
27
+ },
28
+ type: 'problem',
29
+ schema
30
+ },
31
+ create: createNoExportedRule(supportedImports, 'no-exported-styles')
32
+ });
33
+ export default rule;