@atlaskit/eslint-plugin-design-system 8.19.2 → 8.21.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 (37) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +1 -0
  3. package/constellation/index/usage.mdx +61 -1
  4. package/dist/cjs/presets/all.codegen.js +2 -1
  5. package/dist/cjs/presets/recommended.codegen.js +2 -1
  6. package/dist/cjs/rules/consistent-css-prop-usage/index.js +13 -4
  7. package/dist/cjs/rules/index.codegen.js +3 -1
  8. package/dist/cjs/rules/use-button-group-label/index.js +83 -0
  9. package/dist/cjs/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.js +24 -32
  10. package/dist/cjs/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +7 -3
  11. package/dist/es2019/presets/all.codegen.js +2 -1
  12. package/dist/es2019/presets/recommended.codegen.js +2 -1
  13. package/dist/es2019/rules/consistent-css-prop-usage/index.js +12 -4
  14. package/dist/es2019/rules/index.codegen.js +3 -1
  15. package/dist/es2019/rules/use-button-group-label/index.js +75 -0
  16. package/dist/es2019/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.js +23 -32
  17. package/dist/es2019/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +6 -3
  18. package/dist/esm/presets/all.codegen.js +2 -1
  19. package/dist/esm/presets/recommended.codegen.js +2 -1
  20. package/dist/esm/rules/consistent-css-prop-usage/index.js +13 -4
  21. package/dist/esm/rules/index.codegen.js +3 -1
  22. package/dist/esm/rules/use-button-group-label/index.js +77 -0
  23. package/dist/esm/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.js +23 -32
  24. package/dist/esm/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +7 -3
  25. package/dist/types/index.codegen.d.ts +2 -0
  26. package/dist/types/presets/all.codegen.d.ts +2 -1
  27. package/dist/types/presets/recommended.codegen.d.ts +2 -1
  28. package/dist/types/rules/index.codegen.d.ts +1 -0
  29. package/dist/types/rules/use-button-group-label/index.d.ts +3 -0
  30. package/dist/types/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.d.ts +6 -2
  31. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  32. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  33. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
  34. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  35. package/dist/types-ts4.5/rules/use-button-group-label/index.d.ts +3 -0
  36. package/dist/types-ts4.5/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.d.ts +6 -2
  37. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 8.21.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#66250](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/66250) [`6ff74a16aee7`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/6ff74a16aee7) - Introducing new rule to encourage adding/referencing accessible name to a ButtonGroup component.
8
+
9
+ ## 8.20.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#66409](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/66409) [`f6c48f4a67c1`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f6c48f4a67c1) - Implemented functionality for the consistent-css-prop-usage rule to account for cssMap usages
14
+
15
+ ### Patch Changes
16
+
17
+ - [#66604](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/66604) [`3205b1daf57f`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3205b1daf57f) - Refactor internal logic of `use-primitives` to better handle cases it will not suggest transformations for, based on the value of CSS properties.
18
+
3
19
  ## 8.19.2
4
20
 
5
21
  ### Patch Changes
package/README.md CHANGED
@@ -65,6 +65,7 @@ module.exports = {
65
65
  | <a href="./src/rules/no-unsafe-style-overrides/README.md">no-unsafe-style-overrides</a> | Discourage usage of unsafe style overrides used against the Atlassian Design System. | Yes | | |
66
66
  | <a href="./src/rules/no-unsupported-drag-and-drop-libraries/README.md">no-unsupported-drag-and-drop-libraries</a> | Disallow importing unsupported drag and drop modules. | Yes | | |
67
67
  | <a href="./src/rules/prefer-primitives/README.md">prefer-primitives</a> | Increase awareness of primitive components via code hints. Strictly used for education purposes and discoverability. To enforce usage please refer to the `use-primitives` rule. | | | |
68
+ | <a href="./src/rules/use-button-group-label/README.md">use-button-group-label</a> | Ensures button groups are described to assistive technology by a direct label or by another element. | Yes | | Yes |
68
69
  | <a href="./src/rules/use-drawer-label/README.md">use-drawer-label</a> | Encourages to provide accessible name for Atlassian Design System Drawer component. | Yes | | Yes |
69
70
  | <a href="./src/rules/use-heading-level-in-spotlight-card/README.md">use-heading-level-in-spotlight-card</a> | Inform developers of eventual requirement of `headingLevel` prop in `SpotlightCard` component. The heading level should be the appropriate level according to the surrounding context. | Yes | Yes | |
70
71
  | <a href="./src/rules/use-href-in-link-item/README.md">use-href-in-link-item</a> | Inform developers of eventual requirement of `href` prop in `LinkItem` component. Elements with a `link` role require an `href` attribute for users to properly navigate, particularly those using assistive technologies. If no valid `href` is required for your use case, consider using a `ButtonItem` instead. | Yes | Yes | Yes |
@@ -29,6 +29,7 @@ This plugin contains rules that should be used when working with the [Atlassian
29
29
  | <a href="#no-unsafe-style-overrides">no-unsafe-style-overrides</a> | Discourage usage of unsafe style overrides used against the Atlassian Design System. | Yes | | |
30
30
  | <a href="#no-unsupported-drag-and-drop-libraries">no-unsupported-drag-and-drop-libraries</a> | Disallow importing unsupported drag and drop modules. | Yes | | |
31
31
  | <a href="#prefer-primitives">prefer-primitives</a> | Increase awareness of primitive components via code hints. Strictly used for education purposes and discoverability. To enforce usage please refer to the `use-primitives` rule. | | | |
32
+ | <a href="#use-button-group-label">use-button-group-label</a> | Ensures button groups are described to assistive technology by a direct label or by another element. | Yes | | Yes |
32
33
  | <a href="#use-drawer-label">use-drawer-label</a> | Encourages to provide accessible name for Atlassian Design System Drawer component. | Yes | | Yes |
33
34
  | <a href="#use-heading-level-in-spotlight-card">use-heading-level-in-spotlight-card</a> | Inform developers of eventual requirement of `headingLevel` prop in `SpotlightCard` component. The heading level should be the appropriate level according to the surrounding context. | Yes | Yes | |
34
35
  | <a href="#use-href-in-link-item">use-href-in-link-item</a> | Inform developers of eventual requirement of `href` prop in `LinkItem` component. Elements with a `link` role require an `href` attribute for users to properly navigate, particularly those using assistive technologies. If no valid `href` is required for your use case, consider using a `ButtonItem` instead. | Yes | Yes | Yes |
@@ -142,7 +143,7 @@ This rule comes with options to support different repository configurations.
142
143
 
143
144
  #### cssFunctions
144
145
 
145
- An array of function names the linting rule should target. Defaults to `['css', 'xcss']`.
146
+ An array of function names the linting rule should target. Defaults to `['css', 'xcss']`. Functionality of cssMap will be linted regardless of the configuration of `cssFunctions` as it can be used with either attribute.
146
147
 
147
148
  #### stylesPlacement
148
149
 
@@ -767,6 +768,65 @@ This rule marks code as violations when it may be able to be replaced with a pri
767
768
  </Component>
768
769
  ```
769
770
 
771
+ ## use-button-group-label
772
+
773
+ ButtonGroup should have an accessible name or a reference to it, so that upon opening, users of assistive technologies could have contextual information of interaction with current element.
774
+
775
+ <h3>Examples</h3>
776
+
777
+ This rule will indicate user with warning to strongly recommend usage of either `label` or `titleId` prop.
778
+
779
+ #### Incorrect
780
+
781
+ ```tsx
782
+ <ButtonGroup>
783
+ ^^^^^^^^^^^ Missing either `label` or `titleId` prop.
784
+ <Button>Save</Button>
785
+ <Button>Edit</Button>
786
+ <Button>Delete</Button>
787
+ </ButtonGroup>
788
+
789
+ <ButtonGroup label="">
790
+ ^^^^^ `label` prop is missing accessible name value.
791
+ <Button>Save</Button>
792
+ <Button>Edit</Button>
793
+ <Button>Delete</Button>
794
+ </ButtonGroup>
795
+
796
+ <h2 id="button-group-title">ButtonGroup content title</hi>
797
+ <ButtonGroup titleId="">
798
+ ^^^^^^^ `titleId` prop is missing reference value.
799
+ <Button>Save</Button>
800
+ <Button>Edit</Button>
801
+ <Button>Delete</Button>
802
+ </ButtonGroup>
803
+
804
+ <h2 id="button-group-title">ButtonGroup content title</h2>
805
+ <ButtonGroup titleId="button-group-title" label="">
806
+ ^^^^^^^ ^^^^^ Do not include both `titleId` and `label` properties. Use `titleId` if the label text is available in the DOM to reference it, otherwise use `label` to provide accessible name explicitly.
807
+ <Button>Save</Button>
808
+ <Button>Edit</Button>
809
+ <Button>Delete</Button>
810
+ </ButtonGroup>
811
+ ```
812
+
813
+ #### Correct
814
+
815
+ ```tsx
816
+ <ButtonGroup label="ButtonGroup content title">
817
+ <Button>Save</Button>
818
+ <Button>Edit</Button>
819
+ <Button>Delete</Button>
820
+ </ButtonGroup>
821
+
822
+ <h2 id="button-group-title">ButtonGroup content title</h2>
823
+ <ButtonGroup titleId="button-group-title">
824
+ <Button>Save</Button>
825
+ <Button>Edit</Button>
826
+ <Button>Delete</Button>
827
+ </ButtonGroup>
828
+ ```
829
+
770
830
  ## use-drawer-label
771
831
 
772
832
  Drawer should have an accessible name or a reference to it, so that upon opening, users of assistive technologies could have contextual information of interaction with current element.
@@ -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::6efa1e48692b3e287d6dfcd500a5f0ab>>
9
+ * @codegen <<SignedSource::d1a459e1ea71650f65b2890dc86cc398>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -28,6 +28,7 @@ var _default = exports.default = {
28
28
  '@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
29
29
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
30
30
  '@atlaskit/design-system/prefer-primitives': 'warn',
31
+ '@atlaskit/design-system/use-button-group-label': 'warn',
31
32
  '@atlaskit/design-system/use-drawer-label': 'warn',
32
33
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
33
34
  '@atlaskit/design-system/use-href-in-link-item': '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::be810d87ec2d253e3b053dc06ff1b99a>>
9
+ * @codegen <<SignedSource::3b93cfbbe0ea14514b9600509632394b>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -23,6 +23,7 @@ var _default = exports.default = {
23
23
  '@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
24
24
  '@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
25
25
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
26
+ '@atlaskit/design-system/use-button-group-label': 'warn',
26
27
  '@atlaskit/design-system/use-drawer-label': 'warn',
27
28
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
28
29
  '@atlaskit/design-system/use-href-in-link-item': 'warn',
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
10
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
11
  var _eslintCodemodUtils = require("eslint-codemod-utils");
11
12
  var _assign = _interopRequireDefault(require("lodash/assign"));
@@ -25,9 +26,9 @@ function findSpreadProperties(node) {
25
26
  });
26
27
  }
27
28
  function analyzeIdentifier(context, sourceIdentifier, configuration) {
28
- var _getIdentifierInParen;
29
+ var _getIdentifierInParen, _getIdentifierInParen2;
29
30
  var scope = context.getScope();
30
- var _ref = ((_getIdentifierInParen = (0, _eslintCodemodUtils.getIdentifierInParentScope)(scope, sourceIdentifier.name)) === null || _getIdentifierInParen === void 0 ? void 0 : _getIdentifierInParen.identifiers) || [],
31
+ var _ref = (_getIdentifierInParen = (_getIdentifierInParen2 = (0, _eslintCodemodUtils.getIdentifierInParentScope)(scope, sourceIdentifier.name)) === null || _getIdentifierInParen2 === void 0 ? void 0 : _getIdentifierInParen2.identifiers) !== null && _getIdentifierInParen !== void 0 ? _getIdentifierInParen : [],
31
32
  _ref2 = (0, _slicedToArray2.default)(_ref, 1),
32
33
  identifier = _ref2[0];
33
34
  if (!identifier || !identifier.parent) {
@@ -50,7 +51,7 @@ function analyzeIdentifier(context, sourceIdentifier, configuration) {
50
51
  });
51
52
  return;
52
53
  }
53
- if (identifier.parent && identifier.parent.init && !isCssCallExpression(identifier.parent.init, configuration.cssFunctions)) {
54
+ if (identifier.parent && identifier.parent.init && !isCssCallExpression(identifier.parent.init, [].concat((0, _toConsumableArray2.default)(configuration.cssFunctions), ['cssMap']))) {
54
55
  // When variable value is not of type css({})
55
56
  context.report({
56
57
  node: identifier,
@@ -69,6 +70,13 @@ function analyzeIdentifier(context, sourceIdentifier, configuration) {
69
70
  });
70
71
  }
71
72
  }
73
+
74
+ /**
75
+ * Handle different cases based on what's been passed in the css-related JSXAttribute
76
+ * @param context the context of the node
77
+ * @param expression the expression of the JSXAttribute value
78
+ * @param configuration what css-related functions to account for (eg. css, xcss, cssMap), and whether to detect bottom vs top expressions
79
+ */
72
80
  var traverseExpressionWithConfig = function traverseExpressionWithConfig(context, expression, configuration) {
73
81
  function traverseExpression(expression) {
74
82
  switch (expression.type) {
@@ -140,7 +148,8 @@ var rule = (0, _createRule.createLintRule)({
140
148
  create: function create(context) {
141
149
  var _ref3;
142
150
  var mergedConfig = (0, _assign.default)({}, defaultConfig, context.options[0]);
143
- var callSelector = mergedConfig.cssFunctions.map(function (fn) {
151
+ var callSelectorFunctions = [].concat((0, _toConsumableArray2.default)(mergedConfig.cssFunctions), ['cssMap']);
152
+ var callSelector = callSelectorFunctions.map(function (fn) {
144
153
  return "CallExpression[callee.name=".concat(fn, "]");
145
154
  }).join(',');
146
155
  return _ref3 = {}, (0, _defineProperty2.default)(_ref3, callSelector, function (node) {
@@ -21,6 +21,7 @@ var _noUnsafeDesignTokenUsage = _interopRequireDefault(require("./no-unsafe-desi
21
21
  var _noUnsafeStyleOverrides = _interopRequireDefault(require("./no-unsafe-style-overrides"));
22
22
  var _noUnsupportedDragAndDropLibraries = _interopRequireDefault(require("./no-unsupported-drag-and-drop-libraries"));
23
23
  var _preferPrimitives = _interopRequireDefault(require("./prefer-primitives"));
24
+ var _useButtonGroupLabel = _interopRequireDefault(require("./use-button-group-label"));
24
25
  var _useDrawerLabel = _interopRequireDefault(require("./use-drawer-label"));
25
26
  var _useHeadingLevelInSpotlightCard = _interopRequireDefault(require("./use-heading-level-in-spotlight-card"));
26
27
  var _useHrefInLinkItem = _interopRequireDefault(require("./use-href-in-link-item"));
@@ -28,7 +29,7 @@ var _usePrimitives = _interopRequireDefault(require("./use-primitives"));
28
29
  var _useVisuallyHidden = _interopRequireDefault(require("./use-visually-hidden"));
29
30
  /**
30
31
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
31
- * @codegen <<SignedSource::ab1f5b129d07027c228dbd79da5f3572>>
32
+ * @codegen <<SignedSource::14cdfdcbd8b999ee097a1a5b245d7117>>
32
33
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
33
34
  */
34
35
  var _default = exports.default = {
@@ -48,6 +49,7 @@ var _default = exports.default = {
48
49
  'no-unsafe-style-overrides': _noUnsafeStyleOverrides.default,
49
50
  'no-unsupported-drag-and-drop-libraries': _noUnsupportedDragAndDropLibraries.default,
50
51
  'prefer-primitives': _preferPrimitives.default,
52
+ 'use-button-group-label': _useButtonGroupLabel.default,
51
53
  'use-drawer-label': _useDrawerLabel.default,
52
54
  'use-heading-level-in-spotlight-card': _useHeadingLevelInSpotlightCard.default,
53
55
  'use-href-in-link-item': _useHrefInLinkItem.default,
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
8
+ var _createRule = require("../utils/create-rule");
9
+ // eslint-disable-next-line import/no-extraneous-dependencies
10
+
11
+ var elementsAccessibleNameProps = ['label', 'titleId'];
12
+ var rule = (0, _createRule.createLintRule)({
13
+ meta: {
14
+ name: 'use-button-group-label',
15
+ type: 'suggestion',
16
+ docs: {
17
+ description: 'Ensures button groups are described to assistive technology by a direct label or by another element.',
18
+ recommended: true,
19
+ severity: 'warn'
20
+ },
21
+ messages: {
22
+ missingLabelProp: 'Missing accessible name. If there is no visible content to associate use `label` prop, otherwise pass id of element to `titleId` prop to be associated as label.',
23
+ labelPropShouldHaveContents: 'Define string that labels the interactive element.',
24
+ titleIdShouldHaveValue: '`titleId` should reference the id of element that define accessible name.',
25
+ noBothPropsUsage: 'Do not include both `titleId` and `label` properties. Use `titleId` if the label text is available in the DOM to reference it, otherwise use `label` to provide accessible name explicitly.'
26
+ },
27
+ hasSuggestions: true
28
+ },
29
+ create: function create(context) {
30
+ var contextLocalIdentifier = [];
31
+ return {
32
+ ImportDeclaration: function ImportDeclaration(node) {
33
+ if (node.source.value === '@atlaskit/button') {
34
+ if (node.specifiers.length) {
35
+ var defaultImport = node.specifiers.filter(function (spec) {
36
+ return spec.type === 'ImportSpecifier';
37
+ });
38
+ if (defaultImport && defaultImport.length) {
39
+ var local = defaultImport[0].local;
40
+ contextLocalIdentifier.push(local.name);
41
+ }
42
+ }
43
+ }
44
+ },
45
+ JSXElement: function JSXElement(node) {
46
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXElement')) {
47
+ return;
48
+ }
49
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node.openingElement.name, 'JSXIdentifier')) {
50
+ return;
51
+ }
52
+ var name = node.openingElement.name.name;
53
+ if (contextLocalIdentifier.includes(name)) {
54
+ var componentLabelProps = node.openingElement.attributes.filter(function (attr) {
55
+ return (0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXAttribute') && (0, _eslintCodemodUtils.isNodeOfType)(attr.name, 'JSXIdentifier') && elementsAccessibleNameProps.includes(attr.name.name);
56
+ });
57
+ if (componentLabelProps.length === 1) {
58
+ var prop = componentLabelProps[0];
59
+ if ('value' in prop && prop.value) {
60
+ if ((0, _eslintCodemodUtils.isNodeOfType)(prop.value, 'Literal') && !prop.value.value || (0, _eslintCodemodUtils.isNodeOfType)(prop.value, 'JSXExpressionContainer') && !prop.value.expression) {
61
+ context.report({
62
+ node: prop,
63
+ messageId: prop.name.name === 'label' ? 'labelPropShouldHaveContents' : 'titleIdShouldHaveValue'
64
+ });
65
+ }
66
+ }
67
+ } else if (componentLabelProps.length > 1) {
68
+ context.report({
69
+ node: node.openingElement,
70
+ messageId: 'noBothPropsUsage'
71
+ });
72
+ } else {
73
+ context.report({
74
+ node: node.openingElement,
75
+ messageId: 'missingLabelProp'
76
+ });
77
+ }
78
+ }
79
+ }
80
+ };
81
+ }
82
+ });
83
+ var _default = exports.default = rule;
@@ -3,34 +3,24 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.convertASTObjectExpressionToJSObject = void 0;
6
+ exports.convertASTObjectExpressionToJSObject = exports.SPREAD_SYNTAX = void 0;
7
7
  var _eslintCodemodUtils = require("eslint-codemod-utils");
8
- // FIXME: This is only loosely typed
9
-
8
+ var SPREAD_SYNTAX = exports.SPREAD_SYNTAX = Symbol('SPREAD_SYNTAX');
10
9
  /**
11
10
  * Note: Not recursive. Only handles top level key/value pairs
12
11
  */
13
12
  var convertASTObjectExpressionToJSObject = exports.convertASTObjectExpressionToJSObject = function convertASTObjectExpressionToJSObject(styles) {
14
- var styleObj = {};
13
+ var styleObj = {
14
+ unsupported: []
15
+ };
15
16
 
16
- // if we see any spread props we stop and return false to indicate this is unsupported
17
+ // if we see any spread props we indicate that as unsupported
17
18
  if (!styles.properties.every(function (prop) {
18
19
  return (0, _eslintCodemodUtils.isNodeOfType)(prop, 'Property');
19
20
  })) {
20
- return false;
21
+ styleObj.unsupported.push(SPREAD_SYNTAX);
21
22
  }
22
-
23
- // TODO: https://product-fabric.atlassian.net/browse/DSP-16055
24
- // We need to harden this logic asap.
25
- // It currently generates a false positive for:
26
- // styled.div({
27
- // marginTop: "0px",
28
- // marginBottom: blah(...),
29
- // })
30
- // as the value for `marginBottom` is not a string nor a `token` call, it is just skipped
31
- // from the resulting map and this is inaccurate.
32
23
  styles.properties.forEach(function (prop) {
33
- // cases we want to skip (see note above)
34
24
  if (!(0, _eslintCodemodUtils.isNodeOfType)(prop, 'Property')) {
35
25
  return;
36
26
  }
@@ -41,28 +31,30 @@ var convertASTObjectExpressionToJSObject = exports.convertASTObjectExpressionToJ
41
31
  // a literal string value, the base case
42
32
  if ((0, _eslintCodemodUtils.isNodeOfType)(prop.value, 'Literal') && typeof prop.value.value === 'string') {
43
33
  styleObj[prop.key.name] = prop.value.value;
34
+ return;
44
35
  }
45
36
 
46
37
  // try to handle a direct call to `token`
47
38
  if ((0, _eslintCodemodUtils.isNodeOfType)(prop.value, 'CallExpression')) {
48
- var _callExpression$argum;
49
39
  var callExpression = prop.value;
50
- // skip if not a call to `token`
51
- if (!(0, _eslintCodemodUtils.isNodeOfType)(callExpression.callee, 'Identifier') || callExpression.callee.name !== 'token') {
52
- return;
40
+ // strictly handle calls to `token`
41
+ if ((0, _eslintCodemodUtils.isNodeOfType)(callExpression.callee, 'Identifier') && callExpression.callee.name === 'token') {
42
+ // only two valid cases are supported
43
+ // one argument => token('space.100')
44
+ // two arguments => token('space.100', '8px')
45
+ if ((callExpression.arguments.length === 1 || callExpression.arguments.length === 2) && (0, _eslintCodemodUtils.isNodeOfType)(callExpression.arguments[0], 'Literal') && (typeof callExpression.arguments[1] === 'undefined' || (0, _eslintCodemodUtils.isNodeOfType)(callExpression.arguments[1], 'Literal'))) {
46
+ var _callExpression$argum;
47
+ styleObj[prop.key.name] = {
48
+ tokenName: String(callExpression.arguments[0].value),
49
+ fallbackValue: (_callExpression$argum = callExpression.arguments[1]) !== null && _callExpression$argum !== void 0 && _callExpression$argum.value ? String(callExpression.arguments[1].value) : undefined
50
+ };
51
+ return;
52
+ }
53
53
  }
54
-
55
- // only two valid cases are supported
56
- // one argument => token('space.100')
57
- // two arguments => token('space.100', '8px')
58
- if (callExpression.arguments.length !== 1 && callExpression.arguments.length !== 2 || !(0, _eslintCodemodUtils.isNodeOfType)(callExpression.arguments[0], 'Literal') || callExpression.arguments[1] && !(0, _eslintCodemodUtils.isNodeOfType)(callExpression.arguments[1], 'Literal')) {
59
- return;
60
- }
61
- styleObj[prop.key.name] = {
62
- tokenName: String(callExpression.arguments[0].value),
63
- fallbackValue: (_callExpression$argum = callExpression.arguments[1]) !== null && _callExpression$argum !== void 0 && _callExpression$argum.value ? String(callExpression.arguments[1].value) : undefined
64
- };
65
54
  }
55
+
56
+ // if we get here we have an unsupported value
57
+ styleObj.unsupported.push(prop.key.name);
66
58
  });
67
59
  return styleObj;
68
60
  };
@@ -6,18 +6,22 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.isValidCssPropertiesToTransform = void 0;
8
8
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
10
  var _eslintCodemodUtils = require("eslint-codemod-utils");
10
11
  var _cssToXcss = require("../transformers/css-to-xcss");
11
12
  var _convertAstObjectExpressionToJsObject = require("./convert-ast-object-expression-to-js-object");
13
+ var _excluded = ["unsupported"];
12
14
  var isValidCssPropertiesToTransform = exports.isValidCssPropertiesToTransform = function isValidCssPropertiesToTransform(node, config) {
13
15
  var cssObjectExpression = node.arguments[0];
14
16
  // Bail on empty object calls
15
17
  if (!cssObjectExpression || !(0, _eslintCodemodUtils.isNodeOfType)(cssObjectExpression, 'ObjectExpression')) {
16
18
  return false;
17
19
  }
18
- var cssObject = (0, _convertAstObjectExpressionToJsObject.convertASTObjectExpressionToJSObject)(cssObjectExpression);
19
- // Bail if there are less or more than 1 styles defined
20
- if (!cssObject || Object.keys(cssObject).length !== 1) {
20
+ var _convertASTObjectExpr = (0, _convertAstObjectExpressionToJsObject.convertASTObjectExpressionToJSObject)(cssObjectExpression),
21
+ unsupported = _convertASTObjectExpr.unsupported,
22
+ cssObject = (0, _objectWithoutProperties2.default)(_convertASTObjectExpr, _excluded);
23
+ // Bail if there are any unsupported styles
24
+ if (unsupported.length > 0 || Object.keys(cssObject).length !== 1) {
21
25
  return false;
22
26
  }
23
27
  // Short-circuit when token calls are found but pattern is not enabled in config
@@ -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::6efa1e48692b3e287d6dfcd500a5f0ab>>
3
+ * @codegen <<SignedSource::d1a459e1ea71650f65b2890dc86cc398>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  export default {
@@ -22,6 +22,7 @@ export default {
22
22
  '@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
23
23
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
24
24
  '@atlaskit/design-system/prefer-primitives': 'warn',
25
+ '@atlaskit/design-system/use-button-group-label': 'warn',
25
26
  '@atlaskit/design-system/use-drawer-label': 'warn',
26
27
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
27
28
  '@atlaskit/design-system/use-href-in-link-item': '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::be810d87ec2d253e3b053dc06ff1b99a>>
3
+ * @codegen <<SignedSource::3b93cfbbe0ea14514b9600509632394b>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  export default {
@@ -17,6 +17,7 @@ export default {
17
17
  '@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
18
18
  '@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
19
19
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
20
+ '@atlaskit/design-system/use-button-group-label': 'warn',
20
21
  '@atlaskit/design-system/use-drawer-label': 'warn',
21
22
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
22
23
  '@atlaskit/design-system/use-href-in-link-item': 'warn',
@@ -14,9 +14,9 @@ function findSpreadProperties(node) {
14
14
  property.type === 'ExperimentalSpreadProperty');
15
15
  }
16
16
  function analyzeIdentifier(context, sourceIdentifier, configuration) {
17
- var _getIdentifierInParen;
17
+ var _getIdentifierInParen, _getIdentifierInParen2;
18
18
  const scope = context.getScope();
19
- const [identifier] = ((_getIdentifierInParen = getIdentifierInParentScope(scope, sourceIdentifier.name)) === null || _getIdentifierInParen === void 0 ? void 0 : _getIdentifierInParen.identifiers) || [];
19
+ const [identifier] = (_getIdentifierInParen = (_getIdentifierInParen2 = getIdentifierInParentScope(scope, sourceIdentifier.name)) === null || _getIdentifierInParen2 === void 0 ? void 0 : _getIdentifierInParen2.identifiers) !== null && _getIdentifierInParen !== void 0 ? _getIdentifierInParen : [];
20
20
  if (!identifier || !identifier.parent) {
21
21
  // Identifier isn't in the module, skip!
22
22
  return;
@@ -37,7 +37,7 @@ function analyzeIdentifier(context, sourceIdentifier, configuration) {
37
37
  });
38
38
  return;
39
39
  }
40
- if (identifier.parent && identifier.parent.init && !isCssCallExpression(identifier.parent.init, configuration.cssFunctions)) {
40
+ if (identifier.parent && identifier.parent.init && !isCssCallExpression(identifier.parent.init, [...configuration.cssFunctions, 'cssMap'])) {
41
41
  // When variable value is not of type css({})
42
42
  context.report({
43
43
  node: identifier,
@@ -56,6 +56,13 @@ function analyzeIdentifier(context, sourceIdentifier, configuration) {
56
56
  });
57
57
  }
58
58
  }
59
+
60
+ /**
61
+ * Handle different cases based on what's been passed in the css-related JSXAttribute
62
+ * @param context the context of the node
63
+ * @param expression the expression of the JSXAttribute value
64
+ * @param configuration what css-related functions to account for (eg. css, xcss, cssMap), and whether to detect bottom vs top expressions
65
+ */
59
66
  const traverseExpressionWithConfig = (context, expression, configuration) => {
60
67
  function traverseExpression(expression) {
61
68
  switch (expression.type) {
@@ -124,7 +131,8 @@ const rule = createLintRule({
124
131
  },
125
132
  create(context) {
126
133
  const mergedConfig = assign({}, defaultConfig, context.options[0]);
127
- const callSelector = mergedConfig.cssFunctions.map(fn => `CallExpression[callee.name=${fn}]`).join(',');
134
+ const callSelectorFunctions = [...mergedConfig.cssFunctions, 'cssMap'];
135
+ const callSelector = callSelectorFunctions.map(fn => `CallExpression[callee.name=${fn}]`).join(',');
128
136
  return {
129
137
  [callSelector]: node => {
130
138
  if (node.parent.type !== 'VariableDeclarator') {
@@ -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::ab1f5b129d07027c228dbd79da5f3572>>
3
+ * @codegen <<SignedSource::14cdfdcbd8b999ee097a1a5b245d7117>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import consistentCssPropUsage from './consistent-css-prop-usage';
@@ -19,6 +19,7 @@ import noUnsafeDesignTokenUsage from './no-unsafe-design-token-usage';
19
19
  import noUnsafeStyleOverrides from './no-unsafe-style-overrides';
20
20
  import noUnsupportedDragAndDropLibraries from './no-unsupported-drag-and-drop-libraries';
21
21
  import preferPrimitives from './prefer-primitives';
22
+ import useButtonGroupLabel from './use-button-group-label';
22
23
  import useDrawerLabel from './use-drawer-label';
23
24
  import useHeadingLevelInSpotlightCard from './use-heading-level-in-spotlight-card';
24
25
  import useHrefInLinkItem from './use-href-in-link-item';
@@ -41,6 +42,7 @@ export default {
41
42
  'no-unsafe-style-overrides': noUnsafeStyleOverrides,
42
43
  'no-unsupported-drag-and-drop-libraries': noUnsupportedDragAndDropLibraries,
43
44
  'prefer-primitives': preferPrimitives,
45
+ 'use-button-group-label': useButtonGroupLabel,
44
46
  'use-drawer-label': useDrawerLabel,
45
47
  'use-heading-level-in-spotlight-card': useHeadingLevelInSpotlightCard,
46
48
  'use-href-in-link-item': useHrefInLinkItem,
@@ -0,0 +1,75 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
+
3
+ import { isNodeOfType } from 'eslint-codemod-utils';
4
+ import { createLintRule } from '../utils/create-rule';
5
+ const elementsAccessibleNameProps = ['label', 'titleId'];
6
+ const rule = createLintRule({
7
+ meta: {
8
+ name: 'use-button-group-label',
9
+ type: 'suggestion',
10
+ docs: {
11
+ description: 'Ensures button groups are described to assistive technology by a direct label or by another element.',
12
+ recommended: true,
13
+ severity: 'warn'
14
+ },
15
+ messages: {
16
+ missingLabelProp: 'Missing accessible name. If there is no visible content to associate use `label` prop, otherwise pass id of element to `titleId` prop to be associated as label.',
17
+ labelPropShouldHaveContents: 'Define string that labels the interactive element.',
18
+ titleIdShouldHaveValue: '`titleId` should reference the id of element that define accessible name.',
19
+ noBothPropsUsage: 'Do not include both `titleId` and `label` properties. Use `titleId` if the label text is available in the DOM to reference it, otherwise use `label` to provide accessible name explicitly.'
20
+ },
21
+ hasSuggestions: true
22
+ },
23
+ create(context) {
24
+ const contextLocalIdentifier = [];
25
+ return {
26
+ ImportDeclaration(node) {
27
+ if (node.source.value === '@atlaskit/button') {
28
+ if (node.specifiers.length) {
29
+ const defaultImport = node.specifiers.filter(spec => spec.type === 'ImportSpecifier');
30
+ if (defaultImport && defaultImport.length) {
31
+ const {
32
+ local
33
+ } = defaultImport[0];
34
+ contextLocalIdentifier.push(local.name);
35
+ }
36
+ }
37
+ }
38
+ },
39
+ JSXElement(node) {
40
+ if (!isNodeOfType(node, 'JSXElement')) {
41
+ return;
42
+ }
43
+ if (!isNodeOfType(node.openingElement.name, 'JSXIdentifier')) {
44
+ return;
45
+ }
46
+ const name = node.openingElement.name.name;
47
+ if (contextLocalIdentifier.includes(name)) {
48
+ const componentLabelProps = node.openingElement.attributes.filter(attr => isNodeOfType(attr, 'JSXAttribute') && isNodeOfType(attr.name, 'JSXIdentifier') && elementsAccessibleNameProps.includes(attr.name.name));
49
+ if (componentLabelProps.length === 1) {
50
+ const prop = componentLabelProps[0];
51
+ if ('value' in prop && prop.value) {
52
+ if (isNodeOfType(prop.value, 'Literal') && !prop.value.value || isNodeOfType(prop.value, 'JSXExpressionContainer') && !prop.value.expression) {
53
+ context.report({
54
+ node: prop,
55
+ messageId: prop.name.name === 'label' ? 'labelPropShouldHaveContents' : 'titleIdShouldHaveValue'
56
+ });
57
+ }
58
+ }
59
+ } else if (componentLabelProps.length > 1) {
60
+ context.report({
61
+ node: node.openingElement,
62
+ messageId: 'noBothPropsUsage'
63
+ });
64
+ } else {
65
+ context.report({
66
+ node: node.openingElement,
67
+ messageId: 'missingLabelProp'
68
+ });
69
+ }
70
+ }
71
+ }
72
+ };
73
+ }
74
+ });
75
+ export default rule;
@@ -1,29 +1,18 @@
1
1
  import { isNodeOfType } from 'eslint-codemod-utils';
2
-
3
- // FIXME: This is only loosely typed
4
-
2
+ export const SPREAD_SYNTAX = Symbol('SPREAD_SYNTAX');
5
3
  /**
6
4
  * Note: Not recursive. Only handles top level key/value pairs
7
5
  */
8
6
  export const convertASTObjectExpressionToJSObject = styles => {
9
- const styleObj = {};
7
+ const styleObj = {
8
+ unsupported: []
9
+ };
10
10
 
11
- // if we see any spread props we stop and return false to indicate this is unsupported
11
+ // if we see any spread props we indicate that as unsupported
12
12
  if (!styles.properties.every(prop => isNodeOfType(prop, 'Property'))) {
13
- return false;
13
+ styleObj.unsupported.push(SPREAD_SYNTAX);
14
14
  }
15
-
16
- // TODO: https://product-fabric.atlassian.net/browse/DSP-16055
17
- // We need to harden this logic asap.
18
- // It currently generates a false positive for:
19
- // styled.div({
20
- // marginTop: "0px",
21
- // marginBottom: blah(...),
22
- // })
23
- // as the value for `marginBottom` is not a string nor a `token` call, it is just skipped
24
- // from the resulting map and this is inaccurate.
25
15
  styles.properties.forEach(prop => {
26
- // cases we want to skip (see note above)
27
16
  if (!isNodeOfType(prop, 'Property')) {
28
17
  return;
29
18
  }
@@ -34,28 +23,30 @@ export const convertASTObjectExpressionToJSObject = styles => {
34
23
  // a literal string value, the base case
35
24
  if (isNodeOfType(prop.value, 'Literal') && typeof prop.value.value === 'string') {
36
25
  styleObj[prop.key.name] = prop.value.value;
26
+ return;
37
27
  }
38
28
 
39
29
  // try to handle a direct call to `token`
40
30
  if (isNodeOfType(prop.value, 'CallExpression')) {
41
- var _callExpression$argum;
42
31
  const callExpression = prop.value;
43
- // skip if not a call to `token`
44
- if (!isNodeOfType(callExpression.callee, 'Identifier') || callExpression.callee.name !== 'token') {
45
- return;
32
+ // strictly handle calls to `token`
33
+ if (isNodeOfType(callExpression.callee, 'Identifier') && callExpression.callee.name === 'token') {
34
+ // only two valid cases are supported
35
+ // one argument => token('space.100')
36
+ // two arguments => token('space.100', '8px')
37
+ if ((callExpression.arguments.length === 1 || callExpression.arguments.length === 2) && isNodeOfType(callExpression.arguments[0], 'Literal') && (typeof callExpression.arguments[1] === 'undefined' || isNodeOfType(callExpression.arguments[1], 'Literal'))) {
38
+ var _callExpression$argum;
39
+ styleObj[prop.key.name] = {
40
+ tokenName: String(callExpression.arguments[0].value),
41
+ fallbackValue: (_callExpression$argum = callExpression.arguments[1]) !== null && _callExpression$argum !== void 0 && _callExpression$argum.value ? String(callExpression.arguments[1].value) : undefined
42
+ };
43
+ return;
44
+ }
46
45
  }
47
-
48
- // only two valid cases are supported
49
- // one argument => token('space.100')
50
- // two arguments => token('space.100', '8px')
51
- if (callExpression.arguments.length !== 1 && callExpression.arguments.length !== 2 || !isNodeOfType(callExpression.arguments[0], 'Literal') || callExpression.arguments[1] && !isNodeOfType(callExpression.arguments[1], 'Literal')) {
52
- return;
53
- }
54
- styleObj[prop.key.name] = {
55
- tokenName: String(callExpression.arguments[0].value),
56
- fallbackValue: (_callExpression$argum = callExpression.arguments[1]) !== null && _callExpression$argum !== void 0 && _callExpression$argum.value ? String(callExpression.arguments[1].value) : undefined
57
- };
58
46
  }
47
+
48
+ // if we get here we have an unsupported value
49
+ styleObj.unsupported.push(prop.key.name);
59
50
  });
60
51
  return styleObj;
61
52
  };
@@ -7,9 +7,12 @@ export const isValidCssPropertiesToTransform = (node, config) => {
7
7
  if (!cssObjectExpression || !isNodeOfType(cssObjectExpression, 'ObjectExpression')) {
8
8
  return false;
9
9
  }
10
- const cssObject = convertASTObjectExpressionToJSObject(cssObjectExpression);
11
- // Bail if there are less or more than 1 styles defined
12
- if (!cssObject || Object.keys(cssObject).length !== 1) {
10
+ const {
11
+ unsupported,
12
+ ...cssObject
13
+ } = convertASTObjectExpressionToJSObject(cssObjectExpression);
14
+ // Bail if there are any unsupported styles
15
+ if (unsupported.length > 0 || Object.keys(cssObject).length !== 1) {
13
16
  return false;
14
17
  }
15
18
  // Short-circuit when token calls are found but pattern is not enabled in config
@@ -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::6efa1e48692b3e287d6dfcd500a5f0ab>>
3
+ * @codegen <<SignedSource::d1a459e1ea71650f65b2890dc86cc398>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  export default {
@@ -22,6 +22,7 @@ export default {
22
22
  '@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
23
23
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
24
24
  '@atlaskit/design-system/prefer-primitives': 'warn',
25
+ '@atlaskit/design-system/use-button-group-label': 'warn',
25
26
  '@atlaskit/design-system/use-drawer-label': 'warn',
26
27
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
27
28
  '@atlaskit/design-system/use-href-in-link-item': '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::be810d87ec2d253e3b053dc06ff1b99a>>
3
+ * @codegen <<SignedSource::3b93cfbbe0ea14514b9600509632394b>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  export default {
@@ -17,6 +17,7 @@ export default {
17
17
  '@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
18
18
  '@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
19
19
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
20
+ '@atlaskit/design-system/use-button-group-label': 'warn',
20
21
  '@atlaskit/design-system/use-drawer-label': 'warn',
21
22
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
22
23
  '@atlaskit/design-system/use-href-in-link-item': 'warn',
@@ -1,4 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
4
  // eslint-disable-next-line import/no-extraneous-dependencies
4
5
 
@@ -18,9 +19,9 @@ function findSpreadProperties(node) {
18
19
  });
19
20
  }
20
21
  function analyzeIdentifier(context, sourceIdentifier, configuration) {
21
- var _getIdentifierInParen;
22
+ var _getIdentifierInParen, _getIdentifierInParen2;
22
23
  var scope = context.getScope();
23
- var _ref = ((_getIdentifierInParen = getIdentifierInParentScope(scope, sourceIdentifier.name)) === null || _getIdentifierInParen === void 0 ? void 0 : _getIdentifierInParen.identifiers) || [],
24
+ var _ref = (_getIdentifierInParen = (_getIdentifierInParen2 = getIdentifierInParentScope(scope, sourceIdentifier.name)) === null || _getIdentifierInParen2 === void 0 ? void 0 : _getIdentifierInParen2.identifiers) !== null && _getIdentifierInParen !== void 0 ? _getIdentifierInParen : [],
24
25
  _ref2 = _slicedToArray(_ref, 1),
25
26
  identifier = _ref2[0];
26
27
  if (!identifier || !identifier.parent) {
@@ -43,7 +44,7 @@ function analyzeIdentifier(context, sourceIdentifier, configuration) {
43
44
  });
44
45
  return;
45
46
  }
46
- if (identifier.parent && identifier.parent.init && !isCssCallExpression(identifier.parent.init, configuration.cssFunctions)) {
47
+ if (identifier.parent && identifier.parent.init && !isCssCallExpression(identifier.parent.init, [].concat(_toConsumableArray(configuration.cssFunctions), ['cssMap']))) {
47
48
  // When variable value is not of type css({})
48
49
  context.report({
49
50
  node: identifier,
@@ -62,6 +63,13 @@ function analyzeIdentifier(context, sourceIdentifier, configuration) {
62
63
  });
63
64
  }
64
65
  }
66
+
67
+ /**
68
+ * Handle different cases based on what's been passed in the css-related JSXAttribute
69
+ * @param context the context of the node
70
+ * @param expression the expression of the JSXAttribute value
71
+ * @param configuration what css-related functions to account for (eg. css, xcss, cssMap), and whether to detect bottom vs top expressions
72
+ */
65
73
  var traverseExpressionWithConfig = function traverseExpressionWithConfig(context, expression, configuration) {
66
74
  function traverseExpression(expression) {
67
75
  switch (expression.type) {
@@ -133,7 +141,8 @@ var rule = createLintRule({
133
141
  create: function create(context) {
134
142
  var _ref3;
135
143
  var mergedConfig = assign({}, defaultConfig, context.options[0]);
136
- var callSelector = mergedConfig.cssFunctions.map(function (fn) {
144
+ var callSelectorFunctions = [].concat(_toConsumableArray(mergedConfig.cssFunctions), ['cssMap']);
145
+ var callSelector = callSelectorFunctions.map(function (fn) {
137
146
  return "CallExpression[callee.name=".concat(fn, "]");
138
147
  }).join(',');
139
148
  return _ref3 = {}, _defineProperty(_ref3, callSelector, function (node) {
@@ -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::ab1f5b129d07027c228dbd79da5f3572>>
3
+ * @codegen <<SignedSource::14cdfdcbd8b999ee097a1a5b245d7117>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import consistentCssPropUsage from './consistent-css-prop-usage';
@@ -19,6 +19,7 @@ import noUnsafeDesignTokenUsage from './no-unsafe-design-token-usage';
19
19
  import noUnsafeStyleOverrides from './no-unsafe-style-overrides';
20
20
  import noUnsupportedDragAndDropLibraries from './no-unsupported-drag-and-drop-libraries';
21
21
  import preferPrimitives from './prefer-primitives';
22
+ import useButtonGroupLabel from './use-button-group-label';
22
23
  import useDrawerLabel from './use-drawer-label';
23
24
  import useHeadingLevelInSpotlightCard from './use-heading-level-in-spotlight-card';
24
25
  import useHrefInLinkItem from './use-href-in-link-item';
@@ -41,6 +42,7 @@ export default {
41
42
  'no-unsafe-style-overrides': noUnsafeStyleOverrides,
42
43
  'no-unsupported-drag-and-drop-libraries': noUnsupportedDragAndDropLibraries,
43
44
  'prefer-primitives': preferPrimitives,
45
+ 'use-button-group-label': useButtonGroupLabel,
44
46
  'use-drawer-label': useDrawerLabel,
45
47
  'use-heading-level-in-spotlight-card': useHeadingLevelInSpotlightCard,
46
48
  'use-href-in-link-item': useHrefInLinkItem,
@@ -0,0 +1,77 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
+
3
+ import { isNodeOfType } from 'eslint-codemod-utils';
4
+ import { createLintRule } from '../utils/create-rule';
5
+ var elementsAccessibleNameProps = ['label', 'titleId'];
6
+ var rule = createLintRule({
7
+ meta: {
8
+ name: 'use-button-group-label',
9
+ type: 'suggestion',
10
+ docs: {
11
+ description: 'Ensures button groups are described to assistive technology by a direct label or by another element.',
12
+ recommended: true,
13
+ severity: 'warn'
14
+ },
15
+ messages: {
16
+ missingLabelProp: 'Missing accessible name. If there is no visible content to associate use `label` prop, otherwise pass id of element to `titleId` prop to be associated as label.',
17
+ labelPropShouldHaveContents: 'Define string that labels the interactive element.',
18
+ titleIdShouldHaveValue: '`titleId` should reference the id of element that define accessible name.',
19
+ noBothPropsUsage: 'Do not include both `titleId` and `label` properties. Use `titleId` if the label text is available in the DOM to reference it, otherwise use `label` to provide accessible name explicitly.'
20
+ },
21
+ hasSuggestions: true
22
+ },
23
+ create: function create(context) {
24
+ var contextLocalIdentifier = [];
25
+ return {
26
+ ImportDeclaration: function ImportDeclaration(node) {
27
+ if (node.source.value === '@atlaskit/button') {
28
+ if (node.specifiers.length) {
29
+ var defaultImport = node.specifiers.filter(function (spec) {
30
+ return spec.type === 'ImportSpecifier';
31
+ });
32
+ if (defaultImport && defaultImport.length) {
33
+ var local = defaultImport[0].local;
34
+ contextLocalIdentifier.push(local.name);
35
+ }
36
+ }
37
+ }
38
+ },
39
+ JSXElement: function JSXElement(node) {
40
+ if (!isNodeOfType(node, 'JSXElement')) {
41
+ return;
42
+ }
43
+ if (!isNodeOfType(node.openingElement.name, 'JSXIdentifier')) {
44
+ return;
45
+ }
46
+ var name = node.openingElement.name.name;
47
+ if (contextLocalIdentifier.includes(name)) {
48
+ var componentLabelProps = node.openingElement.attributes.filter(function (attr) {
49
+ return isNodeOfType(attr, 'JSXAttribute') && isNodeOfType(attr.name, 'JSXIdentifier') && elementsAccessibleNameProps.includes(attr.name.name);
50
+ });
51
+ if (componentLabelProps.length === 1) {
52
+ var prop = componentLabelProps[0];
53
+ if ('value' in prop && prop.value) {
54
+ if (isNodeOfType(prop.value, 'Literal') && !prop.value.value || isNodeOfType(prop.value, 'JSXExpressionContainer') && !prop.value.expression) {
55
+ context.report({
56
+ node: prop,
57
+ messageId: prop.name.name === 'label' ? 'labelPropShouldHaveContents' : 'titleIdShouldHaveValue'
58
+ });
59
+ }
60
+ }
61
+ } else if (componentLabelProps.length > 1) {
62
+ context.report({
63
+ node: node.openingElement,
64
+ messageId: 'noBothPropsUsage'
65
+ });
66
+ } else {
67
+ context.report({
68
+ node: node.openingElement,
69
+ messageId: 'missingLabelProp'
70
+ });
71
+ }
72
+ }
73
+ }
74
+ };
75
+ }
76
+ });
77
+ export default rule;
@@ -1,31 +1,20 @@
1
1
  import { isNodeOfType } from 'eslint-codemod-utils';
2
-
3
- // FIXME: This is only loosely typed
4
-
2
+ export var SPREAD_SYNTAX = Symbol('SPREAD_SYNTAX');
5
3
  /**
6
4
  * Note: Not recursive. Only handles top level key/value pairs
7
5
  */
8
6
  export var convertASTObjectExpressionToJSObject = function convertASTObjectExpressionToJSObject(styles) {
9
- var styleObj = {};
7
+ var styleObj = {
8
+ unsupported: []
9
+ };
10
10
 
11
- // if we see any spread props we stop and return false to indicate this is unsupported
11
+ // if we see any spread props we indicate that as unsupported
12
12
  if (!styles.properties.every(function (prop) {
13
13
  return isNodeOfType(prop, 'Property');
14
14
  })) {
15
- return false;
15
+ styleObj.unsupported.push(SPREAD_SYNTAX);
16
16
  }
17
-
18
- // TODO: https://product-fabric.atlassian.net/browse/DSP-16055
19
- // We need to harden this logic asap.
20
- // It currently generates a false positive for:
21
- // styled.div({
22
- // marginTop: "0px",
23
- // marginBottom: blah(...),
24
- // })
25
- // as the value for `marginBottom` is not a string nor a `token` call, it is just skipped
26
- // from the resulting map and this is inaccurate.
27
17
  styles.properties.forEach(function (prop) {
28
- // cases we want to skip (see note above)
29
18
  if (!isNodeOfType(prop, 'Property')) {
30
19
  return;
31
20
  }
@@ -36,28 +25,30 @@ export var convertASTObjectExpressionToJSObject = function convertASTObjectExpre
36
25
  // a literal string value, the base case
37
26
  if (isNodeOfType(prop.value, 'Literal') && typeof prop.value.value === 'string') {
38
27
  styleObj[prop.key.name] = prop.value.value;
28
+ return;
39
29
  }
40
30
 
41
31
  // try to handle a direct call to `token`
42
32
  if (isNodeOfType(prop.value, 'CallExpression')) {
43
- var _callExpression$argum;
44
33
  var callExpression = prop.value;
45
- // skip if not a call to `token`
46
- if (!isNodeOfType(callExpression.callee, 'Identifier') || callExpression.callee.name !== 'token') {
47
- return;
34
+ // strictly handle calls to `token`
35
+ if (isNodeOfType(callExpression.callee, 'Identifier') && callExpression.callee.name === 'token') {
36
+ // only two valid cases are supported
37
+ // one argument => token('space.100')
38
+ // two arguments => token('space.100', '8px')
39
+ if ((callExpression.arguments.length === 1 || callExpression.arguments.length === 2) && isNodeOfType(callExpression.arguments[0], 'Literal') && (typeof callExpression.arguments[1] === 'undefined' || isNodeOfType(callExpression.arguments[1], 'Literal'))) {
40
+ var _callExpression$argum;
41
+ styleObj[prop.key.name] = {
42
+ tokenName: String(callExpression.arguments[0].value),
43
+ fallbackValue: (_callExpression$argum = callExpression.arguments[1]) !== null && _callExpression$argum !== void 0 && _callExpression$argum.value ? String(callExpression.arguments[1].value) : undefined
44
+ };
45
+ return;
46
+ }
48
47
  }
49
-
50
- // only two valid cases are supported
51
- // one argument => token('space.100')
52
- // two arguments => token('space.100', '8px')
53
- if (callExpression.arguments.length !== 1 && callExpression.arguments.length !== 2 || !isNodeOfType(callExpression.arguments[0], 'Literal') || callExpression.arguments[1] && !isNodeOfType(callExpression.arguments[1], 'Literal')) {
54
- return;
55
- }
56
- styleObj[prop.key.name] = {
57
- tokenName: String(callExpression.arguments[0].value),
58
- fallbackValue: (_callExpression$argum = callExpression.arguments[1]) !== null && _callExpression$argum !== void 0 && _callExpression$argum.value ? String(callExpression.arguments[1].value) : undefined
59
- };
60
48
  }
49
+
50
+ // if we get here we have an unsupported value
51
+ styleObj.unsupported.push(prop.key.name);
61
52
  });
62
53
  return styleObj;
63
54
  };
@@ -1,4 +1,6 @@
1
1
  import _typeof from "@babel/runtime/helpers/typeof";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["unsupported"];
2
4
  import { isNodeOfType } from 'eslint-codemod-utils';
3
5
  import { supportedStylesMap } from '../transformers/css-to-xcss';
4
6
  import { convertASTObjectExpressionToJSObject } from './convert-ast-object-expression-to-js-object';
@@ -8,9 +10,11 @@ export var isValidCssPropertiesToTransform = function isValidCssPropertiesToTran
8
10
  if (!cssObjectExpression || !isNodeOfType(cssObjectExpression, 'ObjectExpression')) {
9
11
  return false;
10
12
  }
11
- var cssObject = convertASTObjectExpressionToJSObject(cssObjectExpression);
12
- // Bail if there are less or more than 1 styles defined
13
- if (!cssObject || Object.keys(cssObject).length !== 1) {
13
+ var _convertASTObjectExpr = convertASTObjectExpressionToJSObject(cssObjectExpression),
14
+ unsupported = _convertASTObjectExpr.unsupported,
15
+ cssObject = _objectWithoutProperties(_convertASTObjectExpr, _excluded);
16
+ // Bail if there are any unsupported styles
17
+ if (unsupported.length > 0 || Object.keys(cssObject).length !== 1) {
14
18
  return false;
15
19
  }
16
20
  // Short-circuit when token calls are found but pattern is not enabled in config
@@ -19,6 +19,7 @@ export declare const configs: {
19
19
  '@atlaskit/design-system/no-unsafe-style-overrides': string;
20
20
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
21
21
  '@atlaskit/design-system/prefer-primitives': string;
22
+ '@atlaskit/design-system/use-button-group-label': string;
22
23
  '@atlaskit/design-system/use-drawer-label': string;
23
24
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
24
25
  '@atlaskit/design-system/use-href-in-link-item': string;
@@ -40,6 +41,7 @@ export declare const configs: {
40
41
  '@atlaskit/design-system/no-unsafe-design-token-usage': string;
41
42
  '@atlaskit/design-system/no-unsafe-style-overrides': string;
42
43
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
44
+ '@atlaskit/design-system/use-button-group-label': string;
43
45
  '@atlaskit/design-system/use-drawer-label': string;
44
46
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
45
47
  '@atlaskit/design-system/use-href-in-link-item': 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::6efa1e48692b3e287d6dfcd500a5f0ab>>
3
+ * @codegen <<SignedSource::d1a459e1ea71650f65b2890dc86cc398>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -22,6 +22,7 @@ declare const _default: {
22
22
  '@atlaskit/design-system/no-unsafe-style-overrides': string;
23
23
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
24
24
  '@atlaskit/design-system/prefer-primitives': string;
25
+ '@atlaskit/design-system/use-button-group-label': string;
25
26
  '@atlaskit/design-system/use-drawer-label': string;
26
27
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
27
28
  '@atlaskit/design-system/use-href-in-link-item': 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::be810d87ec2d253e3b053dc06ff1b99a>>
3
+ * @codegen <<SignedSource::3b93cfbbe0ea14514b9600509632394b>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -17,6 +17,7 @@ declare const _default: {
17
17
  '@atlaskit/design-system/no-unsafe-design-token-usage': string;
18
18
  '@atlaskit/design-system/no-unsafe-style-overrides': string;
19
19
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
20
+ '@atlaskit/design-system/use-button-group-label': string;
20
21
  '@atlaskit/design-system/use-drawer-label': string;
21
22
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
22
23
  '@atlaskit/design-system/use-href-in-link-item': string;
@@ -19,6 +19,7 @@ declare const _default: {
19
19
  'no-unsafe-style-overrides': import("eslint").Rule.RuleModule;
20
20
  'no-unsupported-drag-and-drop-libraries': import("eslint").Rule.RuleModule;
21
21
  'prefer-primitives': import("eslint").Rule.RuleModule;
22
+ 'use-button-group-label': import("eslint").Rule.RuleModule;
22
23
  'use-drawer-label': import("eslint").Rule.RuleModule;
23
24
  'use-heading-level-in-spotlight-card': import("eslint").Rule.RuleModule;
24
25
  'use-href-in-link-item': import("eslint").Rule.RuleModule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -1,14 +1,18 @@
1
+ import type { CSSProperties } from 'react';
1
2
  import type { Rule } from 'eslint';
2
3
  import { ObjectExpression } from 'eslint-codemod-utils';
4
+ export declare const SPREAD_SYNTAX: unique symbol;
3
5
  type Token = {
4
6
  tokenName: string;
5
7
  fallbackValue: string | undefined;
6
8
  };
7
9
  export type CSSPropStyleObject = {
8
- [key: string]: string | number | Token;
10
+ [key in keyof CSSProperties]: string | number | Token;
11
+ } & {
12
+ unsupported: (keyof CSSProperties | typeof SPREAD_SYNTAX)[];
9
13
  };
10
14
  /**
11
15
  * Note: Not recursive. Only handles top level key/value pairs
12
16
  */
13
- export declare const convertASTObjectExpressionToJSObject: (styles: ObjectExpression & Partial<Rule.NodeParentExtension>) => CSSPropStyleObject | false;
17
+ export declare const convertASTObjectExpressionToJSObject: (styles: ObjectExpression & Partial<Rule.NodeParentExtension>) => CSSPropStyleObject;
14
18
  export {};
@@ -19,6 +19,7 @@ export declare const configs: {
19
19
  '@atlaskit/design-system/no-unsafe-style-overrides': string;
20
20
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
21
21
  '@atlaskit/design-system/prefer-primitives': string;
22
+ '@atlaskit/design-system/use-button-group-label': string;
22
23
  '@atlaskit/design-system/use-drawer-label': string;
23
24
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
24
25
  '@atlaskit/design-system/use-href-in-link-item': string;
@@ -40,6 +41,7 @@ export declare const configs: {
40
41
  '@atlaskit/design-system/no-unsafe-design-token-usage': string;
41
42
  '@atlaskit/design-system/no-unsafe-style-overrides': string;
42
43
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
44
+ '@atlaskit/design-system/use-button-group-label': string;
43
45
  '@atlaskit/design-system/use-drawer-label': string;
44
46
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
45
47
  '@atlaskit/design-system/use-href-in-link-item': 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::6efa1e48692b3e287d6dfcd500a5f0ab>>
3
+ * @codegen <<SignedSource::d1a459e1ea71650f65b2890dc86cc398>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -22,6 +22,7 @@ declare const _default: {
22
22
  '@atlaskit/design-system/no-unsafe-style-overrides': string;
23
23
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
24
24
  '@atlaskit/design-system/prefer-primitives': string;
25
+ '@atlaskit/design-system/use-button-group-label': string;
25
26
  '@atlaskit/design-system/use-drawer-label': string;
26
27
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
27
28
  '@atlaskit/design-system/use-href-in-link-item': 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::be810d87ec2d253e3b053dc06ff1b99a>>
3
+ * @codegen <<SignedSource::3b93cfbbe0ea14514b9600509632394b>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -17,6 +17,7 @@ declare const _default: {
17
17
  '@atlaskit/design-system/no-unsafe-design-token-usage': string;
18
18
  '@atlaskit/design-system/no-unsafe-style-overrides': string;
19
19
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
20
+ '@atlaskit/design-system/use-button-group-label': string;
20
21
  '@atlaskit/design-system/use-drawer-label': string;
21
22
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
22
23
  '@atlaskit/design-system/use-href-in-link-item': string;
@@ -23,6 +23,7 @@ declare const _default: {
23
23
  'no-unsafe-style-overrides': import("eslint").Rule.RuleModule;
24
24
  'no-unsupported-drag-and-drop-libraries': import("eslint").Rule.RuleModule;
25
25
  'prefer-primitives': import("eslint").Rule.RuleModule;
26
+ 'use-button-group-label': import("eslint").Rule.RuleModule;
26
27
  'use-drawer-label': import("eslint").Rule.RuleModule;
27
28
  'use-heading-level-in-spotlight-card': import("eslint").Rule.RuleModule;
28
29
  'use-href-in-link-item': import("eslint").Rule.RuleModule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -1,14 +1,18 @@
1
+ import type { CSSProperties } from 'react';
1
2
  import type { Rule } from 'eslint';
2
3
  import { ObjectExpression } from 'eslint-codemod-utils';
4
+ export declare const SPREAD_SYNTAX: unique symbol;
3
5
  type Token = {
4
6
  tokenName: string;
5
7
  fallbackValue: string | undefined;
6
8
  };
7
9
  export type CSSPropStyleObject = {
8
- [key: string]: string | number | Token;
10
+ [key in keyof CSSProperties]: string | number | Token;
11
+ } & {
12
+ unsupported: (keyof CSSProperties | typeof SPREAD_SYNTAX)[];
9
13
  };
10
14
  /**
11
15
  * Note: Not recursive. Only handles top level key/value pairs
12
16
  */
13
- export declare const convertASTObjectExpressionToJSObject: (styles: ObjectExpression & Partial<Rule.NodeParentExtension>) => CSSPropStyleObject | false;
17
+ export declare const convertASTObjectExpressionToJSObject: (styles: ObjectExpression & Partial<Rule.NodeParentExtension>) => CSSPropStyleObject;
14
18
  export {};
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.19.2",
4
+ "version": "8.21.0",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "publishConfig": {
7
7
  "registry": "https://registry.npmjs.org/"