@atlaskit/eslint-plugin-ui-styling-standard 0.8.3 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +1 -0
  3. package/constellation/index/overview.mdx +1 -0
  4. package/constellation/no-array-arguments/usage.mdx +45 -0
  5. package/dist/cjs/presets/all.codegen.js +2 -1
  6. package/dist/cjs/presets/recommended.codegen.js +2 -1
  7. package/dist/cjs/rules/index.codegen.js +3 -1
  8. package/dist/cjs/rules/no-array-arguments/index.js +92 -0
  9. package/dist/es2019/presets/all.codegen.js +2 -1
  10. package/dist/es2019/presets/recommended.codegen.js +2 -1
  11. package/dist/es2019/rules/index.codegen.js +3 -1
  12. package/dist/es2019/rules/no-array-arguments/index.js +68 -0
  13. package/dist/esm/presets/all.codegen.js +2 -1
  14. package/dist/esm/presets/recommended.codegen.js +2 -1
  15. package/dist/esm/rules/index.codegen.js +3 -1
  16. package/dist/esm/rules/no-array-arguments/index.js +86 -0
  17. package/dist/types/index.codegen.d.ts +2 -0
  18. package/dist/types/presets/all.codegen.d.ts +2 -1
  19. package/dist/types/presets/recommended.codegen.d.ts +2 -1
  20. package/dist/types/rules/index.codegen.d.ts +1 -0
  21. package/dist/types/rules/no-array-arguments/index.d.ts +2 -0
  22. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  23. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  24. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
  25. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  26. package/dist/types-ts4.5/rules/no-array-arguments/index.d.ts +2 -0
  27. package/package.json +7 -4
  28. package/src/presets/all.codegen.tsx +2 -1
  29. package/src/presets/recommended.codegen.tsx +2 -1
  30. package/src/rules/index.codegen.tsx +3 -1
  31. package/src/rules/no-array-arguments/README.md +43 -0
  32. package/src/rules/no-array-arguments/__tests__/rule.test.tsx +116 -0
  33. package/src/rules/no-array-arguments/index.tsx +87 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#91840](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/91840) [`997a3d2d0ca0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/997a3d2d0ca0) - Add `no-array-arguments` rule which prevents passing array arguments to style declaration functions.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+
13
+ ## 0.8.4
14
+
15
+ ### Patch Changes
16
+
17
+ - [#89936](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/89936) [`eb8f66c5d0f3`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/eb8f66c5d0f3) - Add @atlaskit/eslint-plugin-ui-styling-standard to the internal Atlassian push model.
18
+
3
19
  ## 0.8.3
4
20
 
5
21
  ### Patch Changes
package/README.md CHANGED
@@ -15,6 +15,7 @@ Not intended for use outside the Atlassian frontend repository.
15
15
  | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | ------- | ----------- |
16
16
  | <a href="./src/rules/convert-props-syntax/README.md">convert-props-syntax</a> | Convert props syntax that is unsupported by styled-components@<4 or @emotion/styled to props syntax that is supported. This is useful when used in conjunction with `no-styled-tagged-template-expression`, as output from the latter may use props syntax unsupported by those libraries. | Yes | Yes | |
17
17
  | <a href="./src/rules/local-cx-xcss/README.md">local-cx-xcss</a> | Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element. | Yes | | |
18
+ | <a href="./src/rules/no-array-arguments/README.md">no-array-arguments</a> | Prevents usage of array arguments to style declaration functions | Yes | Yes | |
18
19
  | <a href="./src/rules/no-classname-prop/README.md">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
19
20
  | <a href="./src/rules/no-container-queries/README.md">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
20
21
  | <a href="./src/rules/no-important-styles/README.md">no-important-styles</a> | Disallows important style declarations | Yes | | |
@@ -13,6 +13,7 @@ but more are planned to support the standard over time.
13
13
  | --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | ------- | ----------- |
14
14
  | <a href="convert-props-syntax/usage">convert-props-syntax</a> | Convert props syntax that is unsupported by styled-components@<4 or @emotion/styled to props syntax that is supported. This is useful when used in conjunction with `no-styled-tagged-template-expression`, as output from the latter may use props syntax unsupported by those libraries. | Yes | Yes | |
15
15
  | <a href="local-cx-xcss/usage">local-cx-xcss</a> | Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element. | Yes | | |
16
+ | <a href="no-array-arguments/usage">no-array-arguments</a> | Prevents usage of array arguments to style declaration functions | Yes | Yes | |
16
17
  | <a href="no-classname-prop/usage">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
17
18
  | <a href="no-container-queries/usage">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
18
19
  | <a href="no-important-styles/usage">no-important-styles</a> | Disallows important style declarations | Yes | | |
@@ -0,0 +1,45 @@
1
+ # no-array-arguments
2
+
3
+ This rule prevents usage of array arguments to style declaration functions.
4
+
5
+ ## Examples
6
+
7
+ ### Incorrect
8
+
9
+ ```js
10
+ import { css } from '@compiled/react';
11
+ const styles = css([{ width: 100 }, { height: 100 }]);
12
+ ```
13
+
14
+ ```js
15
+ import { styled } from '@compiled/react';
16
+ const styles = css([{ width: 100 }, ...items]);
17
+ ```
18
+
19
+ ### Correct
20
+
21
+ ```js
22
+ import { css } from '@compiled/react';
23
+ const styles = css({ width: 100 }, { height: 100 });
24
+ ```
25
+
26
+ ```js
27
+ import { css } from '@compiled/react';
28
+ const styles = css({ width: 100 }, ...items);
29
+ ```
30
+
31
+ ## Options
32
+
33
+ ### importSources
34
+
35
+ By default, this rule will check `css` usages from:
36
+
37
+ - `@atlaskit/css`
38
+ - `@atlaskit/primitives`
39
+ - `@compiled/react`
40
+ - `@emotion/react`
41
+ - `@emotion/core`
42
+ - `@emotion/styled`
43
+ - `styled-components`
44
+
45
+ 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::7d08e77b09892b3650a472341ec77df3>>
9
+ * @codegen <<SignedSource::d9829b8ad0e327987766d6901d0729b4>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -14,6 +14,7 @@ var _default = exports.default = {
14
14
  rules: {
15
15
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
16
16
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
17
+ '@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
17
18
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
18
19
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
19
20
  '@atlaskit/ui-styling-standard/no-important-styles': '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::7d08e77b09892b3650a472341ec77df3>>
9
+ * @codegen <<SignedSource::d9829b8ad0e327987766d6901d0729b4>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -14,6 +14,7 @@ var _default = exports.default = {
14
14
  rules: {
15
15
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
16
16
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
17
+ '@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
17
18
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
18
19
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
19
20
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
@@ -7,18 +7,20 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = void 0;
8
8
  var _convertPropsSyntax = _interopRequireDefault(require("./convert-props-syntax"));
9
9
  var _localCxXcss = _interopRequireDefault(require("./local-cx-xcss"));
10
+ var _noArrayArguments = _interopRequireDefault(require("./no-array-arguments"));
10
11
  var _noClassnameProp = _interopRequireDefault(require("./no-classname-prop"));
11
12
  var _noContainerQueries = _interopRequireDefault(require("./no-container-queries"));
12
13
  var _noImportantStyles = _interopRequireDefault(require("./no-important-styles"));
13
14
  var _noNestedSelectors = _interopRequireDefault(require("./no-nested-selectors"));
14
15
  /**
15
16
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
16
- * @codegen <<SignedSource::c50c5112f3633542ef17c291cd9d88a8>>
17
+ * @codegen <<SignedSource::f7d910c4a52a88b6aa58324ebe2edfc2>>
17
18
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
18
19
  */
19
20
  var _default = exports.default = {
20
21
  'convert-props-syntax': _convertPropsSyntax.default,
21
22
  'local-cx-xcss': _localCxXcss.default,
23
+ 'no-array-arguments': _noArrayArguments.default,
22
24
  'no-classname-prop': _noClassnameProp.default,
23
25
  'no-container-queries': _noContainerQueries.default,
24
26
  'no-important-styles': _noImportantStyles.default,
@@ -0,0 +1,92 @@
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
+ 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; } } }; }
10
+ 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); }
11
+ 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; }
12
+ var schema = [{
13
+ type: 'object',
14
+ properties: {
15
+ importSources: {
16
+ type: 'array',
17
+ items: {
18
+ type: 'string'
19
+ },
20
+ uniqueItems: true
21
+ }
22
+ }
23
+ }];
24
+ var rule = exports.rule = (0, _createRule.createLintRule)({
25
+ meta: {
26
+ name: 'no-array-arguments',
27
+ docs: {
28
+ description: 'Prevents usage of array arguments to style declaration functions',
29
+ recommended: true,
30
+ severity: 'warn'
31
+ },
32
+ messages: {
33
+ 'no-array-arguments': "Don't pass multiple value in an array. Pass them as multiple arguments instead."
34
+ },
35
+ type: 'problem',
36
+ fixable: 'code',
37
+ schema: schema
38
+ },
39
+ create: function create(context) {
40
+ var importSources = (0, _isSupportedImport.getImportSources)(context);
41
+ return {
42
+ CallExpression: function CallExpression(node) {
43
+ var _context$sourceCode$g = context.sourceCode.getScope(node),
44
+ references = _context$sourceCode$g.references;
45
+ if (!(0, _isSupportedImport.hasStyleObjectArguments)(node.callee, references, importSources)) {
46
+ return;
47
+ }
48
+ var _iterator = _createForOfIteratorHelper(node.arguments),
49
+ _step;
50
+ try {
51
+ var _loop = function _loop() {
52
+ var argument = _step.value;
53
+ if (argument.type === 'ArrayExpression') {
54
+ context.report({
55
+ node: argument,
56
+ messageId: 'no-array-arguments',
57
+ fix: function fix(fixer) {
58
+ if (argument.elements.length === 0) {
59
+ /**
60
+ * Don't autofix if it's an empty array.
61
+ *
62
+ * I couldn't figure out how to get rid of the comma afterwards,
63
+ * so the autofix was producing syntax problems.
64
+ *
65
+ * This is an edge case that shouldn't actually be happening,
66
+ * but if it does it's not hard to just delete the empty array...
67
+ */
68
+ return null;
69
+ }
70
+ var items = argument.elements.filter(function (value) {
71
+ return value !== null;
72
+ }).map(function (element) {
73
+ return context.sourceCode.getText(element);
74
+ });
75
+ return fixer.replaceText(argument, items.join(', '));
76
+ }
77
+ });
78
+ }
79
+ };
80
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
81
+ _loop();
82
+ }
83
+ } catch (err) {
84
+ _iterator.e(err);
85
+ } finally {
86
+ _iterator.f();
87
+ }
88
+ }
89
+ };
90
+ }
91
+ });
92
+ 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::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::d9829b8ad0e327987766d6901d0729b4>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -8,6 +8,7 @@ export default {
8
8
  rules: {
9
9
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
10
10
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
11
+ '@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
11
12
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
12
13
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
13
14
  '@atlaskit/ui-styling-standard/no-important-styles': '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::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::d9829b8ad0e327987766d6901d0729b4>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -8,6 +8,7 @@ export default {
8
8
  rules: {
9
9
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
10
10
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
11
+ '@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
11
12
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
12
13
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
13
14
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::c50c5112f3633542ef17c291cd9d88a8>>
3
+ * @codegen <<SignedSource::f7d910c4a52a88b6aa58324ebe2edfc2>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import convertPropsSyntax from './convert-props-syntax';
7
7
  import localCxXcss from './local-cx-xcss';
8
+ import noArrayArguments from './no-array-arguments';
8
9
  import noClassnameProp from './no-classname-prop';
9
10
  import noContainerQueries from './no-container-queries';
10
11
  import noImportantStyles from './no-important-styles';
@@ -12,6 +13,7 @@ import noNestedSelectors from './no-nested-selectors';
12
13
  export default {
13
14
  'convert-props-syntax': convertPropsSyntax,
14
15
  'local-cx-xcss': localCxXcss,
16
+ 'no-array-arguments': noArrayArguments,
15
17
  'no-classname-prop': noClassnameProp,
16
18
  'no-container-queries': noContainerQueries,
17
19
  'no-important-styles': noImportantStyles,
@@ -0,0 +1,68 @@
1
+ import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
2
+ import { createLintRule } from '../utils/create-rule';
3
+ const schema = [{
4
+ type: 'object',
5
+ properties: {
6
+ importSources: {
7
+ type: 'array',
8
+ items: {
9
+ type: 'string'
10
+ },
11
+ uniqueItems: true
12
+ }
13
+ }
14
+ }];
15
+ export const rule = createLintRule({
16
+ meta: {
17
+ name: 'no-array-arguments',
18
+ docs: {
19
+ description: 'Prevents usage of array arguments to style declaration functions',
20
+ recommended: true,
21
+ severity: 'warn'
22
+ },
23
+ messages: {
24
+ 'no-array-arguments': "Don't pass multiple value in an array. Pass them as multiple arguments instead."
25
+ },
26
+ type: 'problem',
27
+ fixable: 'code',
28
+ schema
29
+ },
30
+ create(context) {
31
+ const importSources = getImportSources(context);
32
+ return {
33
+ CallExpression(node) {
34
+ const {
35
+ references
36
+ } = context.sourceCode.getScope(node);
37
+ if (!hasStyleObjectArguments(node.callee, references, importSources)) {
38
+ return;
39
+ }
40
+ for (const argument of node.arguments) {
41
+ if (argument.type === 'ArrayExpression') {
42
+ context.report({
43
+ node: argument,
44
+ messageId: 'no-array-arguments',
45
+ fix(fixer) {
46
+ if (argument.elements.length === 0) {
47
+ /**
48
+ * Don't autofix if it's an empty array.
49
+ *
50
+ * I couldn't figure out how to get rid of the comma afterwards,
51
+ * so the autofix was producing syntax problems.
52
+ *
53
+ * This is an edge case that shouldn't actually be happening,
54
+ * but if it does it's not hard to just delete the empty array...
55
+ */
56
+ return null;
57
+ }
58
+ const items = argument.elements.filter(value => value !== null).map(element => context.sourceCode.getText(element));
59
+ return fixer.replaceText(argument, items.join(', '));
60
+ }
61
+ });
62
+ }
63
+ }
64
+ }
65
+ };
66
+ }
67
+ });
68
+ export default rule;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::d9829b8ad0e327987766d6901d0729b4>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -8,6 +8,7 @@ export default {
8
8
  rules: {
9
9
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
10
10
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
11
+ '@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
11
12
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
12
13
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
13
14
  '@atlaskit/ui-styling-standard/no-important-styles': '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::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::d9829b8ad0e327987766d6901d0729b4>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -8,6 +8,7 @@ export default {
8
8
  rules: {
9
9
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
10
10
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
11
+ '@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
11
12
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
12
13
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
13
14
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::c50c5112f3633542ef17c291cd9d88a8>>
3
+ * @codegen <<SignedSource::f7d910c4a52a88b6aa58324ebe2edfc2>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import convertPropsSyntax from './convert-props-syntax';
7
7
  import localCxXcss from './local-cx-xcss';
8
+ import noArrayArguments from './no-array-arguments';
8
9
  import noClassnameProp from './no-classname-prop';
9
10
  import noContainerQueries from './no-container-queries';
10
11
  import noImportantStyles from './no-important-styles';
@@ -12,6 +13,7 @@ import noNestedSelectors from './no-nested-selectors';
12
13
  export default {
13
14
  'convert-props-syntax': convertPropsSyntax,
14
15
  'local-cx-xcss': localCxXcss,
16
+ 'no-array-arguments': noArrayArguments,
15
17
  'no-classname-prop': noClassnameProp,
16
18
  'no-container-queries': noContainerQueries,
17
19
  'no-important-styles': noImportantStyles,
@@ -0,0 +1,86 @@
1
+ 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; } } }; }
2
+ 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); }
3
+ 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; }
4
+ import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
5
+ import { createLintRule } from '../utils/create-rule';
6
+ var schema = [{
7
+ type: 'object',
8
+ properties: {
9
+ importSources: {
10
+ type: 'array',
11
+ items: {
12
+ type: 'string'
13
+ },
14
+ uniqueItems: true
15
+ }
16
+ }
17
+ }];
18
+ export var rule = createLintRule({
19
+ meta: {
20
+ name: 'no-array-arguments',
21
+ docs: {
22
+ description: 'Prevents usage of array arguments to style declaration functions',
23
+ recommended: true,
24
+ severity: 'warn'
25
+ },
26
+ messages: {
27
+ 'no-array-arguments': "Don't pass multiple value in an array. Pass them as multiple arguments instead."
28
+ },
29
+ type: 'problem',
30
+ fixable: 'code',
31
+ schema: schema
32
+ },
33
+ create: function create(context) {
34
+ var importSources = getImportSources(context);
35
+ return {
36
+ CallExpression: function CallExpression(node) {
37
+ var _context$sourceCode$g = context.sourceCode.getScope(node),
38
+ references = _context$sourceCode$g.references;
39
+ if (!hasStyleObjectArguments(node.callee, references, importSources)) {
40
+ return;
41
+ }
42
+ var _iterator = _createForOfIteratorHelper(node.arguments),
43
+ _step;
44
+ try {
45
+ var _loop = function _loop() {
46
+ var argument = _step.value;
47
+ if (argument.type === 'ArrayExpression') {
48
+ context.report({
49
+ node: argument,
50
+ messageId: 'no-array-arguments',
51
+ fix: function fix(fixer) {
52
+ if (argument.elements.length === 0) {
53
+ /**
54
+ * Don't autofix if it's an empty array.
55
+ *
56
+ * I couldn't figure out how to get rid of the comma afterwards,
57
+ * so the autofix was producing syntax problems.
58
+ *
59
+ * This is an edge case that shouldn't actually be happening,
60
+ * but if it does it's not hard to just delete the empty array...
61
+ */
62
+ return null;
63
+ }
64
+ var items = argument.elements.filter(function (value) {
65
+ return value !== null;
66
+ }).map(function (element) {
67
+ return context.sourceCode.getText(element);
68
+ });
69
+ return fixer.replaceText(argument, items.join(', '));
70
+ }
71
+ });
72
+ }
73
+ };
74
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
75
+ _loop();
76
+ }
77
+ } catch (err) {
78
+ _iterator.e(err);
79
+ } finally {
80
+ _iterator.f();
81
+ }
82
+ }
83
+ };
84
+ }
85
+ });
86
+ export default rule;
@@ -5,6 +5,7 @@ export declare const configs: {
5
5
  rules: {
6
6
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
7
7
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
8
+ '@atlaskit/ui-styling-standard/no-array-arguments': string;
8
9
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
9
10
  '@atlaskit/ui-styling-standard/no-container-queries': string;
10
11
  '@atlaskit/ui-styling-standard/no-important-styles': string;
@@ -36,6 +37,7 @@ export declare const configs: {
36
37
  rules: {
37
38
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
38
39
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
40
+ '@atlaskit/ui-styling-standard/no-array-arguments': string;
39
41
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
40
42
  '@atlaskit/ui-styling-standard/no-container-queries': string;
41
43
  '@atlaskit/ui-styling-standard/no-important-styles': 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::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::d9829b8ad0e327987766d6901d0729b4>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  declare const _default: {
@@ -8,6 +8,7 @@ declare const _default: {
8
8
  rules: {
9
9
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
10
10
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
11
+ '@atlaskit/ui-styling-standard/no-array-arguments': string;
11
12
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
12
13
  '@atlaskit/ui-styling-standard/no-container-queries': string;
13
14
  '@atlaskit/ui-styling-standard/no-important-styles': 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::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::d9829b8ad0e327987766d6901d0729b4>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  declare const _default: {
@@ -8,6 +8,7 @@ declare const _default: {
8
8
  rules: {
9
9
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
10
10
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
11
+ '@atlaskit/ui-styling-standard/no-array-arguments': string;
11
12
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
12
13
  '@atlaskit/ui-styling-standard/no-container-queries': string;
13
14
  '@atlaskit/ui-styling-standard/no-important-styles': string;
@@ -1,6 +1,7 @@
1
1
  declare const _default: {
2
2
  'convert-props-syntax': import("eslint").Rule.RuleModule;
3
3
  'local-cx-xcss': import("eslint").Rule.RuleModule;
4
+ 'no-array-arguments': import("eslint").Rule.RuleModule;
4
5
  'no-classname-prop': import("eslint").Rule.RuleModule;
5
6
  'no-container-queries': import("eslint").Rule.RuleModule;
6
7
  'no-important-styles': import("eslint").Rule.RuleModule;
@@ -0,0 +1,2 @@
1
+ export declare const rule: import("eslint").Rule.RuleModule;
2
+ export default rule;
@@ -5,6 +5,7 @@ export declare const configs: {
5
5
  rules: {
6
6
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
7
7
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
8
+ '@atlaskit/ui-styling-standard/no-array-arguments': string;
8
9
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
9
10
  '@atlaskit/ui-styling-standard/no-container-queries': string;
10
11
  '@atlaskit/ui-styling-standard/no-important-styles': string;
@@ -36,6 +37,7 @@ export declare const configs: {
36
37
  rules: {
37
38
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
38
39
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
40
+ '@atlaskit/ui-styling-standard/no-array-arguments': string;
39
41
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
40
42
  '@atlaskit/ui-styling-standard/no-container-queries': string;
41
43
  '@atlaskit/ui-styling-standard/no-important-styles': 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::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::d9829b8ad0e327987766d6901d0729b4>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  declare const _default: {
@@ -8,6 +8,7 @@ declare const _default: {
8
8
  rules: {
9
9
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
10
10
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
11
+ '@atlaskit/ui-styling-standard/no-array-arguments': string;
11
12
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
12
13
  '@atlaskit/ui-styling-standard/no-container-queries': string;
13
14
  '@atlaskit/ui-styling-standard/no-important-styles': 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::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::d9829b8ad0e327987766d6901d0729b4>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  declare const _default: {
@@ -8,6 +8,7 @@ declare const _default: {
8
8
  rules: {
9
9
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
10
10
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
11
+ '@atlaskit/ui-styling-standard/no-array-arguments': string;
11
12
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
12
13
  '@atlaskit/ui-styling-standard/no-container-queries': string;
13
14
  '@atlaskit/ui-styling-standard/no-important-styles': string;
@@ -1,6 +1,7 @@
1
1
  declare const _default: {
2
2
  'convert-props-syntax': import("eslint").Rule.RuleModule;
3
3
  'local-cx-xcss': import("eslint").Rule.RuleModule;
4
+ 'no-array-arguments': import("eslint").Rule.RuleModule;
4
5
  'no-classname-prop': import("eslint").Rule.RuleModule;
5
6
  'no-container-queries': import("eslint").Rule.RuleModule;
6
7
  'no-important-styles': import("eslint").Rule.RuleModule;
@@ -0,0 +1,2 @@
1
+ export declare const rule: import("eslint").Rule.RuleModule;
2
+ export default rule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-ui-styling-standard",
3
- "version": "0.8.3",
3
+ "version": "0.9.0",
4
4
  "author": "Atlassian Pty Ltd",
5
5
  "description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
6
6
  "license": "Apache-2.0",
@@ -11,7 +11,10 @@
11
11
  "website": {
12
12
  "name": "UI Styling Standard",
13
13
  "category": "Tooling"
14
- }
14
+ },
15
+ "productPushConsumption": [
16
+ "jira"
17
+ ]
15
18
  },
16
19
  "publishConfig": {
17
20
  "registry": "https://registry.npmjs.org/"
@@ -36,7 +39,7 @@
36
39
  ".": "./src/index.tsx"
37
40
  },
38
41
  "dependencies": {
39
- "@atlaskit/eslint-utils": "^1.1.0",
42
+ "@atlaskit/eslint-utils": "^1.2.0",
40
43
  "@babel/runtime": "^7.0.0",
41
44
  "@typescript-eslint/utils": "^5.48.1",
42
45
  "eslint-codemod-utils": "^1.8.6",
@@ -44,7 +47,7 @@
44
47
  "estraverse": "^5.3.0"
45
48
  },
46
49
  "devDependencies": {
47
- "@atlaskit/ds-lib": "^2.2.0",
50
+ "@atlaskit/ds-lib": "^2.3.0",
48
51
  "@atlaskit/eslint-plugin-design-system": "^9.4.0",
49
52
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
50
53
  "@atlassian/codegen": "*",
@@ -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::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::d9829b8ad0e327987766d6901d0729b4>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -12,6 +12,7 @@ export default {
12
12
  rules: {
13
13
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
14
14
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
15
+ '@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
15
16
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
16
17
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
17
18
  '@atlaskit/ui-styling-standard/no-important-styles': '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::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::d9829b8ad0e327987766d6901d0729b4>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -12,6 +12,7 @@ export default {
12
12
  rules: {
13
13
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
14
14
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
15
+ '@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
15
16
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
16
17
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
17
18
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::c50c5112f3633542ef17c291cd9d88a8>>
3
+ * @codegen <<SignedSource::f7d910c4a52a88b6aa58324ebe2edfc2>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import convertPropsSyntax from './convert-props-syntax';
7
7
  import localCxXcss from './local-cx-xcss';
8
+ import noArrayArguments from './no-array-arguments';
8
9
  import noClassnameProp from './no-classname-prop';
9
10
  import noContainerQueries from './no-container-queries';
10
11
  import noImportantStyles from './no-important-styles';
@@ -13,6 +14,7 @@ import noNestedSelectors from './no-nested-selectors';
13
14
  export default {
14
15
  'convert-props-syntax': convertPropsSyntax,
15
16
  'local-cx-xcss': localCxXcss,
17
+ 'no-array-arguments': noArrayArguments,
16
18
  'no-classname-prop': noClassnameProp,
17
19
  'no-container-queries': noContainerQueries,
18
20
  'no-important-styles': noImportantStyles,
@@ -0,0 +1,43 @@
1
+ This rule prevents usage of array arguments to style declaration functions.
2
+
3
+ ## Examples
4
+
5
+ ### Incorrect
6
+
7
+ ```js
8
+ import { css } from '@compiled/react';
9
+ const styles = css([{ width: 100 }, { height: 100 }]);
10
+ ```
11
+
12
+ ```js
13
+ import { styled } from '@compiled/react';
14
+ const styles = css([{ width: 100 }, ...items]);
15
+ ```
16
+
17
+ ### Correct
18
+
19
+ ```js
20
+ import { css } from '@compiled/react';
21
+ const styles = css({ width: 100 }, { height: 100 });
22
+ ```
23
+
24
+ ```js
25
+ import { css } from '@compiled/react';
26
+ const styles = css({ width: 100 }, ...items);
27
+ ```
28
+
29
+ ## Options
30
+
31
+ ### importSources
32
+
33
+ By default, this rule will check `css` usages from:
34
+
35
+ - `@atlaskit/css`
36
+ - `@atlaskit/primitives`
37
+ - `@compiled/react`
38
+ - `@emotion/react`
39
+ - `@emotion/core`
40
+ - `@emotion/styled`
41
+ - `styled-components`
42
+
43
+ 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,116 @@
1
+ import { typescriptEslintTester } from '../../__tests__/utils/_tester';
2
+ import rule from '../index';
3
+
4
+ typescriptEslintTester.run(
5
+ 'no-nested-selectors',
6
+ // @ts-expect-error
7
+ rule,
8
+ {
9
+ valid: [],
10
+ invalid: [
11
+ {
12
+ name: 'single array argument',
13
+ code: `
14
+ import { css } from '@compiled/react';
15
+ const styles = css([
16
+ { width: 100 },
17
+ { height: 100 }
18
+ ]);
19
+ `,
20
+ output: `
21
+ import { css } from '@compiled/react';
22
+ const styles = css({ width: 100 }, { height: 100 });
23
+ `,
24
+ errors: [{ messageId: 'no-array-arguments' }],
25
+ },
26
+ {
27
+ name: 'multiple array arguments',
28
+ code: `
29
+ import { css } from '@compiled/react';
30
+ const styles = css(
31
+ [
32
+ { width: 100 },
33
+ { height: 100 }
34
+ ],
35
+ [
36
+ { color: 'red' }
37
+ ]
38
+ );
39
+ `,
40
+ output: `
41
+ import { css } from '@compiled/react';
42
+ const styles = css(
43
+ { width: 100 }, { height: 100 },
44
+ { color: 'red' }
45
+ );
46
+ `,
47
+ errors: [
48
+ { messageId: 'no-array-arguments' },
49
+ { messageId: 'no-array-arguments' },
50
+ ],
51
+ },
52
+ {
53
+ name: 'interspersed array arguments',
54
+ code: `
55
+ import { css } from '@compiled/react';
56
+ const styles = css(
57
+ { a: 1 },
58
+ [
59
+ { width: 100 },
60
+ { height: 100 }
61
+ ],
62
+ { b: 2 },
63
+ [
64
+ { color: 'red' },
65
+ { opacity: 0.5 },
66
+ ],
67
+ { c: 3 }
68
+ );
69
+ `,
70
+ output: `
71
+ import { css } from '@compiled/react';
72
+ const styles = css(
73
+ { a: 1 },
74
+ { width: 100 }, { height: 100 },
75
+ { b: 2 },
76
+ { color: 'red' }, { opacity: 0.5 },
77
+ { c: 3 }
78
+ );
79
+ `,
80
+ errors: [
81
+ { messageId: 'no-array-arguments' },
82
+ { messageId: 'no-array-arguments' },
83
+ ],
84
+ },
85
+ {
86
+ name: 'empty array argument',
87
+ code: `
88
+ import { css } from '@compiled/react';
89
+ const styles = css(
90
+ [],
91
+ { color: 'red' },
92
+ []
93
+ );
94
+ `,
95
+ errors: [
96
+ { messageId: 'no-array-arguments' },
97
+ { messageId: 'no-array-arguments' },
98
+ ],
99
+ },
100
+ {
101
+ name: 'spread in array',
102
+ code: `
103
+ import { css } from '@compiled/react';
104
+ const styles = css([
105
+ ...items
106
+ ]);
107
+ `,
108
+ output: `
109
+ import { css } from '@compiled/react';
110
+ const styles = css(...items);
111
+ `,
112
+ errors: [{ messageId: 'no-array-arguments' }],
113
+ },
114
+ ],
115
+ },
116
+ );
@@ -0,0 +1,87 @@
1
+ import type { Expression, SpreadElement } from 'estree';
2
+
3
+ import {
4
+ getImportSources,
5
+ hasStyleObjectArguments,
6
+ } from '@atlaskit/eslint-utils/is-supported-import';
7
+ import { createLintRule } from '../utils/create-rule';
8
+ import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
9
+
10
+ const schema: JSONSchema4 = [
11
+ {
12
+ type: 'object',
13
+ properties: {
14
+ importSources: {
15
+ type: 'array',
16
+ items: { type: 'string' },
17
+ uniqueItems: true,
18
+ },
19
+ },
20
+ },
21
+ ];
22
+
23
+ export const rule = createLintRule({
24
+ meta: {
25
+ name: 'no-array-arguments',
26
+ docs: {
27
+ description:
28
+ 'Prevents usage of array arguments to style declaration functions',
29
+ recommended: true,
30
+ severity: 'warn',
31
+ },
32
+ messages: {
33
+ 'no-array-arguments':
34
+ "Don't pass multiple value in an array. Pass them as multiple arguments instead.",
35
+ },
36
+ type: 'problem',
37
+ fixable: 'code',
38
+ schema,
39
+ },
40
+ create(context) {
41
+ const importSources = getImportSources(context);
42
+ return {
43
+ CallExpression(node) {
44
+ const { references } = context.sourceCode.getScope(node);
45
+
46
+ if (!hasStyleObjectArguments(node.callee, references, importSources)) {
47
+ return;
48
+ }
49
+
50
+ for (const argument of node.arguments) {
51
+ if (argument.type === 'ArrayExpression') {
52
+ context.report({
53
+ node: argument,
54
+ messageId: 'no-array-arguments',
55
+ fix(fixer) {
56
+ if (argument.elements.length === 0) {
57
+ /**
58
+ * Don't autofix if it's an empty array.
59
+ *
60
+ * I couldn't figure out how to get rid of the comma afterwards,
61
+ * so the autofix was producing syntax problems.
62
+ *
63
+ * This is an edge case that shouldn't actually be happening,
64
+ * but if it does it's not hard to just delete the empty array...
65
+ */
66
+ return null;
67
+ }
68
+
69
+ const items = argument.elements
70
+ .filter(
71
+ (
72
+ value: SpreadElement | Expression | null,
73
+ ): value is SpreadElement | Expression => value !== null,
74
+ )
75
+ .map((element) => context.sourceCode.getText(element));
76
+
77
+ return fixer.replaceText(argument, items.join(', '));
78
+ },
79
+ });
80
+ }
81
+ }
82
+ },
83
+ };
84
+ },
85
+ });
86
+
87
+ export default rule;