@atlaskit/eslint-plugin-design-system 8.18.1 → 8.19.1

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 (44) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -0
  3. package/constellation/index/usage.mdx +51 -0
  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/index.codegen.js +3 -1
  7. package/dist/cjs/rules/no-unsafe-style-overrides/index.js +74 -0
  8. package/dist/cjs/rules/use-primitives/config/index.js +15 -0
  9. package/dist/cjs/rules/use-primitives/index.js +9 -9
  10. package/dist/cjs/rules/utils/get-import-node-by-source.js +49 -1
  11. package/dist/cjs/rules/utils/jsx.js +17 -0
  12. package/dist/es2019/presets/all.codegen.js +2 -1
  13. package/dist/es2019/presets/recommended.codegen.js +2 -1
  14. package/dist/es2019/rules/index.codegen.js +3 -1
  15. package/dist/es2019/rules/no-unsafe-style-overrides/index.js +68 -0
  16. package/dist/es2019/rules/use-primitives/config/index.js +9 -0
  17. package/dist/es2019/rules/use-primitives/index.js +9 -8
  18. package/dist/es2019/rules/utils/get-import-node-by-source.js +27 -0
  19. package/dist/es2019/rules/utils/jsx.js +16 -0
  20. package/dist/esm/presets/all.codegen.js +2 -1
  21. package/dist/esm/presets/recommended.codegen.js +2 -1
  22. package/dist/esm/rules/index.codegen.js +3 -1
  23. package/dist/esm/rules/no-unsafe-style-overrides/index.js +68 -0
  24. package/dist/esm/rules/use-primitives/config/index.js +9 -0
  25. package/dist/esm/rules/use-primitives/index.js +9 -8
  26. package/dist/esm/rules/utils/get-import-node-by-source.js +48 -0
  27. package/dist/esm/rules/utils/jsx.js +16 -0
  28. package/dist/types/index.codegen.d.ts +2 -0
  29. package/dist/types/presets/all.codegen.d.ts +2 -1
  30. package/dist/types/presets/recommended.codegen.d.ts +2 -1
  31. package/dist/types/rules/index.codegen.d.ts +1 -0
  32. package/dist/types/rules/no-unsafe-style-overrides/index.d.ts +2 -0
  33. package/dist/types/rules/use-primitives/config/index.d.ts +4 -0
  34. package/dist/types/rules/utils/get-import-node-by-source.d.ts +9 -0
  35. package/dist/types/rules/utils/jsx.d.ts +2 -1
  36. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  37. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  38. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
  39. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  40. package/dist/types-ts4.5/rules/no-unsafe-style-overrides/index.d.ts +2 -0
  41. package/dist/types-ts4.5/rules/use-primitives/config/index.d.ts +4 -0
  42. package/dist/types-ts4.5/rules/utils/get-import-node-by-source.d.ts +9 -0
  43. package/dist/types-ts4.5/rules/utils/jsx.d.ts +2 -1
  44. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 8.19.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#65221](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/65221) [`a2ba22904ca0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a2ba22904ca0) - Allow for @atlaskit/design-system/use-primitives lint rule to take a configuration object.
8
+
9
+ ## 8.19.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#64899](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/64899) [`442878c001f9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/442878c001f9) - Add `no-unsafe-style-overrides`. This rule marks any usage of unsafe style overrides as violations, such as usage of `css`, `theme`, and `cssFn` props.
14
+
3
15
  ## 8.18.1
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -62,6 +62,7 @@ module.exports = {
62
62
  | <a href="./src/rules/no-nested-styles/README.md">no-nested-styles</a> | Disallows use of nested styles in `css` functions. | Yes | | |
63
63
  | <a href="./src/rules/no-physical-properties/README.md">no-physical-properties</a> | Disallow physical properties and values in `css` function calls. | | Yes | |
64
64
  | <a href="./src/rules/no-unsafe-design-token-usage/README.md">no-unsafe-design-token-usage</a> | Enforces design token usage is statically and locally analyzable. | Yes | Yes | |
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 | | |
65
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 | | |
66
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. | | | |
67
68
  | <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 |
@@ -26,6 +26,7 @@ This plugin contains rules that should be used when working with the [Atlassian
26
26
  | <a href="#no-nested-styles">no-nested-styles</a> | Disallows use of nested styles in `css` functions. | Yes | | |
27
27
  | <a href="#no-physical-properties">no-physical-properties</a> | Disallow physical properties and values in `css` function calls. | | Yes | |
28
28
  | <a href="#no-unsafe-design-token-usage">no-unsafe-design-token-usage</a> | Enforces design token usage is statically and locally analyzable. | Yes | Yes | |
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 | | |
29
30
  | <a href="#no-unsupported-drag-and-drop-libraries">no-unsupported-drag-and-drop-libraries</a> | Disallow importing unsupported drag and drop modules. | Yes | | |
30
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. | | | |
31
32
  | <a href="#use-drawer-label">use-drawer-label</a> | Encourages to provide accessible name for Atlassian Design System Drawer component. | Yes | | Yes |
@@ -666,6 +667,56 @@ This rule comes with options to aid in migrating to design tokens.
666
667
  When `true` the rule will mark token function usage as violations when fallbacks aren't defined.
667
668
  When `false` the rule will mark token function usage as violations when fallbacks are defined.
668
669
 
670
+ ## no-unsafe-style-overrides
671
+
672
+ Unsafe style overrides cause friction and incidents when internals of the component you're overriding change. They're inherently unbounded and everything is API that can change at a moments notice.
673
+
674
+ Instead, lean on composition, primitive components, and safe style overrides via the `xcss` prop where component authors declare what styles they want to support.
675
+
676
+ <h3>Examples</h3>
677
+
678
+ #### Incorrect
679
+
680
+ ```tsx
681
+ import Button from '@atlaskit/button';
682
+
683
+ <Button css={{ fontWeight: 500 }}>foo</Button>;
684
+ ^^^
685
+ ```
686
+
687
+ ```tsx
688
+ import { LinkItem } from '@atlaskit/menu';
689
+
690
+ <LinkItem cssFn={() => ({ '> div > div': { padding: 2 } })} />;
691
+ ^^^^^
692
+ ```
693
+
694
+ ```tsx
695
+ import { ButtonItem } from '@atlaskit/side-navigation';
696
+
697
+ <ButtonItem className="text-neutral-400" />;
698
+ ^^^^^^^^^
699
+ ```
700
+
701
+ #### Correct
702
+
703
+ ```tsx
704
+ <Button>
705
+ <strong>foo</strong>
706
+ </Button>
707
+ ```
708
+
709
+ ```tsx
710
+ const styles = css({ padding: 'var(--ds-space-100)' });
711
+
712
+ <Box as="a" xcss={styles}>
713
+ <Stack>
714
+ <Inline />
715
+ <Inline />
716
+ </Stack>
717
+ </Box>;
718
+ ```
719
+
669
720
  ## no-unsupported-drag-and-drop-libraries
670
721
 
671
722
  We encourage the use of Pragmatic drag and drop to power all drag and drop experiences - from table to external files. Pragmatic drag and drop is a performance optimised drag and drop framework that has been designed to power any drag and drop experience on any tech stack. Please avoid using alternative drag and drop libraries as it will lead to poorer performance, increased maintenance costs, (likely) worse accessibility and fragmented user experiences. See https://staging.atlassian.design/components/pragmatic-drag-and-drop/
@@ -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::37a857efd0971ab26170d5f1f526279b>>
9
+ * @codegen <<SignedSource::6efa1e48692b3e287d6dfcd500a5f0ab>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -25,6 +25,7 @@ var _default = exports.default = {
25
25
  '@atlaskit/design-system/no-nested-styles': 'error',
26
26
  '@atlaskit/design-system/no-physical-properties': 'error',
27
27
  '@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
28
+ '@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
28
29
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
29
30
  '@atlaskit/design-system/prefer-primitives': 'warn',
30
31
  '@atlaskit/design-system/use-drawer-label': '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::b3bce8efb2db1fed84370af608ca0d4c>>
9
+ * @codegen <<SignedSource::be810d87ec2d253e3b053dc06ff1b99a>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -21,6 +21,7 @@ var _default = exports.default = {
21
21
  '@atlaskit/design-system/no-deprecated-imports': 'error',
22
22
  '@atlaskit/design-system/no-nested-styles': 'error',
23
23
  '@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
24
+ '@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
24
25
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
25
26
  '@atlaskit/design-system/use-drawer-label': 'warn',
26
27
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
@@ -18,6 +18,7 @@ var _noMargin = _interopRequireDefault(require("./no-margin"));
18
18
  var _noNestedStyles = _interopRequireDefault(require("./no-nested-styles"));
19
19
  var _noPhysicalProperties = _interopRequireDefault(require("./no-physical-properties"));
20
20
  var _noUnsafeDesignTokenUsage = _interopRequireDefault(require("./no-unsafe-design-token-usage"));
21
+ var _noUnsafeStyleOverrides = _interopRequireDefault(require("./no-unsafe-style-overrides"));
21
22
  var _noUnsupportedDragAndDropLibraries = _interopRequireDefault(require("./no-unsupported-drag-and-drop-libraries"));
22
23
  var _preferPrimitives = _interopRequireDefault(require("./prefer-primitives"));
23
24
  var _useDrawerLabel = _interopRequireDefault(require("./use-drawer-label"));
@@ -27,7 +28,7 @@ var _usePrimitives = _interopRequireDefault(require("./use-primitives"));
27
28
  var _useVisuallyHidden = _interopRequireDefault(require("./use-visually-hidden"));
28
29
  /**
29
30
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
30
- * @codegen <<SignedSource::e2cc357c90120dbbd89b2928dba968c0>>
31
+ * @codegen <<SignedSource::ab1f5b129d07027c228dbd79da5f3572>>
31
32
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
32
33
  */
33
34
  var _default = exports.default = {
@@ -44,6 +45,7 @@ var _default = exports.default = {
44
45
  'no-nested-styles': _noNestedStyles.default,
45
46
  'no-physical-properties': _noPhysicalProperties.default,
46
47
  'no-unsafe-design-token-usage': _noUnsafeDesignTokenUsage.default,
48
+ 'no-unsafe-style-overrides': _noUnsafeStyleOverrides.default,
47
49
  'no-unsupported-drag-and-drop-libraries': _noUnsupportedDragAndDropLibraries.default,
48
50
  'prefer-primitives': _preferPrimitives.default,
49
51
  'use-drawer-label': _useDrawerLabel.default,
@@ -0,0 +1,74 @@
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
+ var _getImportNodeBySource = require("../utils/get-import-node-by-source");
10
+ var _jsx = require("../utils/jsx");
11
+ var unsafeOverrides = ['css', 'className', 'theme', 'cssFn', 'styles'];
12
+ var rule = (0, _createRule.createLintRule)({
13
+ meta: {
14
+ docs: {
15
+ recommended: true,
16
+ // This should be an error but for now we're rolling it out as warn so we can actually get it into codebases.
17
+ severity: 'warn',
18
+ description: 'Discourage usage of unsafe style overrides used against the Atlassian Design System.'
19
+ },
20
+ name: 'no-unsafe-style-overrides',
21
+ messages: {
22
+ noUnsafeStyledOverride: 'Wrapping {{componentName}} in a styled component encourages unsafe style overrides which cause friction and incidents when its internals change.',
23
+ noUnsafeOverrides: 'The {{propName}} prop encourages unsafe style overrides which cause friction and incidents when {{componentName}} internals change.'
24
+ }
25
+ },
26
+ create: function create(context) {
27
+ return {
28
+ CallExpression: function CallExpression(node) {
29
+ if (node.callee.type !== 'Identifier' || !node.callee.name.toLowerCase().includes('styled')) {
30
+ // Ignore functions that don't look like styled().
31
+ return;
32
+ }
33
+ var firstArgument = node.arguments[0];
34
+ if (!firstArgument || firstArgument.type !== 'Identifier') {
35
+ return;
36
+ }
37
+ var moduleName = (0, _getImportNodeBySource.getModuleOfIdentifier)(context.getSourceCode(), firstArgument.name);
38
+ if (!moduleName || !moduleName.moduleName.startsWith('@atlaskit')) {
39
+ // Ignore styled calls with non-atlaskit components.
40
+ return;
41
+ }
42
+ context.report({
43
+ node: firstArgument,
44
+ messageId: 'noUnsafeStyledOverride',
45
+ data: {
46
+ componentName: moduleName.importName
47
+ }
48
+ });
49
+ },
50
+ JSXAttribute: function JSXAttribute(node) {
51
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXAttribute') || !(node.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'JSXOpeningElement'))) {
52
+ return;
53
+ }
54
+ var elementName = (0, _jsx.getJSXElementName)(node.parent);
55
+ var moduleName = (0, _getImportNodeBySource.getModuleOfIdentifier)(context.getSourceCode(), elementName);
56
+ if (!moduleName || !moduleName.moduleName.startsWith('@atlaskit')) {
57
+ return;
58
+ }
59
+ var propName = typeof node.name.name === 'string' ? node.name.name : node.name.name.name;
60
+ if (unsafeOverrides.includes(propName)) {
61
+ context.report({
62
+ node: node,
63
+ messageId: 'noUnsafeOverrides',
64
+ data: {
65
+ propName: propName,
66
+ componentName: moduleName.importName
67
+ }
68
+ });
69
+ }
70
+ }
71
+ };
72
+ }
73
+ });
74
+ var _default = exports.default = rule;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getConfig = void 0;
7
+ var defaults = {
8
+ patterns: ['div-object-css']
9
+ };
10
+ var getConfig = exports.getConfig = function getConfig(overrides) {
11
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
12
+ // start with an empty object, then merge in the defaults, then merge in overrides.
13
+ // The empty object is returned, as well as modified in place
14
+ return Object.assign({}, defaults, overrides);
15
+ };
@@ -1,19 +1,15 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.default = void 0;
8
7
  var _eslintCodemodUtils = require("eslint-codemod-utils");
9
- var _assign = _interopRequireDefault(require("lodash/assign"));
10
8
  var _createRule = require("../utils/create-rule");
9
+ var _config = require("./config");
11
10
  var _transformers = require("./transformers");
12
11
  var _utils = require("./utils");
13
12
  var boxDocsUrl = 'https://atlassian.design/components/primitives/box';
14
- var defaultConfig = {
15
- preview: false
16
- };
17
13
  var rule = (0, _createRule.createLintRule)({
18
14
  meta: {
19
15
  name: 'use-primitives',
@@ -30,11 +26,11 @@ var rule = (0, _createRule.createLintRule)({
30
26
  }
31
27
  },
32
28
  create: function create(context) {
33
- var mergedConfig = (0, _assign.default)({}, defaultConfig, context.options[0]);
29
+ var config = (0, _config.getConfig)(context.options[0]);
34
30
  return {
35
31
  // transforms styled.<html>(...) usages
36
32
  CallExpression: function CallExpression(node) {
37
- if (!mergedConfig.preview) {
33
+ if (!config.patterns.includes('compiled-styled-object')) {
38
34
  return;
39
35
  }
40
36
  if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression')) {
@@ -64,6 +60,7 @@ var rule = (0, _createRule.createLintRule)({
64
60
  },
65
61
  // transforms <div css={...}> usages
66
62
  JSXOpeningElement: function JSXOpeningElement(node) {
63
+ var config = (0, _config.getConfig)(context.options[0]);
67
64
  if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXOpeningElement')) {
68
65
  return;
69
66
  }
@@ -73,7 +70,7 @@ var rule = (0, _createRule.createLintRule)({
73
70
  if (!(0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'JSXElement')) {
74
71
  return;
75
72
  }
76
- var suggestBox = shouldSuggestBox(node.parent, context);
73
+ var suggestBox = shouldSuggestBox(node.parent, context, config);
77
74
  if (suggestBox) {
78
75
  context.report({
79
76
  node: node,
@@ -91,7 +88,7 @@ var rule = (0, _createRule.createLintRule)({
91
88
  };
92
89
  }
93
90
  });
94
- var shouldSuggestBox = function shouldSuggestBox(node, context
91
+ var shouldSuggestBox = function shouldSuggestBox(node, context, config
95
92
  // scope: Scope.Scope,
96
93
  ) {
97
94
  if (!node) {
@@ -138,6 +135,9 @@ var shouldSuggestBox = function shouldSuggestBox(node, context
138
135
  if (!cssVariableValue || !(0, _utils.isFunctionNamed)(cssVariableValue, 'css')) {
139
136
  return false;
140
137
  }
138
+ if (!config.patterns.includes('div-object-css')) {
139
+ return false;
140
+ }
141
141
  return (0, _utils.isValidCssPropertiesToTransform)(cssVariableValue.node.init);
142
142
  };
143
143
  var _default = exports.default = rule;
@@ -3,7 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getImportedNodeBySource = void 0;
6
+ exports.getModuleOfIdentifier = exports.getImportedNodeBySource = void 0;
7
+ 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; } } }; }
8
+ 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); }
9
+ 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; }
7
10
  // eslint-disable-next-line import/no-extraneous-dependencies
8
11
 
9
12
  /**
@@ -17,4 +20,49 @@ var getImportedNodeBySource = exports.getImportedNodeBySource = function getImpo
17
20
  }).find(function (node) {
18
21
  return node.source.value === path;
19
22
  });
23
+ };
24
+
25
+ /**
26
+ * Returns the module name of an identifier, if one exists.
27
+ *
28
+ * getModuleOfIdentifier(source, 'Button'); // "@atlaskit/button"
29
+ */
30
+ var getModuleOfIdentifier = exports.getModuleOfIdentifier = function getModuleOfIdentifier(source, identifierName) {
31
+ var _iterator = _createForOfIteratorHelper(source.ast.body),
32
+ _step;
33
+ try {
34
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
35
+ var node = _step.value;
36
+ if (node.type === 'ImportDeclaration') {
37
+ var _iterator2 = _createForOfIteratorHelper(node.specifiers),
38
+ _step2;
39
+ try {
40
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
41
+ var spec = _step2.value;
42
+ if (spec.type === 'ImportDefaultSpecifier' && spec.local.name === identifierName) {
43
+ return {
44
+ moduleName: node.source.value + '',
45
+ importName: identifierName
46
+ };
47
+ }
48
+ if (spec.type === 'ImportSpecifier' && spec.local.name === identifierName) {
49
+ return {
50
+ moduleName: node.source.value + '',
51
+ importName: spec.imported.name
52
+ };
53
+ }
54
+ }
55
+ } catch (err) {
56
+ _iterator2.e(err);
57
+ } finally {
58
+ _iterator2.f();
59
+ }
60
+ }
61
+ }
62
+ } catch (err) {
63
+ _iterator.e(err);
64
+ } finally {
65
+ _iterator.f();
66
+ }
67
+ return undefined;
20
68
  };
@@ -4,9 +4,26 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.findProp = findProp;
7
+ exports.getJSXElementName = getJSXElementName;
7
8
  function findProp(jsx, propName) {
8
9
  var labelProp = jsx.openingElement.attributes.find(function (attr) {
9
10
  return attr.type === 'JSXAttribute' && attr.name.name === propName;
10
11
  });
11
12
  return labelProp;
13
+ }
14
+ function unrollMemberExpression(exp) {
15
+ if (exp.type === 'JSXIdentifier') {
16
+ return exp.name;
17
+ }
18
+ return unrollMemberExpression(exp.object);
19
+ }
20
+ function getJSXElementName(jsx) {
21
+ switch (jsx.name.type) {
22
+ case 'JSXIdentifier':
23
+ return jsx.name.name;
24
+ case 'JSXMemberExpression':
25
+ return unrollMemberExpression(jsx.name.object);
26
+ case 'JSXNamespacedName':
27
+ return jsx.name.namespace.name;
28
+ }
12
29
  }
@@ -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::37a857efd0971ab26170d5f1f526279b>>
3
+ * @codegen <<SignedSource::6efa1e48692b3e287d6dfcd500a5f0ab>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  export default {
@@ -19,6 +19,7 @@ export default {
19
19
  '@atlaskit/design-system/no-nested-styles': 'error',
20
20
  '@atlaskit/design-system/no-physical-properties': 'error',
21
21
  '@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
22
+ '@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
22
23
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
23
24
  '@atlaskit/design-system/prefer-primitives': 'warn',
24
25
  '@atlaskit/design-system/use-drawer-label': '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::b3bce8efb2db1fed84370af608ca0d4c>>
3
+ * @codegen <<SignedSource::be810d87ec2d253e3b053dc06ff1b99a>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  export default {
@@ -15,6 +15,7 @@ export default {
15
15
  '@atlaskit/design-system/no-deprecated-imports': 'error',
16
16
  '@atlaskit/design-system/no-nested-styles': 'error',
17
17
  '@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
18
+ '@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
18
19
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
19
20
  '@atlaskit/design-system/use-drawer-label': 'warn',
20
21
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': '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::e2cc357c90120dbbd89b2928dba968c0>>
3
+ * @codegen <<SignedSource::ab1f5b129d07027c228dbd79da5f3572>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import consistentCssPropUsage from './consistent-css-prop-usage';
@@ -16,6 +16,7 @@ import noMargin from './no-margin';
16
16
  import noNestedStyles from './no-nested-styles';
17
17
  import noPhysicalProperties from './no-physical-properties';
18
18
  import noUnsafeDesignTokenUsage from './no-unsafe-design-token-usage';
19
+ import noUnsafeStyleOverrides from './no-unsafe-style-overrides';
19
20
  import noUnsupportedDragAndDropLibraries from './no-unsupported-drag-and-drop-libraries';
20
21
  import preferPrimitives from './prefer-primitives';
21
22
  import useDrawerLabel from './use-drawer-label';
@@ -37,6 +38,7 @@ export default {
37
38
  'no-nested-styles': noNestedStyles,
38
39
  'no-physical-properties': noPhysicalProperties,
39
40
  'no-unsafe-design-token-usage': noUnsafeDesignTokenUsage,
41
+ 'no-unsafe-style-overrides': noUnsafeStyleOverrides,
40
42
  'no-unsupported-drag-and-drop-libraries': noUnsupportedDragAndDropLibraries,
41
43
  'prefer-primitives': preferPrimitives,
42
44
  'use-drawer-label': useDrawerLabel,
@@ -0,0 +1,68 @@
1
+ import { isNodeOfType } from 'eslint-codemod-utils';
2
+ import { createLintRule } from '../utils/create-rule';
3
+ import { getModuleOfIdentifier } from '../utils/get-import-node-by-source';
4
+ import { getJSXElementName } from '../utils/jsx';
5
+ const unsafeOverrides = ['css', 'className', 'theme', 'cssFn', 'styles'];
6
+ const rule = createLintRule({
7
+ meta: {
8
+ docs: {
9
+ recommended: true,
10
+ // This should be an error but for now we're rolling it out as warn so we can actually get it into codebases.
11
+ severity: 'warn',
12
+ description: 'Discourage usage of unsafe style overrides used against the Atlassian Design System.'
13
+ },
14
+ name: 'no-unsafe-style-overrides',
15
+ messages: {
16
+ noUnsafeStyledOverride: 'Wrapping {{componentName}} in a styled component encourages unsafe style overrides which cause friction and incidents when its internals change.',
17
+ noUnsafeOverrides: 'The {{propName}} prop encourages unsafe style overrides which cause friction and incidents when {{componentName}} internals change.'
18
+ }
19
+ },
20
+ create(context) {
21
+ return {
22
+ CallExpression(node) {
23
+ if (node.callee.type !== 'Identifier' || !node.callee.name.toLowerCase().includes('styled')) {
24
+ // Ignore functions that don't look like styled().
25
+ return;
26
+ }
27
+ const firstArgument = node.arguments[0];
28
+ if (!firstArgument || firstArgument.type !== 'Identifier') {
29
+ return;
30
+ }
31
+ const moduleName = getModuleOfIdentifier(context.getSourceCode(), firstArgument.name);
32
+ if (!moduleName || !moduleName.moduleName.startsWith('@atlaskit')) {
33
+ // Ignore styled calls with non-atlaskit components.
34
+ return;
35
+ }
36
+ context.report({
37
+ node: firstArgument,
38
+ messageId: 'noUnsafeStyledOverride',
39
+ data: {
40
+ componentName: moduleName.importName
41
+ }
42
+ });
43
+ },
44
+ JSXAttribute(node) {
45
+ if (!isNodeOfType(node, 'JSXAttribute') || !(node.parent && isNodeOfType(node.parent, 'JSXOpeningElement'))) {
46
+ return;
47
+ }
48
+ const elementName = getJSXElementName(node.parent);
49
+ const moduleName = getModuleOfIdentifier(context.getSourceCode(), elementName);
50
+ if (!moduleName || !moduleName.moduleName.startsWith('@atlaskit')) {
51
+ return;
52
+ }
53
+ const propName = typeof node.name.name === 'string' ? node.name.name : node.name.name.name;
54
+ if (unsafeOverrides.includes(propName)) {
55
+ context.report({
56
+ node,
57
+ messageId: 'noUnsafeOverrides',
58
+ data: {
59
+ propName,
60
+ componentName: moduleName.importName
61
+ }
62
+ });
63
+ }
64
+ }
65
+ };
66
+ }
67
+ });
68
+ export default rule;
@@ -0,0 +1,9 @@
1
+ const defaults = {
2
+ patterns: ['div-object-css']
3
+ };
4
+ export const getConfig = overrides => {
5
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
6
+ // start with an empty object, then merge in the defaults, then merge in overrides.
7
+ // The empty object is returned, as well as modified in place
8
+ return Object.assign({}, defaults, overrides);
9
+ };
@@ -1,12 +1,9 @@
1
1
  import { getIdentifierInParentScope, isNodeOfType } from 'eslint-codemod-utils';
2
- import assign from 'lodash/assign';
3
2
  import { createLintRule } from '../utils/create-rule';
3
+ import { getConfig } from './config';
4
4
  import { jsxElementToBoxTransformer, styledComponentToPrimitive } from './transformers';
5
5
  import { containsOnlySupportedAttrs, findValidJsxUsageToTransform, findValidStyledComponentCall, getAttributeValueIdentifier, getJSXAttributeByName, getVariableDefinitionValue, getVariableUsagesCount, isFunctionNamed, isValidCssPropertiesToTransform, isValidTagName } from './utils';
6
6
  const boxDocsUrl = 'https://atlassian.design/components/primitives/box';
7
- const defaultConfig = {
8
- preview: false
9
- };
10
7
  const rule = createLintRule({
11
8
  meta: {
12
9
  name: 'use-primitives',
@@ -23,11 +20,11 @@ const rule = createLintRule({
23
20
  }
24
21
  },
25
22
  create(context) {
26
- const mergedConfig = assign({}, defaultConfig, context.options[0]);
23
+ const config = getConfig(context.options[0]);
27
24
  return {
28
25
  // transforms styled.<html>(...) usages
29
26
  CallExpression(node) {
30
- if (!mergedConfig.preview) {
27
+ if (!config.patterns.includes('compiled-styled-object')) {
31
28
  return;
32
29
  }
33
30
  if (!isNodeOfType(node, 'CallExpression')) {
@@ -57,6 +54,7 @@ const rule = createLintRule({
57
54
  },
58
55
  // transforms <div css={...}> usages
59
56
  JSXOpeningElement(node) {
57
+ const config = getConfig(context.options[0]);
60
58
  if (!isNodeOfType(node, 'JSXOpeningElement')) {
61
59
  return;
62
60
  }
@@ -66,7 +64,7 @@ const rule = createLintRule({
66
64
  if (!isNodeOfType(node.parent, 'JSXElement')) {
67
65
  return;
68
66
  }
69
- const suggestBox = shouldSuggestBox(node.parent, context);
67
+ const suggestBox = shouldSuggestBox(node.parent, context, config);
70
68
  if (suggestBox) {
71
69
  context.report({
72
70
  node: node,
@@ -84,7 +82,7 @@ const rule = createLintRule({
84
82
  };
85
83
  }
86
84
  });
87
- const shouldSuggestBox = (node, context
85
+ const shouldSuggestBox = (node, context, config
88
86
  // scope: Scope.Scope,
89
87
  ) => {
90
88
  if (!node) {
@@ -131,6 +129,9 @@ const shouldSuggestBox = (node, context
131
129
  if (!cssVariableValue || !isFunctionNamed(cssVariableValue, 'css')) {
132
130
  return false;
133
131
  }
132
+ if (!config.patterns.includes('div-object-css')) {
133
+ return false;
134
+ }
134
135
  return isValidCssPropertiesToTransform(cssVariableValue.node.init);
135
136
  };
136
137
  export default rule;
@@ -7,4 +7,31 @@
7
7
  */
8
8
  export const getImportedNodeBySource = (source, path) => {
9
9
  return source.ast.body.filter(node => node.type === 'ImportDeclaration').find(node => node.source.value === path);
10
+ };
11
+
12
+ /**
13
+ * Returns the module name of an identifier, if one exists.
14
+ *
15
+ * getModuleOfIdentifier(source, 'Button'); // "@atlaskit/button"
16
+ */
17
+ export const getModuleOfIdentifier = (source, identifierName) => {
18
+ for (const node of source.ast.body) {
19
+ if (node.type === 'ImportDeclaration') {
20
+ for (const spec of node.specifiers) {
21
+ if (spec.type === 'ImportDefaultSpecifier' && spec.local.name === identifierName) {
22
+ return {
23
+ moduleName: node.source.value + '',
24
+ importName: identifierName
25
+ };
26
+ }
27
+ if (spec.type === 'ImportSpecifier' && spec.local.name === identifierName) {
28
+ return {
29
+ moduleName: node.source.value + '',
30
+ importName: spec.imported.name
31
+ };
32
+ }
33
+ }
34
+ }
35
+ }
36
+ return undefined;
10
37
  };
@@ -1,4 +1,20 @@
1
1
  export function findProp(jsx, propName) {
2
2
  const labelProp = jsx.openingElement.attributes.find(attr => attr.type === 'JSXAttribute' && attr.name.name === propName);
3
3
  return labelProp;
4
+ }
5
+ function unrollMemberExpression(exp) {
6
+ if (exp.type === 'JSXIdentifier') {
7
+ return exp.name;
8
+ }
9
+ return unrollMemberExpression(exp.object);
10
+ }
11
+ export function getJSXElementName(jsx) {
12
+ switch (jsx.name.type) {
13
+ case 'JSXIdentifier':
14
+ return jsx.name.name;
15
+ case 'JSXMemberExpression':
16
+ return unrollMemberExpression(jsx.name.object);
17
+ case 'JSXNamespacedName':
18
+ return jsx.name.namespace.name;
19
+ }
4
20
  }
@@ -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::37a857efd0971ab26170d5f1f526279b>>
3
+ * @codegen <<SignedSource::6efa1e48692b3e287d6dfcd500a5f0ab>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  export default {
@@ -19,6 +19,7 @@ export default {
19
19
  '@atlaskit/design-system/no-nested-styles': 'error',
20
20
  '@atlaskit/design-system/no-physical-properties': 'error',
21
21
  '@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
22
+ '@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
22
23
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
23
24
  '@atlaskit/design-system/prefer-primitives': 'warn',
24
25
  '@atlaskit/design-system/use-drawer-label': '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::b3bce8efb2db1fed84370af608ca0d4c>>
3
+ * @codegen <<SignedSource::be810d87ec2d253e3b053dc06ff1b99a>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  export default {
@@ -15,6 +15,7 @@ export default {
15
15
  '@atlaskit/design-system/no-deprecated-imports': 'error',
16
16
  '@atlaskit/design-system/no-nested-styles': 'error',
17
17
  '@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
18
+ '@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
18
19
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
19
20
  '@atlaskit/design-system/use-drawer-label': 'warn',
20
21
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': '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::e2cc357c90120dbbd89b2928dba968c0>>
3
+ * @codegen <<SignedSource::ab1f5b129d07027c228dbd79da5f3572>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import consistentCssPropUsage from './consistent-css-prop-usage';
@@ -16,6 +16,7 @@ import noMargin from './no-margin';
16
16
  import noNestedStyles from './no-nested-styles';
17
17
  import noPhysicalProperties from './no-physical-properties';
18
18
  import noUnsafeDesignTokenUsage from './no-unsafe-design-token-usage';
19
+ import noUnsafeStyleOverrides from './no-unsafe-style-overrides';
19
20
  import noUnsupportedDragAndDropLibraries from './no-unsupported-drag-and-drop-libraries';
20
21
  import preferPrimitives from './prefer-primitives';
21
22
  import useDrawerLabel from './use-drawer-label';
@@ -37,6 +38,7 @@ export default {
37
38
  'no-nested-styles': noNestedStyles,
38
39
  'no-physical-properties': noPhysicalProperties,
39
40
  'no-unsafe-design-token-usage': noUnsafeDesignTokenUsage,
41
+ 'no-unsafe-style-overrides': noUnsafeStyleOverrides,
40
42
  'no-unsupported-drag-and-drop-libraries': noUnsupportedDragAndDropLibraries,
41
43
  'prefer-primitives': preferPrimitives,
42
44
  'use-drawer-label': useDrawerLabel,
@@ -0,0 +1,68 @@
1
+ import { isNodeOfType } from 'eslint-codemod-utils';
2
+ import { createLintRule } from '../utils/create-rule';
3
+ import { getModuleOfIdentifier } from '../utils/get-import-node-by-source';
4
+ import { getJSXElementName } from '../utils/jsx';
5
+ var unsafeOverrides = ['css', 'className', 'theme', 'cssFn', 'styles'];
6
+ var rule = createLintRule({
7
+ meta: {
8
+ docs: {
9
+ recommended: true,
10
+ // This should be an error but for now we're rolling it out as warn so we can actually get it into codebases.
11
+ severity: 'warn',
12
+ description: 'Discourage usage of unsafe style overrides used against the Atlassian Design System.'
13
+ },
14
+ name: 'no-unsafe-style-overrides',
15
+ messages: {
16
+ noUnsafeStyledOverride: 'Wrapping {{componentName}} in a styled component encourages unsafe style overrides which cause friction and incidents when its internals change.',
17
+ noUnsafeOverrides: 'The {{propName}} prop encourages unsafe style overrides which cause friction and incidents when {{componentName}} internals change.'
18
+ }
19
+ },
20
+ create: function create(context) {
21
+ return {
22
+ CallExpression: function CallExpression(node) {
23
+ if (node.callee.type !== 'Identifier' || !node.callee.name.toLowerCase().includes('styled')) {
24
+ // Ignore functions that don't look like styled().
25
+ return;
26
+ }
27
+ var firstArgument = node.arguments[0];
28
+ if (!firstArgument || firstArgument.type !== 'Identifier') {
29
+ return;
30
+ }
31
+ var moduleName = getModuleOfIdentifier(context.getSourceCode(), firstArgument.name);
32
+ if (!moduleName || !moduleName.moduleName.startsWith('@atlaskit')) {
33
+ // Ignore styled calls with non-atlaskit components.
34
+ return;
35
+ }
36
+ context.report({
37
+ node: firstArgument,
38
+ messageId: 'noUnsafeStyledOverride',
39
+ data: {
40
+ componentName: moduleName.importName
41
+ }
42
+ });
43
+ },
44
+ JSXAttribute: function JSXAttribute(node) {
45
+ if (!isNodeOfType(node, 'JSXAttribute') || !(node.parent && isNodeOfType(node.parent, 'JSXOpeningElement'))) {
46
+ return;
47
+ }
48
+ var elementName = getJSXElementName(node.parent);
49
+ var moduleName = getModuleOfIdentifier(context.getSourceCode(), elementName);
50
+ if (!moduleName || !moduleName.moduleName.startsWith('@atlaskit')) {
51
+ return;
52
+ }
53
+ var propName = typeof node.name.name === 'string' ? node.name.name : node.name.name.name;
54
+ if (unsafeOverrides.includes(propName)) {
55
+ context.report({
56
+ node: node,
57
+ messageId: 'noUnsafeOverrides',
58
+ data: {
59
+ propName: propName,
60
+ componentName: moduleName.importName
61
+ }
62
+ });
63
+ }
64
+ }
65
+ };
66
+ }
67
+ });
68
+ export default rule;
@@ -0,0 +1,9 @@
1
+ var defaults = {
2
+ patterns: ['div-object-css']
3
+ };
4
+ export var getConfig = function getConfig(overrides) {
5
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
6
+ // start with an empty object, then merge in the defaults, then merge in overrides.
7
+ // The empty object is returned, as well as modified in place
8
+ return Object.assign({}, defaults, overrides);
9
+ };
@@ -1,12 +1,9 @@
1
1
  import { getIdentifierInParentScope, isNodeOfType } from 'eslint-codemod-utils';
2
- import assign from 'lodash/assign';
3
2
  import { createLintRule } from '../utils/create-rule';
3
+ import { getConfig } from './config';
4
4
  import { jsxElementToBoxTransformer, styledComponentToPrimitive } from './transformers';
5
5
  import { containsOnlySupportedAttrs, findValidJsxUsageToTransform, findValidStyledComponentCall, getAttributeValueIdentifier, getJSXAttributeByName, getVariableDefinitionValue, getVariableUsagesCount, isFunctionNamed, isValidCssPropertiesToTransform, isValidTagName } from './utils';
6
6
  var boxDocsUrl = 'https://atlassian.design/components/primitives/box';
7
- var defaultConfig = {
8
- preview: false
9
- };
10
7
  var rule = createLintRule({
11
8
  meta: {
12
9
  name: 'use-primitives',
@@ -23,11 +20,11 @@ var rule = createLintRule({
23
20
  }
24
21
  },
25
22
  create: function create(context) {
26
- var mergedConfig = assign({}, defaultConfig, context.options[0]);
23
+ var config = getConfig(context.options[0]);
27
24
  return {
28
25
  // transforms styled.<html>(...) usages
29
26
  CallExpression: function CallExpression(node) {
30
- if (!mergedConfig.preview) {
27
+ if (!config.patterns.includes('compiled-styled-object')) {
31
28
  return;
32
29
  }
33
30
  if (!isNodeOfType(node, 'CallExpression')) {
@@ -57,6 +54,7 @@ var rule = createLintRule({
57
54
  },
58
55
  // transforms <div css={...}> usages
59
56
  JSXOpeningElement: function JSXOpeningElement(node) {
57
+ var config = getConfig(context.options[0]);
60
58
  if (!isNodeOfType(node, 'JSXOpeningElement')) {
61
59
  return;
62
60
  }
@@ -66,7 +64,7 @@ var rule = createLintRule({
66
64
  if (!isNodeOfType(node.parent, 'JSXElement')) {
67
65
  return;
68
66
  }
69
- var suggestBox = shouldSuggestBox(node.parent, context);
67
+ var suggestBox = shouldSuggestBox(node.parent, context, config);
70
68
  if (suggestBox) {
71
69
  context.report({
72
70
  node: node,
@@ -84,7 +82,7 @@ var rule = createLintRule({
84
82
  };
85
83
  }
86
84
  });
87
- var shouldSuggestBox = function shouldSuggestBox(node, context
85
+ var shouldSuggestBox = function shouldSuggestBox(node, context, config
88
86
  // scope: Scope.Scope,
89
87
  ) {
90
88
  if (!node) {
@@ -131,6 +129,9 @@ var shouldSuggestBox = function shouldSuggestBox(node, context
131
129
  if (!cssVariableValue || !isFunctionNamed(cssVariableValue, 'css')) {
132
130
  return false;
133
131
  }
132
+ if (!config.patterns.includes('div-object-css')) {
133
+ return false;
134
+ }
134
135
  return isValidCssPropertiesToTransform(cssVariableValue.node.init);
135
136
  };
136
137
  export default rule;
@@ -1,3 +1,6 @@
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; }
1
4
  // eslint-disable-next-line import/no-extraneous-dependencies
2
5
 
3
6
  /**
@@ -11,4 +14,49 @@ export var getImportedNodeBySource = function getImportedNodeBySource(source, pa
11
14
  }).find(function (node) {
12
15
  return node.source.value === path;
13
16
  });
17
+ };
18
+
19
+ /**
20
+ * Returns the module name of an identifier, if one exists.
21
+ *
22
+ * getModuleOfIdentifier(source, 'Button'); // "@atlaskit/button"
23
+ */
24
+ export var getModuleOfIdentifier = function getModuleOfIdentifier(source, identifierName) {
25
+ var _iterator = _createForOfIteratorHelper(source.ast.body),
26
+ _step;
27
+ try {
28
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
29
+ var node = _step.value;
30
+ if (node.type === 'ImportDeclaration') {
31
+ var _iterator2 = _createForOfIteratorHelper(node.specifiers),
32
+ _step2;
33
+ try {
34
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
35
+ var spec = _step2.value;
36
+ if (spec.type === 'ImportDefaultSpecifier' && spec.local.name === identifierName) {
37
+ return {
38
+ moduleName: node.source.value + '',
39
+ importName: identifierName
40
+ };
41
+ }
42
+ if (spec.type === 'ImportSpecifier' && spec.local.name === identifierName) {
43
+ return {
44
+ moduleName: node.source.value + '',
45
+ importName: spec.imported.name
46
+ };
47
+ }
48
+ }
49
+ } catch (err) {
50
+ _iterator2.e(err);
51
+ } finally {
52
+ _iterator2.f();
53
+ }
54
+ }
55
+ }
56
+ } catch (err) {
57
+ _iterator.e(err);
58
+ } finally {
59
+ _iterator.f();
60
+ }
61
+ return undefined;
14
62
  };
@@ -3,4 +3,20 @@ export function findProp(jsx, propName) {
3
3
  return attr.type === 'JSXAttribute' && attr.name.name === propName;
4
4
  });
5
5
  return labelProp;
6
+ }
7
+ function unrollMemberExpression(exp) {
8
+ if (exp.type === 'JSXIdentifier') {
9
+ return exp.name;
10
+ }
11
+ return unrollMemberExpression(exp.object);
12
+ }
13
+ export function getJSXElementName(jsx) {
14
+ switch (jsx.name.type) {
15
+ case 'JSXIdentifier':
16
+ return jsx.name.name;
17
+ case 'JSXMemberExpression':
18
+ return unrollMemberExpression(jsx.name.object);
19
+ case 'JSXNamespacedName':
20
+ return jsx.name.namespace.name;
21
+ }
6
22
  }
@@ -16,6 +16,7 @@ export declare const configs: {
16
16
  '@atlaskit/design-system/no-nested-styles': string;
17
17
  '@atlaskit/design-system/no-physical-properties': string;
18
18
  '@atlaskit/design-system/no-unsafe-design-token-usage': string;
19
+ '@atlaskit/design-system/no-unsafe-style-overrides': string;
19
20
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
20
21
  '@atlaskit/design-system/prefer-primitives': string;
21
22
  '@atlaskit/design-system/use-drawer-label': string;
@@ -37,6 +38,7 @@ export declare const configs: {
37
38
  '@atlaskit/design-system/no-deprecated-imports': string;
38
39
  '@atlaskit/design-system/no-nested-styles': string;
39
40
  '@atlaskit/design-system/no-unsafe-design-token-usage': string;
41
+ '@atlaskit/design-system/no-unsafe-style-overrides': string;
40
42
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
41
43
  '@atlaskit/design-system/use-drawer-label': string;
42
44
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': 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::37a857efd0971ab26170d5f1f526279b>>
3
+ * @codegen <<SignedSource::6efa1e48692b3e287d6dfcd500a5f0ab>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -19,6 +19,7 @@ declare const _default: {
19
19
  '@atlaskit/design-system/no-nested-styles': string;
20
20
  '@atlaskit/design-system/no-physical-properties': string;
21
21
  '@atlaskit/design-system/no-unsafe-design-token-usage': string;
22
+ '@atlaskit/design-system/no-unsafe-style-overrides': string;
22
23
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
23
24
  '@atlaskit/design-system/prefer-primitives': string;
24
25
  '@atlaskit/design-system/use-drawer-label': 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::b3bce8efb2db1fed84370af608ca0d4c>>
3
+ * @codegen <<SignedSource::be810d87ec2d253e3b053dc06ff1b99a>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -15,6 +15,7 @@ declare const _default: {
15
15
  '@atlaskit/design-system/no-deprecated-imports': string;
16
16
  '@atlaskit/design-system/no-nested-styles': string;
17
17
  '@atlaskit/design-system/no-unsafe-design-token-usage': string;
18
+ '@atlaskit/design-system/no-unsafe-style-overrides': string;
18
19
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
19
20
  '@atlaskit/design-system/use-drawer-label': string;
20
21
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
@@ -16,6 +16,7 @@ declare const _default: {
16
16
  'no-nested-styles': import("eslint").Rule.RuleModule;
17
17
  'no-physical-properties': import("eslint").Rule.RuleModule;
18
18
  'no-unsafe-design-token-usage': import("eslint").Rule.RuleModule;
19
+ 'no-unsafe-style-overrides': import("eslint").Rule.RuleModule;
19
20
  'no-unsupported-drag-and-drop-libraries': import("eslint").Rule.RuleModule;
20
21
  'prefer-primitives': import("eslint").Rule.RuleModule;
21
22
  'use-drawer-label': import("eslint").Rule.RuleModule;
@@ -0,0 +1,2 @@
1
+ declare const rule: import("eslint").Rule.RuleModule;
2
+ export default rule;
@@ -0,0 +1,4 @@
1
+ export interface RuleConfig {
2
+ patterns: ('div-object-css' | 'compiled-styled-object' | 'compiled-template-literal' | 'div-object-css-with-tokens' | 'div-object-css-with-multiple-vals')[];
3
+ }
4
+ export declare const getConfig: (overrides: Partial<RuleConfig>) => Required<RuleConfig>;
@@ -6,3 +6,12 @@ import type { ImportDeclaration } from 'eslint-codemod-utils';
6
6
  * @returns {ImportDeclaration}
7
7
  */
8
8
  export declare const getImportedNodeBySource: (source: SourceCode, path: string) => ImportDeclaration | undefined;
9
+ /**
10
+ * Returns the module name of an identifier, if one exists.
11
+ *
12
+ * getModuleOfIdentifier(source, 'Button'); // "@atlaskit/button"
13
+ */
14
+ export declare const getModuleOfIdentifier: (source: SourceCode, identifierName: string) => {
15
+ moduleName: string;
16
+ importName: string;
17
+ } | undefined;
@@ -1,2 +1,3 @@
1
- import type { JSXAttribute, JSXElement } from 'eslint-codemod-utils';
1
+ import type { JSXAttribute, JSXElement, JSXOpeningElement } from 'eslint-codemod-utils';
2
2
  export declare function findProp(jsx: JSXElement, propName: string): JSXAttribute | undefined;
3
+ export declare function getJSXElementName(jsx: JSXOpeningElement): string;
@@ -16,6 +16,7 @@ export declare const configs: {
16
16
  '@atlaskit/design-system/no-nested-styles': string;
17
17
  '@atlaskit/design-system/no-physical-properties': string;
18
18
  '@atlaskit/design-system/no-unsafe-design-token-usage': string;
19
+ '@atlaskit/design-system/no-unsafe-style-overrides': string;
19
20
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
20
21
  '@atlaskit/design-system/prefer-primitives': string;
21
22
  '@atlaskit/design-system/use-drawer-label': string;
@@ -37,6 +38,7 @@ export declare const configs: {
37
38
  '@atlaskit/design-system/no-deprecated-imports': string;
38
39
  '@atlaskit/design-system/no-nested-styles': string;
39
40
  '@atlaskit/design-system/no-unsafe-design-token-usage': string;
41
+ '@atlaskit/design-system/no-unsafe-style-overrides': string;
40
42
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
41
43
  '@atlaskit/design-system/use-drawer-label': string;
42
44
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': 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::37a857efd0971ab26170d5f1f526279b>>
3
+ * @codegen <<SignedSource::6efa1e48692b3e287d6dfcd500a5f0ab>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -19,6 +19,7 @@ declare const _default: {
19
19
  '@atlaskit/design-system/no-nested-styles': string;
20
20
  '@atlaskit/design-system/no-physical-properties': string;
21
21
  '@atlaskit/design-system/no-unsafe-design-token-usage': string;
22
+ '@atlaskit/design-system/no-unsafe-style-overrides': string;
22
23
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
23
24
  '@atlaskit/design-system/prefer-primitives': string;
24
25
  '@atlaskit/design-system/use-drawer-label': 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::b3bce8efb2db1fed84370af608ca0d4c>>
3
+ * @codegen <<SignedSource::be810d87ec2d253e3b053dc06ff1b99a>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -15,6 +15,7 @@ declare const _default: {
15
15
  '@atlaskit/design-system/no-deprecated-imports': string;
16
16
  '@atlaskit/design-system/no-nested-styles': string;
17
17
  '@atlaskit/design-system/no-unsafe-design-token-usage': string;
18
+ '@atlaskit/design-system/no-unsafe-style-overrides': string;
18
19
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
19
20
  '@atlaskit/design-system/use-drawer-label': string;
20
21
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
@@ -20,6 +20,7 @@ declare const _default: {
20
20
  'no-nested-styles': import("eslint").Rule.RuleModule;
21
21
  'no-physical-properties': import("eslint").Rule.RuleModule;
22
22
  'no-unsafe-design-token-usage': import("eslint").Rule.RuleModule;
23
+ 'no-unsafe-style-overrides': import("eslint").Rule.RuleModule;
23
24
  'no-unsupported-drag-and-drop-libraries': import("eslint").Rule.RuleModule;
24
25
  'prefer-primitives': import("eslint").Rule.RuleModule;
25
26
  'use-drawer-label': import("eslint").Rule.RuleModule;
@@ -0,0 +1,2 @@
1
+ declare const rule: import("eslint").Rule.RuleModule;
2
+ export default rule;
@@ -0,0 +1,4 @@
1
+ export interface RuleConfig {
2
+ patterns: ('div-object-css' | 'compiled-styled-object' | 'compiled-template-literal' | 'div-object-css-with-tokens' | 'div-object-css-with-multiple-vals')[];
3
+ }
4
+ export declare const getConfig: (overrides: Partial<RuleConfig>) => Required<RuleConfig>;
@@ -6,3 +6,12 @@ import type { ImportDeclaration } from 'eslint-codemod-utils';
6
6
  * @returns {ImportDeclaration}
7
7
  */
8
8
  export declare const getImportedNodeBySource: (source: SourceCode, path: string) => ImportDeclaration | undefined;
9
+ /**
10
+ * Returns the module name of an identifier, if one exists.
11
+ *
12
+ * getModuleOfIdentifier(source, 'Button'); // "@atlaskit/button"
13
+ */
14
+ export declare const getModuleOfIdentifier: (source: SourceCode, identifierName: string) => {
15
+ moduleName: string;
16
+ importName: string;
17
+ } | undefined;
@@ -1,2 +1,3 @@
1
- import type { JSXAttribute, JSXElement } from 'eslint-codemod-utils';
1
+ import type { JSXAttribute, JSXElement, JSXOpeningElement } from 'eslint-codemod-utils';
2
2
  export declare function findProp(jsx: JSXElement, propName: string): JSXAttribute | undefined;
3
+ export declare function getJSXElementName(jsx: JSXOpeningElement): string;
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.18.1",
4
+ "version": "8.19.1",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "publishConfig": {
7
7
  "registry": "https://registry.npmjs.org/"