@atlaskit/eslint-plugin-design-system 8.23.4 → 8.24.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 8.24.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#70036](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/70036) [`667c0a990b15`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/667c0a990b15) - Allow linting of multiple property style objects in use-primitives rule.
8
+
3
9
  ## 8.23.4
4
10
 
5
11
  ### Patch Changes
@@ -15,7 +15,25 @@ var ASTObjectExpression = exports.Object = {
15
15
  return !!ASTObjectExpression.getProperty(node, name);
16
16
  },
17
17
  /**
18
- * Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`
18
+ * Returns true if an object contains no nested values, false otherwise.
19
+ *
20
+ * Note:
21
+ * - Returns false if object contains spread elements.
22
+ * - Returns true if object is empty.
23
+ */
24
+ isFlat: function isFlat(node) {
25
+ return node.properties.every(function (entry) {
26
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(entry, 'Property')) {
27
+ return false;
28
+ }
29
+ if ((0, _eslintCodemodUtils.isNodeOfType)(entry.value, 'ObjectExpression')) {
30
+ return false;
31
+ }
32
+ return true;
33
+ });
34
+ },
35
+ /**
36
+ * Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`.
19
37
  */
20
38
  getEntryByPropertyName: function getEntryByPropertyName(node, name) {
21
39
  return node.properties.find(function (property) {
@@ -36,16 +54,16 @@ var ASTObjectExpression = exports.Object = {
36
54
  return [fixer.remove(entry)];
37
55
  },
38
56
  /**
39
- * Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`
57
+ * Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`.
40
58
  */
41
59
  getProperty: function getProperty(node, name) {
42
60
  var _ASTObjectExpression$;
43
61
  return (_ASTObjectExpression$ = ASTObjectExpression.getEntryByPropertyName(node, name)) === null || _ASTObjectExpression$ === void 0 ? void 0 : _ASTObjectExpression$.key;
44
62
  },
45
63
  /**
46
- * Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`
64
+ * Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`.
47
65
  *
48
- * Values can be basically anything, so be careful with this
66
+ * Values can be basically anything, so be careful with this.
49
67
  */
50
68
  getValueByPropertyName: function getValueByPropertyName(node, name) {
51
69
  var _ASTObjectExpression$2;
@@ -73,7 +91,7 @@ var ASTObjectExpression = exports.Object = {
73
91
  * fixer,
74
92
  * )
75
93
  * ```
76
- * Will result in `{ padding: 'space.100', margin: 'space.200'}`
94
+ * Will result in `{ padding: 'space.100', margin: 'space.200'}`.
77
95
  */
78
96
  appendEntry: function appendEntry(node, key, value, fixer) {
79
97
  return fixer.insertTextAfter(node.properties[node.properties.length - 1], "".concat((0, _eslintCodemodUtils.property)({
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof3 = require("@babel/runtime/helpers/typeof");
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
@@ -8,9 +9,12 @@ exports.isValidCssPropertiesToTransform = void 0;
8
9
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
10
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
11
  var _eslintCodemodUtils = require("eslint-codemod-utils");
12
+ var ast = _interopRequireWildcard(require("../../../ast-nodes"));
11
13
  var _cssToXcss = require("../transformers/css-to-xcss");
12
14
  var _convertAstObjectExpressionToJsObject = require("./convert-ast-object-expression-to-js-object");
13
15
  var _excluded = ["unsupported"];
16
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
18
  var isValidCssPropertiesToTransform = exports.isValidCssPropertiesToTransform = function isValidCssPropertiesToTransform(node, config) {
15
19
  if (!node) {
16
20
  return false;
@@ -20,13 +24,20 @@ var isValidCssPropertiesToTransform = exports.isValidCssPropertiesToTransform =
20
24
  if (!cssObjectExpression || !(0, _eslintCodemodUtils.isNodeOfType)(cssObjectExpression, 'ObjectExpression')) {
21
25
  return false;
22
26
  }
27
+ if (!ast.Object.isFlat(cssObjectExpression)) {
28
+ return false;
29
+ }
23
30
  var _convertASTObjectExpr = (0, _convertAstObjectExpressionToJsObject.convertASTObjectExpressionToJSObject)(cssObjectExpression),
24
31
  unsupported = _convertASTObjectExpr.unsupported,
25
32
  cssObject = (0, _objectWithoutProperties2.default)(_convertASTObjectExpr, _excluded);
26
33
  // Bail if there are any unsupported styles
27
- if (unsupported.length > 0 || Object.keys(cssObject).length !== 1) {
34
+ if (unsupported.length > 0) {
28
35
  return false;
29
36
  }
37
+ if (!config.patterns.includes('multiple-properties') && Object.keys(cssObject).length > 1) {
38
+ return false;
39
+ }
40
+
30
41
  // Short-circuit when token calls are found but pattern is not enabled in config
31
42
  if (!config.patterns.includes('css-property-with-tokens') && Object.values(cssObject).some(function (value) {
32
43
  return (0, _typeof2.default)(value) === 'object' && value.tokenName;
@@ -9,7 +9,25 @@ const ASTObjectExpression = {
9
9
  return !!ASTObjectExpression.getProperty(node, name);
10
10
  },
11
11
  /**
12
- * Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`
12
+ * Returns true if an object contains no nested values, false otherwise.
13
+ *
14
+ * Note:
15
+ * - Returns false if object contains spread elements.
16
+ * - Returns true if object is empty.
17
+ */
18
+ isFlat(node) {
19
+ return node.properties.every(entry => {
20
+ if (!isNodeOfType(entry, 'Property')) {
21
+ return false;
22
+ }
23
+ if (isNodeOfType(entry.value, 'ObjectExpression')) {
24
+ return false;
25
+ }
26
+ return true;
27
+ });
28
+ },
29
+ /**
30
+ * Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`.
13
31
  */
14
32
  getEntryByPropertyName(node, name) {
15
33
  return node.properties.find(property => {
@@ -30,16 +48,16 @@ const ASTObjectExpression = {
30
48
  return [fixer.remove(entry)];
31
49
  },
32
50
  /**
33
- * Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`
51
+ * Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`.
34
52
  */
35
53
  getProperty(node, name) {
36
54
  var _ASTObjectExpression$;
37
55
  return (_ASTObjectExpression$ = ASTObjectExpression.getEntryByPropertyName(node, name)) === null || _ASTObjectExpression$ === void 0 ? void 0 : _ASTObjectExpression$.key;
38
56
  },
39
57
  /**
40
- * Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`
58
+ * Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`.
41
59
  *
42
- * Values can be basically anything, so be careful with this
60
+ * Values can be basically anything, so be careful with this.
43
61
  */
44
62
  getValueByPropertyName(node, name) {
45
63
  var _ASTObjectExpression$2;
@@ -67,7 +85,7 @@ const ASTObjectExpression = {
67
85
  * fixer,
68
86
  * )
69
87
  * ```
70
- * Will result in `{ padding: 'space.100', margin: 'space.200'}`
88
+ * Will result in `{ padding: 'space.100', margin: 'space.200'}`.
71
89
  */
72
90
  appendEntry(node, key, value, fixer) {
73
91
  return fixer.insertTextAfter(node.properties[node.properties.length - 1], `${property({
@@ -1,4 +1,5 @@
1
1
  import { isNodeOfType } from 'eslint-codemod-utils';
2
+ import * as ast from '../../../ast-nodes';
2
3
  import { supportedStylesMap } from '../transformers/css-to-xcss';
3
4
  import { convertASTObjectExpressionToJSObject } from './convert-ast-object-expression-to-js-object';
4
5
  export const isValidCssPropertiesToTransform = (node, config) => {
@@ -10,14 +11,21 @@ export const isValidCssPropertiesToTransform = (node, config) => {
10
11
  if (!cssObjectExpression || !isNodeOfType(cssObjectExpression, 'ObjectExpression')) {
11
12
  return false;
12
13
  }
14
+ if (!ast.Object.isFlat(cssObjectExpression)) {
15
+ return false;
16
+ }
13
17
  const {
14
18
  unsupported,
15
19
  ...cssObject
16
20
  } = convertASTObjectExpressionToJSObject(cssObjectExpression);
17
21
  // Bail if there are any unsupported styles
18
- if (unsupported.length > 0 || Object.keys(cssObject).length !== 1) {
22
+ if (unsupported.length > 0) {
19
23
  return false;
20
24
  }
25
+ if (!config.patterns.includes('multiple-properties') && Object.keys(cssObject).length > 1) {
26
+ return false;
27
+ }
28
+
21
29
  // Short-circuit when token calls are found but pattern is not enabled in config
22
30
  if (!config.patterns.includes('css-property-with-tokens') && Object.values(cssObject).some(value => typeof value === 'object' && value.tokenName)) {
23
31
  return false;
@@ -9,7 +9,25 @@ var ASTObjectExpression = {
9
9
  return !!ASTObjectExpression.getProperty(node, name);
10
10
  },
11
11
  /**
12
- * Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`
12
+ * Returns true if an object contains no nested values, false otherwise.
13
+ *
14
+ * Note:
15
+ * - Returns false if object contains spread elements.
16
+ * - Returns true if object is empty.
17
+ */
18
+ isFlat: function isFlat(node) {
19
+ return node.properties.every(function (entry) {
20
+ if (!isNodeOfType(entry, 'Property')) {
21
+ return false;
22
+ }
23
+ if (isNodeOfType(entry.value, 'ObjectExpression')) {
24
+ return false;
25
+ }
26
+ return true;
27
+ });
28
+ },
29
+ /**
30
+ * Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`.
13
31
  */
14
32
  getEntryByPropertyName: function getEntryByPropertyName(node, name) {
15
33
  return node.properties.find(function (property) {
@@ -30,16 +48,16 @@ var ASTObjectExpression = {
30
48
  return [fixer.remove(entry)];
31
49
  },
32
50
  /**
33
- * Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`
51
+ * Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`.
34
52
  */
35
53
  getProperty: function getProperty(node, name) {
36
54
  var _ASTObjectExpression$;
37
55
  return (_ASTObjectExpression$ = ASTObjectExpression.getEntryByPropertyName(node, name)) === null || _ASTObjectExpression$ === void 0 ? void 0 : _ASTObjectExpression$.key;
38
56
  },
39
57
  /**
40
- * Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`
58
+ * Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`.
41
59
  *
42
- * Values can be basically anything, so be careful with this
60
+ * Values can be basically anything, so be careful with this.
43
61
  */
44
62
  getValueByPropertyName: function getValueByPropertyName(node, name) {
45
63
  var _ASTObjectExpression$2;
@@ -67,7 +85,7 @@ var ASTObjectExpression = {
67
85
  * fixer,
68
86
  * )
69
87
  * ```
70
- * Will result in `{ padding: 'space.100', margin: 'space.200'}`
88
+ * Will result in `{ padding: 'space.100', margin: 'space.200'}`.
71
89
  */
72
90
  appendEntry: function appendEntry(node, key, value, fixer) {
73
91
  return fixer.insertTextAfter(node.properties[node.properties.length - 1], "".concat(property({
@@ -2,6 +2,7 @@ import _typeof from "@babel/runtime/helpers/typeof";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
3
  var _excluded = ["unsupported"];
4
4
  import { isNodeOfType } from 'eslint-codemod-utils';
5
+ import * as ast from '../../../ast-nodes';
5
6
  import { supportedStylesMap } from '../transformers/css-to-xcss';
6
7
  import { convertASTObjectExpressionToJSObject } from './convert-ast-object-expression-to-js-object';
7
8
  export var isValidCssPropertiesToTransform = function isValidCssPropertiesToTransform(node, config) {
@@ -13,13 +14,20 @@ export var isValidCssPropertiesToTransform = function isValidCssPropertiesToTran
13
14
  if (!cssObjectExpression || !isNodeOfType(cssObjectExpression, 'ObjectExpression')) {
14
15
  return false;
15
16
  }
17
+ if (!ast.Object.isFlat(cssObjectExpression)) {
18
+ return false;
19
+ }
16
20
  var _convertASTObjectExpr = convertASTObjectExpressionToJSObject(cssObjectExpression),
17
21
  unsupported = _convertASTObjectExpr.unsupported,
18
22
  cssObject = _objectWithoutProperties(_convertASTObjectExpr, _excluded);
19
23
  // Bail if there are any unsupported styles
20
- if (unsupported.length > 0 || Object.keys(cssObject).length !== 1) {
24
+ if (unsupported.length > 0) {
21
25
  return false;
22
26
  }
27
+ if (!config.patterns.includes('multiple-properties') && Object.keys(cssObject).length > 1) {
28
+ return false;
29
+ }
30
+
23
31
  // Short-circuit when token calls are found but pattern is not enabled in config
24
32
  if (!config.patterns.includes('css-property-with-tokens') && Object.values(cssObject).some(function (value) {
25
33
  return _typeof(value) === 'object' && value.tokenName;
@@ -6,18 +6,26 @@ declare const ASTObjectExpression: {
6
6
  */
7
7
  hasProperty(node: ObjectExpression, name: string): boolean;
8
8
  /**
9
- * Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`
9
+ * Returns true if an object contains no nested values, false otherwise.
10
+ *
11
+ * Note:
12
+ * - Returns false if object contains spread elements.
13
+ * - Returns true if object is empty.
14
+ */
15
+ isFlat(node: ObjectExpression): boolean;
16
+ /**
17
+ * Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`.
10
18
  */
11
19
  getEntryByPropertyName(node: ObjectExpression, name: string): Property | undefined;
12
20
  deleteEntry(node: ObjectExpression, name: string, fixer: Rule.RuleFixer): Rule.Fix[];
13
21
  /**
14
- * Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`
22
+ * Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`.
15
23
  */
16
24
  getProperty(node: ObjectExpression, name: string): Property['key'] | undefined;
17
25
  /**
18
- * Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`
26
+ * Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`.
19
27
  *
20
- * Values can be basically anything, so be careful with this
28
+ * Values can be basically anything, so be careful with this.
21
29
  */
22
30
  getValueByPropertyName(node: ObjectExpression, name: string): Property['value'] | undefined;
23
31
  containsSpreadProps(node: ObjectExpression): boolean;
@@ -32,7 +40,7 @@ declare const ASTObjectExpression: {
32
40
  * fixer,
33
41
  * )
34
42
  * ```
35
- * Will result in `{ padding: 'space.100', margin: 'space.200'}`
43
+ * Will result in `{ padding: 'space.100', margin: 'space.200'}`.
36
44
  */
37
45
  appendEntry(node: ObjectExpression, key: string, value: string, fixer: Rule.RuleFixer): Rule.Fix;
38
46
  };
@@ -1,4 +1,4 @@
1
- type Pattern = 'compiled-css-function' | 'compiled-styled-object' | 'css-template-literal' | 'css-property-with-tokens' | 'css-property-multiple-values';
1
+ type Pattern = 'compiled-css-function' | 'compiled-styled-object' | 'css-template-literal' | 'css-property-with-tokens' | 'css-property-multiple-values' | 'multiple-properties';
2
2
  export interface RuleConfig {
3
3
  patterns: Pattern[];
4
4
  }
@@ -6,18 +6,26 @@ declare const ASTObjectExpression: {
6
6
  */
7
7
  hasProperty(node: ObjectExpression, name: string): boolean;
8
8
  /**
9
- * Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`
9
+ * Returns true if an object contains no nested values, false otherwise.
10
+ *
11
+ * Note:
12
+ * - Returns false if object contains spread elements.
13
+ * - Returns true if object is empty.
14
+ */
15
+ isFlat(node: ObjectExpression): boolean;
16
+ /**
17
+ * Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`.
10
18
  */
11
19
  getEntryByPropertyName(node: ObjectExpression, name: string): Property | undefined;
12
20
  deleteEntry(node: ObjectExpression, name: string, fixer: Rule.RuleFixer): Rule.Fix[];
13
21
  /**
14
- * Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`
22
+ * Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`.
15
23
  */
16
24
  getProperty(node: ObjectExpression, name: string): Property['key'] | undefined;
17
25
  /**
18
- * Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`
26
+ * Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`.
19
27
  *
20
- * Values can be basically anything, so be careful with this
28
+ * Values can be basically anything, so be careful with this.
21
29
  */
22
30
  getValueByPropertyName(node: ObjectExpression, name: string): Property['value'] | undefined;
23
31
  containsSpreadProps(node: ObjectExpression): boolean;
@@ -32,7 +40,7 @@ declare const ASTObjectExpression: {
32
40
  * fixer,
33
41
  * )
34
42
  * ```
35
- * Will result in `{ padding: 'space.100', margin: 'space.200'}`
43
+ * Will result in `{ padding: 'space.100', margin: 'space.200'}`.
36
44
  */
37
45
  appendEntry(node: ObjectExpression, key: string, value: string, fixer: Rule.RuleFixer): Rule.Fix;
38
46
  };
@@ -1,4 +1,4 @@
1
- type Pattern = 'compiled-css-function' | 'compiled-styled-object' | 'css-template-literal' | 'css-property-with-tokens' | 'css-property-multiple-values';
1
+ type Pattern = 'compiled-css-function' | 'compiled-styled-object' | 'css-template-literal' | 'css-property-with-tokens' | 'css-property-multiple-values' | 'multiple-properties';
2
2
  export interface RuleConfig {
3
3
  patterns: Pattern[];
4
4
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
3
  "description": "The essential plugin for use with the Atlassian Design System.",
4
- "version": "8.23.4",
4
+ "version": "8.24.0",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "publishConfig": {
7
7
  "registry": "https://registry.npmjs.org/"