@atlaskit/eslint-plugin-design-system 8.27.0 → 8.28.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 (97) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +31 -29
  3. package/constellation/consistent-css-prop-usage/usage.mdx +193 -0
  4. package/constellation/ensure-design-token-usage/usage.mdx +72 -0
  5. package/constellation/ensure-design-token-usage-preview/usage.mdx +5 -0
  6. package/constellation/icon-label/usage.mdx +39 -0
  7. package/constellation/index/usage.mdx +31 -1508
  8. package/constellation/local-cx-xcss/usage.mdx +37 -0
  9. package/constellation/no-banned-imports/usage.mdx +17 -0
  10. package/constellation/no-css-tagged-template-expression/usage.mdx +66 -0
  11. package/constellation/no-deprecated-apis/usage.mdx +76 -0
  12. package/constellation/no-deprecated-design-token-usage/usage.mdx +27 -0
  13. package/constellation/no-deprecated-imports/usage.mdx +62 -0
  14. package/constellation/no-empty-styled-expression/usage.mdx +77 -0
  15. package/constellation/no-exported-css/usage.mdx +50 -0
  16. package/constellation/no-exported-keyframes/usage.mdx +50 -0
  17. package/constellation/no-invalid-css-map/usage.mdx +199 -0
  18. package/constellation/no-keyframes-tagged-template-expression/usage.mdx +76 -0
  19. package/constellation/no-margin/usage.mdx +20 -0
  20. package/constellation/no-nested-styles/usage.mdx +47 -0
  21. package/constellation/no-physical-properties/usage.mdx +53 -0
  22. package/constellation/no-styled-tagged-template-expression/usage.mdx +90 -0
  23. package/constellation/no-unsafe-design-token-usage/usage.mdx +49 -0
  24. package/constellation/no-unsafe-style-overrides/usage.mdx +49 -0
  25. package/constellation/no-unsupported-drag-and-drop-libraries/usage.mdx +17 -0
  26. package/constellation/prefer-primitives/usage.mdx +31 -0
  27. package/constellation/use-button-group-label/usage.mdx +58 -0
  28. package/constellation/use-drawer-label/usage.mdx +53 -0
  29. package/constellation/use-heading-level-in-spotlight-card/usage.mdx +20 -0
  30. package/constellation/use-href-in-link-item/usage.mdx +18 -0
  31. package/constellation/use-primitives/usage.mdx +77 -0
  32. package/constellation/use-visually-hidden/usage.mdx +34 -0
  33. package/dist/cjs/presets/all.codegen.js +3 -1
  34. package/dist/cjs/rules/index.codegen.js +5 -1
  35. package/dist/cjs/rules/no-css-tagged-template-expression/index.js +3 -2
  36. package/dist/cjs/rules/no-keyframes-tagged-template-expression/index.js +27 -0
  37. package/dist/cjs/rules/no-styled-tagged-template-expression/index.js +27 -0
  38. package/dist/cjs/rules/no-styled-tagged-template-expression/is-styled.js +53 -0
  39. package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/index.js +26 -6
  40. package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.js +28 -2
  41. package/dist/cjs/rules/utils/create-rule.js +7 -5
  42. package/dist/cjs/rules/utils/is-supported-import.js +7 -10
  43. package/dist/es2019/presets/all.codegen.js +3 -1
  44. package/dist/es2019/rules/index.codegen.js +5 -1
  45. package/dist/es2019/rules/no-css-tagged-template-expression/index.js +3 -2
  46. package/dist/es2019/rules/no-keyframes-tagged-template-expression/index.js +21 -0
  47. package/dist/es2019/rules/no-styled-tagged-template-expression/index.js +21 -0
  48. package/dist/es2019/rules/no-styled-tagged-template-expression/is-styled.js +45 -0
  49. package/dist/es2019/rules/utils/create-no-tagged-template-expression-rule/index.js +84 -0
  50. package/dist/es2019/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.js +28 -2
  51. package/dist/es2019/rules/utils/create-rule.js +7 -5
  52. package/dist/es2019/rules/utils/is-supported-import.js +7 -8
  53. package/dist/esm/presets/all.codegen.js +3 -1
  54. package/dist/esm/rules/index.codegen.js +5 -1
  55. package/dist/esm/rules/no-css-tagged-template-expression/index.js +3 -2
  56. package/dist/esm/rules/no-keyframes-tagged-template-expression/index.js +21 -0
  57. package/dist/esm/rules/no-styled-tagged-template-expression/index.js +21 -0
  58. package/dist/esm/rules/no-styled-tagged-template-expression/is-styled.js +47 -0
  59. package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/index.js +25 -5
  60. package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.js +28 -2
  61. package/dist/esm/rules/utils/create-rule.js +7 -5
  62. package/dist/esm/rules/utils/is-supported-import.js +7 -9
  63. package/dist/types/index.codegen.d.ts +2 -0
  64. package/dist/types/presets/all.codegen.d.ts +3 -1
  65. package/dist/types/rules/index.codegen.d.ts +2 -0
  66. package/dist/types/rules/no-keyframes-tagged-template-expression/index.d.ts +2 -0
  67. package/dist/types/rules/no-styled-tagged-template-expression/index.d.ts +2 -0
  68. package/dist/types/rules/no-styled-tagged-template-expression/is-styled.d.ts +7 -0
  69. package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/index.d.ts +3 -1
  70. package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.d.ts +3 -0
  71. package/dist/types/rules/utils/is-supported-import.d.ts +5 -5
  72. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  73. package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -1
  74. package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
  75. package/dist/types-ts4.5/rules/no-keyframes-tagged-template-expression/index.d.ts +2 -0
  76. package/dist/types-ts4.5/rules/no-styled-tagged-template-expression/index.d.ts +2 -0
  77. package/dist/types-ts4.5/rules/no-styled-tagged-template-expression/is-styled.d.ts +7 -0
  78. package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/index.d.ts +3 -1
  79. package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.d.ts +3 -0
  80. package/dist/types-ts4.5/rules/utils/is-supported-import.d.ts +5 -5
  81. package/package.json +1 -1
  82. package/dist/es2019/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.js +0 -62
  83. /package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.js +0 -0
  84. /package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.js +0 -0
  85. /package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.js +0 -0
  86. /package/dist/es2019/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.js +0 -0
  87. /package/dist/es2019/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.js +0 -0
  88. /package/dist/es2019/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.js +0 -0
  89. /package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.js +0 -0
  90. /package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.js +0 -0
  91. /package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.js +0 -0
  92. /package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.d.ts +0 -0
  93. /package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.d.ts +0 -0
  94. /package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.d.ts +0 -0
  95. /package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.d.ts +0 -0
  96. /package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.d.ts +0 -0
  97. /package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.d.ts +0 -0
@@ -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::914085544778f4543f43e3e30d0982e0>>
9
+ * @codegen <<SignedSource::5647ce9c10ba880cffece66b5924fd6e>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -26,9 +26,11 @@ var _default = exports.default = {
26
26
  '@atlaskit/design-system/no-exported-css': 'warn',
27
27
  '@atlaskit/design-system/no-exported-keyframes': 'warn',
28
28
  '@atlaskit/design-system/no-invalid-css-map': 'error',
29
+ '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'error',
29
30
  '@atlaskit/design-system/no-margin': 'warn',
30
31
  '@atlaskit/design-system/no-nested-styles': 'error',
31
32
  '@atlaskit/design-system/no-physical-properties': 'error',
33
+ '@atlaskit/design-system/no-styled-tagged-template-expression': 'error',
32
34
  '@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
33
35
  '@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
34
36
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
@@ -19,9 +19,11 @@ var _noEmptyStyledExpression = _interopRequireDefault(require("./no-empty-styled
19
19
  var _noExportedCss = _interopRequireDefault(require("./no-exported-css"));
20
20
  var _noExportedKeyframes = _interopRequireDefault(require("./no-exported-keyframes"));
21
21
  var _noInvalidCssMap = _interopRequireDefault(require("./no-invalid-css-map"));
22
+ var _noKeyframesTaggedTemplateExpression = _interopRequireDefault(require("./no-keyframes-tagged-template-expression"));
22
23
  var _noMargin = _interopRequireDefault(require("./no-margin"));
23
24
  var _noNestedStyles = _interopRequireDefault(require("./no-nested-styles"));
24
25
  var _noPhysicalProperties = _interopRequireDefault(require("./no-physical-properties"));
26
+ var _noStyledTaggedTemplateExpression = _interopRequireDefault(require("./no-styled-tagged-template-expression"));
25
27
  var _noUnsafeDesignTokenUsage = _interopRequireDefault(require("./no-unsafe-design-token-usage"));
26
28
  var _noUnsafeStyleOverrides = _interopRequireDefault(require("./no-unsafe-style-overrides"));
27
29
  var _noUnsupportedDragAndDropLibraries = _interopRequireDefault(require("./no-unsupported-drag-and-drop-libraries"));
@@ -34,7 +36,7 @@ var _usePrimitives = _interopRequireDefault(require("./use-primitives"));
34
36
  var _useVisuallyHidden = _interopRequireDefault(require("./use-visually-hidden"));
35
37
  /**
36
38
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
37
- * @codegen <<SignedSource::0a2d88c9772eb438048415f13550f592>>
39
+ * @codegen <<SignedSource::0a2813f0b87e94d23e1f6fc388539c70>>
38
40
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
39
41
  */
40
42
  var _default = exports.default = {
@@ -52,9 +54,11 @@ var _default = exports.default = {
52
54
  'no-exported-css': _noExportedCss.default,
53
55
  'no-exported-keyframes': _noExportedKeyframes.default,
54
56
  'no-invalid-css-map': _noInvalidCssMap.default,
57
+ 'no-keyframes-tagged-template-expression': _noKeyframesTaggedTemplateExpression.default,
55
58
  'no-margin': _noMargin.default,
56
59
  'no-nested-styles': _noNestedStyles.default,
57
60
  'no-physical-properties': _noPhysicalProperties.default,
61
+ 'no-styled-tagged-template-expression': _noStyledTaggedTemplateExpression.default,
58
62
  'no-unsafe-design-token-usage': _noUnsafeDesignTokenUsage.default,
59
63
  'no-unsafe-style-overrides': _noUnsafeStyleOverrides.default,
60
64
  'no-unsupported-drag-and-drop-libraries': _noUnsupportedDragAndDropLibraries.default,
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _createNoTaggedTemplateExpressionRule = require("../utils/create-no-tagged-template-expression-rule");
7
8
  var _createRule = require("../utils/create-rule");
8
9
  var _isSupportedImport = require("../utils/is-supported-import");
9
- var _createNoTaggedTemplateExpressionRule = require("./create-no-tagged-template-expression-rule");
10
10
  var rule = (0, _createRule.createLintRule)({
11
11
  meta: {
12
12
  name: 'no-css-tagged-template-expression',
@@ -19,7 +19,8 @@ var rule = (0, _createRule.createLintRule)({
19
19
  },
20
20
  messages: {
21
21
  unexpectedTaggedTemplate: 'Unexpected `css` tagged template expression'
22
- }
22
+ },
23
+ schema: _createNoTaggedTemplateExpressionRule.noTaggedTemplateExpressionRuleSchema
23
24
  },
24
25
  create: (0, _createNoTaggedTemplateExpressionRule.createNoTaggedTemplateExpressionRule)(_isSupportedImport.isCss, 'unexpectedTaggedTemplate')
25
26
  });
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _createNoTaggedTemplateExpressionRule = require("../utils/create-no-tagged-template-expression-rule");
8
+ var _createRule = require("../utils/create-rule");
9
+ var _isSupportedImport = require("../utils/is-supported-import");
10
+ var rule = (0, _createRule.createLintRule)({
11
+ meta: {
12
+ name: 'no-keyframes-tagged-template-expression',
13
+ fixable: 'code',
14
+ type: 'problem',
15
+ docs: {
16
+ description: 'Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled',
17
+ recommended: false,
18
+ severity: 'error'
19
+ },
20
+ messages: {
21
+ unexpectedTaggedTemplate: 'Unexpected `keyframes` tagged template expression'
22
+ },
23
+ schema: _createNoTaggedTemplateExpressionRule.noTaggedTemplateExpressionRuleSchema
24
+ },
25
+ create: (0, _createNoTaggedTemplateExpressionRule.createNoTaggedTemplateExpressionRule)(_isSupportedImport.isKeyframes, 'unexpectedTaggedTemplate')
26
+ });
27
+ var _default = exports.default = rule;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _createNoTaggedTemplateExpressionRule = require("../utils/create-no-tagged-template-expression-rule");
8
+ var _createRule = require("../utils/create-rule");
9
+ var _isStyled = require("./is-styled");
10
+ var rule = (0, _createRule.createLintRule)({
11
+ meta: {
12
+ name: 'no-styled-tagged-template-expression',
13
+ fixable: 'code',
14
+ type: 'problem',
15
+ docs: {
16
+ description: 'Disallows any `styled` tagged template expressions that originate from Emotion, Styled Components or Compiled',
17
+ recommended: false,
18
+ severity: 'error'
19
+ },
20
+ messages: {
21
+ unexpectedTaggedTemplate: 'Unexpected `styled` tagged template expression'
22
+ },
23
+ schema: _createNoTaggedTemplateExpressionRule.noTaggedTemplateExpressionRuleSchema
24
+ },
25
+ create: (0, _createNoTaggedTemplateExpressionRule.createNoTaggedTemplateExpressionRule)(_isStyled.isStyled, 'unexpectedTaggedTemplate')
26
+ });
27
+ var _default = exports.default = rule;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isStyled = void 0;
7
+ var _isSupportedImport = require("../utils/is-supported-import");
8
+ // eslint-disable-next-line import/no-extraneous-dependencies
9
+
10
+ var functionName = 'styled';
11
+ var checkDefinitionHasImport = function checkDefinitionHasImport(def, importSources) {
12
+ if (def.type !== 'ImportBinding') {
13
+ return false;
14
+ }
15
+ if (!def.parent || !importSources.includes(def.parent.source.value)) {
16
+ return false;
17
+ }
18
+
19
+ // `@compiled/react` only exposes styled as a named export
20
+ if (importSources.includes(_isSupportedImport.CSS_IN_JS_IMPORTS.compiled) && def.parent.source.value === _isSupportedImport.CSS_IN_JS_IMPORTS.compiled) {
21
+ return def.node.type === 'ImportSpecifier' && def.node.imported.name === functionName;
22
+ }
23
+
24
+ // `@emotion/styled` only exposes styled as a default export
25
+ if (importSources.includes(_isSupportedImport.CSS_IN_JS_IMPORTS.emotionStyled) && def.parent.source.value === _isSupportedImport.CSS_IN_JS_IMPORTS.emotionStyled) {
26
+ return def.node.type === 'ImportDefaultSpecifier';
27
+ }
28
+
29
+ // `styled-components` only exposes styled as a default export
30
+ if (importSources.includes(_isSupportedImport.CSS_IN_JS_IMPORTS.styledComponents) && def.parent.source.value === _isSupportedImport.CSS_IN_JS_IMPORTS.styledComponents) {
31
+ return def.node.type === 'ImportDefaultSpecifier';
32
+ }
33
+ return false;
34
+ };
35
+ var isStyled = exports.isStyled = function isStyled(nodeToCheck, referencesInScope, importSources) {
36
+ var nodeIdentifier = null;
37
+
38
+ // Handles styled.div`` case
39
+ if (nodeToCheck.type === 'MemberExpression' && nodeToCheck.object.type === 'Identifier') {
40
+ nodeIdentifier = nodeToCheck.object;
41
+ }
42
+
43
+ // Handles styled(Base)`` case
44
+ if (nodeToCheck.type === 'CallExpression' && nodeToCheck.callee.type === 'Identifier') {
45
+ nodeIdentifier = nodeToCheck.callee;
46
+ }
47
+ return referencesInScope.some(function (reference) {
48
+ var _reference$resolved;
49
+ return reference.identifier === nodeIdentifier && ((_reference$resolved = reference.resolved) === null || _reference$resolved === void 0 ? void 0 : _reference$resolved.defs.some(function (def) {
50
+ return checkDefinitionHasImport(def, importSources);
51
+ }));
52
+ });
53
+ };
@@ -4,23 +4,43 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.createNoTaggedTemplateExpressionRule = void 0;
7
+ exports.noTaggedTemplateExpressionRuleSchema = exports.createNoTaggedTemplateExpressionRule = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _isSupportedImport = require("../../utils/is-supported-import");
9
+ var _isSupportedImport = require("../is-supported-import");
10
10
  var _generate = require("./generate");
11
11
  var _getTaggedTemplateExpressionOffset = require("./get-tagged-template-expression-offset");
12
12
  var _toArguments = require("./to-arguments");
13
13
  // Original source from Compiled https://github.com/atlassian-labs/compiled/blob/master/packages/eslint-plugin/src/utils/create-no-tagged-template-expression-rule/index.ts
14
14
  // eslint-disable-next-line import/no-extraneous-dependencies
15
15
 
16
- var IMPORT_SOURCES = [_isSupportedImport.CSS_IN_JS_IMPORTS.compiled, _isSupportedImport.CSS_IN_JS_IMPORTS.emotionReact, _isSupportedImport.CSS_IN_JS_IMPORTS.emotionCore, _isSupportedImport.CSS_IN_JS_IMPORTS.styledComponents];
16
+ var noTaggedTemplateExpressionRuleSchema = exports.noTaggedTemplateExpressionRuleSchema = [{
17
+ type: 'object',
18
+ properties: {
19
+ importSources: {
20
+ type: 'array',
21
+ items: {
22
+ type: 'string'
23
+ },
24
+ uniqueItems: true
25
+ }
26
+ }
27
+ }];
28
+
29
+ /**
30
+ * When true, template strings containing multiline comments are completely skipped over.
31
+ *
32
+ * When false, multiline comments are stripped out. Ideally we would preserve them,
33
+ * but it would add a lot of complexity.
34
+ */
35
+ var shouldSkipMultilineComments = false;
17
36
  var createNoTaggedTemplateExpressionRule = exports.createNoTaggedTemplateExpressionRule = function createNoTaggedTemplateExpressionRule(isUsage, messageId) {
18
37
  return function (context) {
38
+ var importSources = (0, _isSupportedImport.getImportSources)(context);
19
39
  return {
20
40
  TaggedTemplateExpression: function TaggedTemplateExpression(node) {
21
41
  var _context$getScope = context.getScope(),
22
42
  references = _context$getScope.references;
23
- if (!isUsage(node.tag, references, IMPORT_SOURCES)) {
43
+ if (!isUsage(node.tag, references, importSources)) {
24
44
  return;
25
45
  }
26
46
  context.report({
@@ -34,9 +54,9 @@ var createNoTaggedTemplateExpressionRule = exports.createNoTaggedTemplateExpress
34
54
  quasi = node.quasi;
35
55
  source = context.getSourceCode(); // TODO Eventually handle comments instead of skipping them
36
56
  // Skip auto-fixing comments
37
- if (!quasi.quasis.map(function (q) {
57
+ if (!(shouldSkipMultilineComments && quasi.quasis.map(function (q) {
38
58
  return q.value.raw;
39
- }).join('').match(/\/\*[\s\S]*\*\//g)) {
59
+ }).join('').match(/\/\*[\s\S]*\*\//g))) {
40
60
  _context.next = 4;
41
61
  break;
42
62
  }
@@ -56,7 +56,30 @@ var getArguments = function getArguments(chars) {
56
56
  }
57
57
  }
58
58
  var getValue = function getValue() {
59
- if (!value.trim().length && expressions.length) {
59
+ /**
60
+ * This branch is required for handling interpolated functions:
61
+ *
62
+ * css`
63
+ * color: ${(props) => props.textColor}
64
+ * `
65
+ *
66
+ * But it also breaks interpolations of multiple tokens:
67
+ *
68
+ * css`
69
+ * padding: ${token('space.100')} ${token('space.200')}
70
+ * `
71
+ *
72
+ * which becomes invalid syntax:
73
+ *
74
+ * css({
75
+ * padding: token('space.100')token('space.200')
76
+ * })
77
+ *
78
+ * Limiting this branch to when `expressions.length === 1` seems
79
+ * to allow both cases to work. There may be other edge cases,
80
+ * but none were caught by the existing test suite.
81
+ */
82
+ if (!value.trim().length && expressions.length === 1) {
60
83
  return {
61
84
  type: 'expression',
62
85
  expression: expressions.map(function (e) {
@@ -184,7 +207,10 @@ var toArguments = exports.toArguments = function toArguments(source, template) {
184
207
  i = _step4$value[0],
185
208
  quasi = _step4$value[1];
186
209
  // Deal with selectors across multiple lines
187
- var styleTemplateElement = quasi.value.raw.replace(/(\r\n|\n|\r)/gm, ' ').replace(/\s+/g, ' ');
210
+ var styleTemplateElement = quasi.value.raw.replace(/\/\*(.|\n|\r)*?\*\//g, '') // Removes multi-line comments
211
+ // Remove single line comments
212
+ // Negative lookbehind to handle URL-like double slashes
213
+ .replace(/(?<!https?:)\/\/.*$/gm, '').replace(/(\r\n|\n|\r)/gm, ' ').replace(/\s+/g, ' ');
188
214
  var _iterator5 = _createForOfIteratorHelper(styleTemplateElement),
189
215
  _step5;
190
216
  try {
@@ -17,7 +17,7 @@ var _utils = require("@typescript-eslint/utils");
17
17
  * @deprecated
18
18
  */
19
19
  var createRule = exports.createRule = _utils.ESLintUtils.RuleCreator(function (name) {
20
- return "https://atlassian.design/components/eslint-plugin-design-system/usage#".concat(name);
20
+ return getRuleUrl(name);
21
21
  });
22
22
  /**
23
23
  * Tiny wrapped over the ESLint rule module type that ensures
@@ -25,8 +25,10 @@ var createRule = exports.createRule = _utils.ESLintUtils.RuleCreator(function (n
25
25
  * as well as improving type support.
26
26
  */
27
27
  var createLintRule = exports.createLintRule = function createLintRule(rule) {
28
- var ruleName = rule.meta.name.replace('/', ''); // If it's a nested rule, ensure the url is clean
29
- var url = "https://atlassian.design/components/eslint-plugin-design-system/usage#".concat(ruleName);
30
- rule.meta.docs.url = url;
28
+ rule.meta.docs.url = getRuleUrl(rule.meta.name);
31
29
  return rule;
32
- };
30
+ };
31
+ function getRuleUrl(ruleName) {
32
+ var name = ruleName.replace('/', '-'); // If it's a nested rule, ensure the url is clean and matches codegen/gatsby
33
+ return "https://atlassian.design/components/eslint-plugin-design-system/".concat(name, "/usage");
34
+ }
@@ -1,17 +1,16 @@
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.isStyled = exports.isKeyframes = exports.isCxFunction = exports.isCssMap = exports.isCss = exports.getImportSources = exports.DEFAULT_IMPORT_SOURCES = exports.CSS_IN_JS_IMPORTS = void 0;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
7
  // eslint-disable-next-line import/no-extraneous-dependencies
10
8
 
11
9
  var CSS_IN_JS_IMPORTS = exports.CSS_IN_JS_IMPORTS = {
12
10
  compiled: '@compiled/react',
13
11
  emotionReact: '@emotion/react',
14
12
  emotionCore: '@emotion/core',
13
+ emotionStyled: '@emotion/styled',
15
14
  styledComponents: 'styled-components',
16
15
  atlaskitCss: '@atlaskit/css',
17
16
  atlaskitPrimitives: '@atlaskit/primitives'
@@ -20,16 +19,14 @@ var CSS_IN_JS_IMPORTS = exports.CSS_IN_JS_IMPORTS = {
20
19
  // A CSS-in-JS library an import of a valid css, cx, cssMap, etc.
21
20
  // function might originate from, e.g. @compiled/react, @emotion/core.
22
21
 
23
- // All ESLint rules originating from `@compiled/eslint-plugin` should apply to these libraries.
24
- var DEFAULT_IMPORT_SOURCES = exports.DEFAULT_IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.compiled, CSS_IN_JS_IMPORTS.atlaskitCss];
22
+ /**
23
+ * By default all known import sources are checked against.
24
+ */
25
+ var DEFAULT_IMPORT_SOURCES = exports.DEFAULT_IMPORT_SOURCES = Object.values(CSS_IN_JS_IMPORTS);
25
26
 
26
27
  /**
27
28
  * Given the ESLint rule context, extract and parse the value of the importSources rule option.
28
- * The importSources option is used to define additional libraries for which an ESLint rule
29
- * should apply to.
30
- *
31
- * Note that `@compiled/react` and `@atlaskit/css` are always included in importSources, regardless
32
- * of what importSources is configured to by the user.
29
+ * The importSources option is used to override which libraries an ESLint rule applies to.
33
30
  *
34
31
  * @param context The rule context.
35
32
  * @returns An array of strings representing what CSS-in-JS packages that should be checked, based
@@ -41,7 +38,7 @@ var getImportSources = exports.getImportSources = function getImportSources(cont
41
38
  return DEFAULT_IMPORT_SOURCES;
42
39
  }
43
40
  if (options[0].importSources && Array.isArray(options[0].importSources)) {
44
- return [].concat(DEFAULT_IMPORT_SOURCES, (0, _toConsumableArray2.default)(options[0].importSources));
41
+ return options[0].importSources;
45
42
  }
46
43
  return DEFAULT_IMPORT_SOURCES;
47
44
  };
@@ -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::914085544778f4543f43e3e30d0982e0>>
3
+ * @codegen <<SignedSource::5647ce9c10ba880cffece66b5924fd6e>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  export default {
@@ -20,9 +20,11 @@ export default {
20
20
  '@atlaskit/design-system/no-exported-css': 'warn',
21
21
  '@atlaskit/design-system/no-exported-keyframes': 'warn',
22
22
  '@atlaskit/design-system/no-invalid-css-map': 'error',
23
+ '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'error',
23
24
  '@atlaskit/design-system/no-margin': 'warn',
24
25
  '@atlaskit/design-system/no-nested-styles': 'error',
25
26
  '@atlaskit/design-system/no-physical-properties': 'error',
27
+ '@atlaskit/design-system/no-styled-tagged-template-expression': 'error',
26
28
  '@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
27
29
  '@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
28
30
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
@@ -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::0a2d88c9772eb438048415f13550f592>>
3
+ * @codegen <<SignedSource::0a2813f0b87e94d23e1f6fc388539c70>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import consistentCssPropUsage from './consistent-css-prop-usage';
@@ -17,9 +17,11 @@ import noEmptyStyledExpression from './no-empty-styled-expression';
17
17
  import noExportedCss from './no-exported-css';
18
18
  import noExportedKeyframes from './no-exported-keyframes';
19
19
  import noInvalidCssMap from './no-invalid-css-map';
20
+ import noKeyframesTaggedTemplateExpression from './no-keyframes-tagged-template-expression';
20
21
  import noMargin from './no-margin';
21
22
  import noNestedStyles from './no-nested-styles';
22
23
  import noPhysicalProperties from './no-physical-properties';
24
+ import noStyledTaggedTemplateExpression from './no-styled-tagged-template-expression';
23
25
  import noUnsafeDesignTokenUsage from './no-unsafe-design-token-usage';
24
26
  import noUnsafeStyleOverrides from './no-unsafe-style-overrides';
25
27
  import noUnsupportedDragAndDropLibraries from './no-unsupported-drag-and-drop-libraries';
@@ -45,9 +47,11 @@ export default {
45
47
  'no-exported-css': noExportedCss,
46
48
  'no-exported-keyframes': noExportedKeyframes,
47
49
  'no-invalid-css-map': noInvalidCssMap,
50
+ 'no-keyframes-tagged-template-expression': noKeyframesTaggedTemplateExpression,
48
51
  'no-margin': noMargin,
49
52
  'no-nested-styles': noNestedStyles,
50
53
  'no-physical-properties': noPhysicalProperties,
54
+ 'no-styled-tagged-template-expression': noStyledTaggedTemplateExpression,
51
55
  'no-unsafe-design-token-usage': noUnsafeDesignTokenUsage,
52
56
  'no-unsafe-style-overrides': noUnsafeStyleOverrides,
53
57
  'no-unsupported-drag-and-drop-libraries': noUnsupportedDragAndDropLibraries,
@@ -1,6 +1,6 @@
1
+ import { createNoTaggedTemplateExpressionRule, noTaggedTemplateExpressionRuleSchema } from '../utils/create-no-tagged-template-expression-rule';
1
2
  import { createLintRule } from '../utils/create-rule';
2
3
  import { isCss } from '../utils/is-supported-import';
3
- import { createNoTaggedTemplateExpressionRule } from './create-no-tagged-template-expression-rule';
4
4
  const rule = createLintRule({
5
5
  meta: {
6
6
  name: 'no-css-tagged-template-expression',
@@ -13,7 +13,8 @@ const rule = createLintRule({
13
13
  },
14
14
  messages: {
15
15
  unexpectedTaggedTemplate: 'Unexpected `css` tagged template expression'
16
- }
16
+ },
17
+ schema: noTaggedTemplateExpressionRuleSchema
17
18
  },
18
19
  create: createNoTaggedTemplateExpressionRule(isCss, 'unexpectedTaggedTemplate')
19
20
  });
@@ -0,0 +1,21 @@
1
+ import { createNoTaggedTemplateExpressionRule, noTaggedTemplateExpressionRuleSchema } from '../utils/create-no-tagged-template-expression-rule';
2
+ import { createLintRule } from '../utils/create-rule';
3
+ import { isKeyframes } from '../utils/is-supported-import';
4
+ const rule = createLintRule({
5
+ meta: {
6
+ name: 'no-keyframes-tagged-template-expression',
7
+ fixable: 'code',
8
+ type: 'problem',
9
+ docs: {
10
+ description: 'Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled',
11
+ recommended: false,
12
+ severity: 'error'
13
+ },
14
+ messages: {
15
+ unexpectedTaggedTemplate: 'Unexpected `keyframes` tagged template expression'
16
+ },
17
+ schema: noTaggedTemplateExpressionRuleSchema
18
+ },
19
+ create: createNoTaggedTemplateExpressionRule(isKeyframes, 'unexpectedTaggedTemplate')
20
+ });
21
+ export default rule;
@@ -0,0 +1,21 @@
1
+ import { createNoTaggedTemplateExpressionRule, noTaggedTemplateExpressionRuleSchema } from '../utils/create-no-tagged-template-expression-rule';
2
+ import { createLintRule } from '../utils/create-rule';
3
+ import { isStyled } from './is-styled';
4
+ const rule = createLintRule({
5
+ meta: {
6
+ name: 'no-styled-tagged-template-expression',
7
+ fixable: 'code',
8
+ type: 'problem',
9
+ docs: {
10
+ description: 'Disallows any `styled` tagged template expressions that originate from Emotion, Styled Components or Compiled',
11
+ recommended: false,
12
+ severity: 'error'
13
+ },
14
+ messages: {
15
+ unexpectedTaggedTemplate: 'Unexpected `styled` tagged template expression'
16
+ },
17
+ schema: noTaggedTemplateExpressionRuleSchema
18
+ },
19
+ create: createNoTaggedTemplateExpressionRule(isStyled, 'unexpectedTaggedTemplate')
20
+ });
21
+ export default rule;
@@ -0,0 +1,45 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
+
3
+ import { CSS_IN_JS_IMPORTS } from '../utils/is-supported-import';
4
+ const functionName = 'styled';
5
+ const checkDefinitionHasImport = (def, importSources) => {
6
+ if (def.type !== 'ImportBinding') {
7
+ return false;
8
+ }
9
+ if (!def.parent || !importSources.includes(def.parent.source.value)) {
10
+ return false;
11
+ }
12
+
13
+ // `@compiled/react` only exposes styled as a named export
14
+ if (importSources.includes(CSS_IN_JS_IMPORTS.compiled) && def.parent.source.value === CSS_IN_JS_IMPORTS.compiled) {
15
+ return def.node.type === 'ImportSpecifier' && def.node.imported.name === functionName;
16
+ }
17
+
18
+ // `@emotion/styled` only exposes styled as a default export
19
+ if (importSources.includes(CSS_IN_JS_IMPORTS.emotionStyled) && def.parent.source.value === CSS_IN_JS_IMPORTS.emotionStyled) {
20
+ return def.node.type === 'ImportDefaultSpecifier';
21
+ }
22
+
23
+ // `styled-components` only exposes styled as a default export
24
+ if (importSources.includes(CSS_IN_JS_IMPORTS.styledComponents) && def.parent.source.value === CSS_IN_JS_IMPORTS.styledComponents) {
25
+ return def.node.type === 'ImportDefaultSpecifier';
26
+ }
27
+ return false;
28
+ };
29
+ export const isStyled = (nodeToCheck, referencesInScope, importSources) => {
30
+ let nodeIdentifier = null;
31
+
32
+ // Handles styled.div`` case
33
+ if (nodeToCheck.type === 'MemberExpression' && nodeToCheck.object.type === 'Identifier') {
34
+ nodeIdentifier = nodeToCheck.object;
35
+ }
36
+
37
+ // Handles styled(Base)`` case
38
+ if (nodeToCheck.type === 'CallExpression' && nodeToCheck.callee.type === 'Identifier') {
39
+ nodeIdentifier = nodeToCheck.callee;
40
+ }
41
+ return referencesInScope.some(reference => {
42
+ var _reference$resolved;
43
+ return reference.identifier === nodeIdentifier && ((_reference$resolved = reference.resolved) === null || _reference$resolved === void 0 ? void 0 : _reference$resolved.defs.some(def => checkDefinitionHasImport(def, importSources)));
44
+ });
45
+ };
@@ -0,0 +1,84 @@
1
+ // Original source from Compiled https://github.com/atlassian-labs/compiled/blob/master/packages/eslint-plugin/src/utils/create-no-tagged-template-expression-rule/index.ts
2
+ // eslint-disable-next-line import/no-extraneous-dependencies
3
+
4
+ import { getImportSources } from '../is-supported-import';
5
+ import { generate } from './generate';
6
+ import { getTaggedTemplateExpressionOffset } from './get-tagged-template-expression-offset';
7
+ import { toArguments } from './to-arguments';
8
+ export const noTaggedTemplateExpressionRuleSchema = [{
9
+ type: 'object',
10
+ properties: {
11
+ importSources: {
12
+ type: 'array',
13
+ items: {
14
+ type: 'string'
15
+ },
16
+ uniqueItems: true
17
+ }
18
+ }
19
+ }];
20
+
21
+ /**
22
+ * When true, template strings containing multiline comments are completely skipped over.
23
+ *
24
+ * When false, multiline comments are stripped out. Ideally we would preserve them,
25
+ * but it would add a lot of complexity.
26
+ */
27
+ const shouldSkipMultilineComments = false;
28
+ export const createNoTaggedTemplateExpressionRule = (isUsage, messageId) => context => {
29
+ const importSources = getImportSources(context);
30
+ return {
31
+ TaggedTemplateExpression(node) {
32
+ const {
33
+ references
34
+ } = context.getScope();
35
+ if (!isUsage(node.tag, references, importSources)) {
36
+ return;
37
+ }
38
+ context.report({
39
+ messageId,
40
+ node,
41
+ *fix(fixer) {
42
+ const {
43
+ quasi
44
+ } = node;
45
+ const source = context.getSourceCode();
46
+
47
+ // TODO Eventually handle comments instead of skipping them
48
+ // Skip auto-fixing comments
49
+ if (shouldSkipMultilineComments && quasi.quasis.map(q => q.value.raw).join('').match(/\/\*[\s\S]*\*\//g)) {
50
+ return;
51
+ }
52
+
53
+ // Replace empty tagged template expression with the equivalent object call expression
54
+ if (!quasi.expressions.length && quasi.quasis.length === 1 && !quasi.quasis[0].value.raw.trim()) {
55
+ yield fixer.replaceText(quasi, '({})');
56
+ return;
57
+ }
58
+ const args = toArguments(source, quasi);
59
+
60
+ // Skip invalid CSS
61
+ if (args.length < 1) {
62
+ return;
63
+ }
64
+ const oldCode = source.getText(node);
65
+ // Remove quasi:
66
+ // styled.div<Props>`
67
+ // color: red;
68
+ // `
69
+ // becomes
70
+ // styled.div<Props>
71
+ const withoutQuasi = oldCode.replace(source.getText(quasi), '');
72
+ const newCode = withoutQuasi +
73
+ // Indent the arguments after the tagged template expression range
74
+ generate(args, getTaggedTemplateExpressionOffset(node));
75
+ if (oldCode === newCode) {
76
+ return;
77
+ }
78
+ yield fixer.insertTextBefore(node, newCode);
79
+ yield fixer.remove(node);
80
+ }
81
+ });
82
+ }
83
+ };
84
+ };