@atlaskit/eslint-plugin-ui-styling-standard 3.0.0 → 3.0.2

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 (29) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +19 -19
  3. package/dist/cjs/presets/all-flat.codegen.js +1 -2
  4. package/dist/cjs/presets/all.codegen.js +1 -2
  5. package/dist/cjs/presets/recommended-flat.codegen.js +1 -2
  6. package/dist/cjs/presets/recommended.codegen.js +1 -2
  7. package/dist/cjs/rules/atlaskit-theme/index.js +1 -2
  8. package/dist/cjs/rules/no-important-styles/index.js +35 -9
  9. package/dist/cjs/rules/utils/is-type-wrapper.js +23 -0
  10. package/dist/es2019/presets/all-flat.codegen.js +1 -2
  11. package/dist/es2019/presets/all.codegen.js +1 -2
  12. package/dist/es2019/presets/recommended-flat.codegen.js +1 -2
  13. package/dist/es2019/presets/recommended.codegen.js +1 -2
  14. package/dist/es2019/rules/atlaskit-theme/index.js +1 -2
  15. package/dist/es2019/rules/no-important-styles/index.js +37 -9
  16. package/dist/es2019/rules/utils/is-type-wrapper.js +17 -0
  17. package/dist/esm/presets/all-flat.codegen.js +1 -2
  18. package/dist/esm/presets/all.codegen.js +1 -2
  19. package/dist/esm/presets/recommended-flat.codegen.js +1 -2
  20. package/dist/esm/presets/recommended.codegen.js +1 -2
  21. package/dist/esm/rules/atlaskit-theme/index.js +1 -2
  22. package/dist/esm/rules/no-important-styles/index.js +35 -9
  23. package/dist/esm/rules/utils/is-type-wrapper.js +17 -0
  24. package/dist/types/presets/all-flat.codegen.d.ts +1 -1
  25. package/dist/types/presets/all.codegen.d.ts +1 -1
  26. package/dist/types/presets/recommended-flat.codegen.d.ts +1 -1
  27. package/dist/types/presets/recommended.codegen.d.ts +1 -1
  28. package/dist/types/rules/utils/is-type-wrapper.d.ts +6 -0
  29. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 3.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`8769f20fe2ebd`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8769f20fe2ebd) -
8
+ Disable the legacy `atlaskit-theme` rule in generated presets.
9
+
10
+ ## 3.0.1
11
+
12
+ ### Patch Changes
13
+
14
+ - [`2a6c8a9e812fc`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2a6c8a9e812fc) -
15
+ `no-important-styles` now reports `!important` values wrapped in TypeScript expressions, e.g.
16
+ `color: 'red !important' as const`, and values inside wrapped style objects such as
17
+ `css({…} as const)` or `'&:hover': {…} as const`. Previously these were skipped.
18
+
3
19
  ## 3.0.0
4
20
 
5
21
  ### Major Changes
package/README.md CHANGED
@@ -42,25 +42,25 @@ module.exports = {
42
42
 
43
43
  | Rule | Description | Recommended | Fixable | Suggestions |
44
44
  | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | ------- | ----------- |
45
- | <a href="./src/rules/atlaskit-theme/README.md">atlaskit-theme</a> | Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand | Yes | | |
46
- | <a href="./src/rules/convert-props-syntax/README.md">convert-props-syntax</a> | Convert props syntax that is unsupported by styled-components@<4 or @emotion/styled to props syntax that is supported. This is useful when used in conjunction with `no-styled-tagged-template-expression`, as output from the latter may use props syntax unsupported by those libraries. | Yes | Yes | |
47
- | <a href="./src/rules/enforce-style-prop/README.md">enforce-style-prop</a> | Disallows usage of static styles in the `style` attribute in components | Yes | | |
48
- | <a href="./src/rules/local-cx-xcss/README.md">local-cx-xcss</a> | Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element. | Yes | | |
49
- | <a href="./src/rules/no-array-arguments/README.md">no-array-arguments</a> | Prevents usage of array arguments to style declaration functions | Yes | Yes | |
50
- | <a href="./src/rules/no-atlaskit-theme/README.md">no-atlaskit-theme</a> | Disallow imports from `@atlaskit/theme` | Yes | | |
51
- | <a href="./src/rules/no-classname-prop/README.md">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
52
- | <a href="./src/rules/no-container-queries/README.md">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
53
- | <a href="./src/rules/no-dynamic-styles/README.md">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
54
- | <a href="./src/rules/no-exported-styles/README.md">no-exported-styles</a> | Disallows exports of css, keyframes, styled and xcss | Yes | | |
55
- | <a href="./src/rules/no-global-styles/README.md">no-global-styles</a> | Prevents global styles through CSS-in-JS or CSS module imports | Yes | | |
56
- | <a href="./src/rules/no-important-styles/README.md">no-important-styles</a> | Disallows important style declarations | Yes | | |
57
- | <a href="./src/rules/no-imported-style-values/README.md">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
58
- | <a href="./src/rules/no-nested-selectors/README.md">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
59
- | <a href="./src/rules/no-styled/README.md">no-styled</a> | Disallows usage of the `styled` imports | Yes | | |
60
- | <a href="./src/rules/no-unsafe-selectors/README.md">no-unsafe-selectors</a> | Disallows use of nested styles in `css` functions. | Yes | Yes | Yes |
61
- | <a href="./src/rules/no-unsafe-values/README.md">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
62
- | <a href="./src/rules/no-unused-cssmap-properties/README.md">no-unused-cssmap-properties</a> | Detects unused properties in cssMap style objects that are not exported. Helps maintain clean code by identifying style variants that are defined but never used. | Yes | | |
63
- | <a href="./src/rules/use-compiled/README.md">use-compiled</a> | Ensures usage of `@compiled/react` or `@atlaskit/css` instead of other CSS-in-JS libraries | Yes | Yes | |
45
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/atlaskit-theme/README.md">atlaskit-theme</a> | Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand | | | |
46
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/convert-props-syntax/README.md">convert-props-syntax</a> | Convert props syntax that is unsupported by styled-components@<4 or @emotion/styled to props syntax that is supported. This is useful when used in conjunction with `no-styled-tagged-template-expression`, as output from the latter may use props syntax unsupported by those libraries. | Yes | Yes | |
47
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/enforce-style-prop/README.md">enforce-style-prop</a> | Disallows usage of static styles in the `style` attribute in components | Yes | | |
48
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/local-cx-xcss/README.md">local-cx-xcss</a> | Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element. | Yes | | |
49
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-array-arguments/README.md">no-array-arguments</a> | Prevents usage of array arguments to style declaration functions | Yes | Yes | |
50
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-atlaskit-theme/README.md">no-atlaskit-theme</a> | Disallow imports from `@atlaskit/theme` | Yes | | |
51
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-classname-prop/README.md">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
52
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-container-queries/README.md">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
53
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-dynamic-styles/README.md">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
54
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-exported-styles/README.md">no-exported-styles</a> | Disallows exports of css, keyframes, styled and xcss | Yes | | |
55
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-global-styles/README.md">no-global-styles</a> | Prevents global styles through CSS-in-JS or CSS module imports | Yes | | |
56
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-important-styles/README.md">no-important-styles</a> | Disallows important style declarations | Yes | | |
57
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-imported-style-values/README.md">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
58
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-nested-selectors/README.md">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
59
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-styled/README.md">no-styled</a> | Disallows usage of the `styled` imports | Yes | | |
60
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-unsafe-selectors/README.md">no-unsafe-selectors</a> | Disallows use of nested styles in `css` functions. | Yes | Yes | Yes |
61
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-unsafe-values/README.md">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
62
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-unused-cssmap-properties/README.md">no-unused-cssmap-properties</a> | Detects unused properties in cssMap style objects that are not exported. Helps maintain clean code by identifying style variants that are defined but never used. | Yes | | |
63
+ | <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/use-compiled/README.md">use-compiled</a> | Ensures usage of `@compiled/react` or `@atlaskit/css` instead of other CSS-in-JS libraries | Yes | Yes | |
64
64
  | <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/consistent-css-prop-usage/usage">@atlaskit/design-system/consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
65
65
  | <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-css-tagged-template-expression/usage">@atlaskit/design-system/no-css-tagged-template-expression</a> | Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
66
66
  | <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-keyframes-tagged-template-expression/usage">@atlaskit/design-system/no-keyframes-tagged-template-expression</a> | Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
@@ -9,7 +9,7 @@ var atlaskitDesignSystemPlugin = _interopRequireWildcard(require("@atlaskit/esli
9
9
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
10
10
  /**
11
11
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
12
- * @codegen <<SignedSource::4d0de15d2213df65666693ea490b4cce>>
12
+ * @codegen <<SignedSource::856ecaae15d6d75373055852fa8db5f0>>
13
13
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
14
14
  */
15
15
 
@@ -19,7 +19,6 @@ var config = {
19
19
  '@atlaskit/design-system': atlaskitDesignSystemPlugin
20
20
  },
21
21
  rules: {
22
- '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
23
22
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
24
23
  '@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
25
24
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
@@ -6,14 +6,13 @@ 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::56ecb290562bdf88a8a5b5388a39e5f9>>
9
+ * @codegen <<SignedSource::a0cc99967725d4babf6875fef77b6f62>>
10
10
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
 
13
13
  var config = {
14
14
  plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system'],
15
15
  rules: {
16
- '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
17
16
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
18
17
  '@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
19
18
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
@@ -9,7 +9,7 @@ var atlaskitDesignSystemPlugin = _interopRequireWildcard(require("@atlaskit/esli
9
9
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
10
10
  /**
11
11
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
12
- * @codegen <<SignedSource::4d0de15d2213df65666693ea490b4cce>>
12
+ * @codegen <<SignedSource::856ecaae15d6d75373055852fa8db5f0>>
13
13
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
14
14
  */
15
15
 
@@ -19,7 +19,6 @@ var config = {
19
19
  '@atlaskit/design-system': atlaskitDesignSystemPlugin
20
20
  },
21
21
  rules: {
22
- '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
23
22
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
24
23
  '@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
25
24
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
@@ -6,14 +6,13 @@ 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::56ecb290562bdf88a8a5b5388a39e5f9>>
9
+ * @codegen <<SignedSource::a0cc99967725d4babf6875fef77b6f62>>
10
10
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
 
13
13
  var config = {
14
14
  plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system'],
15
15
  rules: {
16
- '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
17
16
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
18
17
  '@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
19
18
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
@@ -130,8 +130,7 @@ var rule = (0, _createRule.createLintRule)({
130
130
  name: 'atlaskit-theme',
131
131
  docs: {
132
132
  description: 'Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand',
133
- recommended: true,
134
- severity: 'error'
133
+ removeFromPresets: true
135
134
  },
136
135
  messages: {
137
136
  usingTypography: 'Typography does not work with Compiled. Please utilise alternatives like Heading or tokens instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage',
@@ -7,6 +7,7 @@ exports.default = void 0;
7
7
  var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
8
8
  var _schema = require("@atlaskit/eslint-utils/schema");
9
9
  var _createRuleWithTypedConfig = require("../utils/create-rule-with-typed-config");
10
+ var _isTypeWrapper = require("../utils/is-type-wrapper");
10
11
  var _styleCalls = require("../utils/style-calls");
11
12
  var rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
12
13
  meta: {
@@ -77,10 +78,34 @@ function isInSupportedStyleCall(context, value, importSources) {
77
78
  return styleCall.node === call && importSources.includes(styleCall.importSource);
78
79
  }));
79
80
  }
81
+
82
+ /**
83
+ * Step up from `node` past any TypeScript wrappers (`as`, `satisfies`, `<T>`, `!`). Returns the
84
+ * outermost wrapper, which is what the next parent refers to, and that parent.
85
+ */
86
+ function climbTypeWrappers(node) {
87
+ var current = node;
88
+ var parent = current.parent;
89
+ while (parent && (0, _isTypeWrapper.isTypeWrapper)(parent)) {
90
+ current = parent;
91
+ parent = current.parent;
92
+ }
93
+ return {
94
+ node: current,
95
+ parent: parent
96
+ };
97
+ }
98
+
99
+ /**
100
+ * Find the style call a value belongs to, looking through TypeScript wrappers at every level:
101
+ * `color: 'red !important' as const`, `'&:hover': {…} as const` and `css({…} as const)`.
102
+ */
80
103
  function findContainingCall(value) {
81
- var _property, _object;
82
- var property = value.parent;
83
- if (((_property = property) === null || _property === void 0 ? void 0 : _property.type) !== 'Property' || property.value !== value) {
104
+ var _object;
105
+ var _climbTypeWrappers = climbTypeWrappers(value),
106
+ wrappedValue = _climbTypeWrappers.node,
107
+ property = _climbTypeWrappers.parent;
108
+ if ((property === null || property === void 0 ? void 0 : property.type) !== 'Property' || property.value !== wrappedValue) {
84
109
  return null;
85
110
  }
86
111
  var object = property.parent;
@@ -89,20 +114,21 @@ function findContainingCall(value) {
89
114
  }
90
115
  while (object) {
91
116
  var _parent$parent;
92
- var parent = object.parent;
93
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === object) {
117
+ var _climbTypeWrappers2 = climbTypeWrappers(object),
118
+ wrappedObject = _climbTypeWrappers2.node,
119
+ parent = _climbTypeWrappers2.parent;
120
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === wrappedObject) {
94
121
  var _object2;
95
- property = parent;
96
- object = property.parent;
122
+ object = parent.parent;
97
123
  if (((_object2 = object) === null || _object2 === void 0 ? void 0 : _object2.type) !== 'ObjectExpression') {
98
124
  return null;
99
125
  }
100
126
  continue;
101
127
  }
102
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(object)) {
128
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(wrappedObject)) {
103
129
  return parent;
104
130
  }
105
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body === object && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === 'CallExpression' && parent.parent.arguments.includes(parent)) {
131
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body === wrappedObject && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === 'CallExpression' && parent.parent.arguments.includes(parent)) {
106
132
  return parent.parent;
107
133
  }
108
134
  return null;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isTypeWrapper = isTypeWrapper;
7
+ /**
8
+ * TypeScript-only wrappers around an expression that ESTree does not model. None of them change
9
+ * the runtime value, so a rule reading a style key, value or argument should look through them:
10
+ *
11
+ * - `['.foo' satisfies `.${typeof FOO_CLASS}`]: {…}`
12
+ * - `color: 'red !important' as const`
13
+ * - `css({…} as const)`
14
+ * - `<T>{…}` and `value!`
15
+ */
16
+ var TYPE_WRAPPER_TYPES = new Set(['TSAsExpression', 'TSNonNullExpression', 'TSSatisfiesExpression', 'TSTypeAssertion']);
17
+
18
+ /**
19
+ * Whether `node` is a TypeScript wrapper (`as`, `satisfies`, `<T>`, `!`) around an expression.
20
+ */
21
+ function isTypeWrapper(node) {
22
+ return Boolean(node && TYPE_WRAPPER_TYPES.has(node.type));
23
+ }
@@ -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::4d0de15d2213df65666693ea490b4cce>>
3
+ * @codegen <<SignedSource::856ecaae15d6d75373055852fa8db5f0>>
4
4
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
@@ -11,7 +11,6 @@ const config = {
11
11
  '@atlaskit/design-system': atlaskitDesignSystemPlugin
12
12
  },
13
13
  rules: {
14
- '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
15
14
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
16
15
  '@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
17
16
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
@@ -1,13 +1,12 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::56ecb290562bdf88a8a5b5388a39e5f9>>
3
+ * @codegen <<SignedSource::a0cc99967725d4babf6875fef77b6f62>>
4
4
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
7
7
  const config = {
8
8
  plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system'],
9
9
  rules: {
10
- '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
11
10
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
12
11
  '@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
13
12
  '@atlaskit/ui-styling-standard/local-cx-xcss': '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::4d0de15d2213df65666693ea490b4cce>>
3
+ * @codegen <<SignedSource::856ecaae15d6d75373055852fa8db5f0>>
4
4
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
@@ -11,7 +11,6 @@ const config = {
11
11
  '@atlaskit/design-system': atlaskitDesignSystemPlugin
12
12
  },
13
13
  rules: {
14
- '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
15
14
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
16
15
  '@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
17
16
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
@@ -1,13 +1,12 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::56ecb290562bdf88a8a5b5388a39e5f9>>
3
+ * @codegen <<SignedSource::a0cc99967725d4babf6875fef77b6f62>>
4
4
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
7
7
  const config = {
8
8
  plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system'],
9
9
  rules: {
10
- '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
11
10
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
12
11
  '@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
13
12
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
@@ -91,8 +91,7 @@ const rule = createLintRule({
91
91
  name: 'atlaskit-theme',
92
92
  docs: {
93
93
  description: 'Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand',
94
- recommended: true,
95
- severity: 'error'
94
+ removeFromPresets: true
96
95
  },
97
96
  messages: {
98
97
  usingTypography: 'Typography does not work with Compiled. Please utilise alternatives like Heading or tokens instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage',
@@ -1,6 +1,7 @@
1
1
  import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
2
2
  import { importSources } from '@atlaskit/eslint-utils/schema';
3
3
  import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
4
+ import { isTypeWrapper } from '../utils/is-type-wrapper';
4
5
  import { getStyleCalls } from '../utils/style-calls';
5
6
  const rule = createLintRuleWithTypedConfig({
6
7
  meta: {
@@ -72,10 +73,35 @@ function isInSupportedStyleCall(context, value, importSources) {
72
73
  const call = findContainingCall(value);
73
74
  return Boolean(call && getStyleCalls(context).some(styleCall => styleCall.node === call && importSources.includes(styleCall.importSource)));
74
75
  }
76
+
77
+ /**
78
+ * Step up from `node` past any TypeScript wrappers (`as`, `satisfies`, `<T>`, `!`). Returns the
79
+ * outermost wrapper, which is what the next parent refers to, and that parent.
80
+ */
81
+ function climbTypeWrappers(node) {
82
+ let current = node;
83
+ let parent = current.parent;
84
+ while (parent && isTypeWrapper(parent)) {
85
+ current = parent;
86
+ parent = current.parent;
87
+ }
88
+ return {
89
+ node: current,
90
+ parent
91
+ };
92
+ }
93
+
94
+ /**
95
+ * Find the style call a value belongs to, looking through TypeScript wrappers at every level:
96
+ * `color: 'red !important' as const`, `'&:hover': {…} as const` and `css({…} as const)`.
97
+ */
75
98
  function findContainingCall(value) {
76
- var _property, _object;
77
- let property = value.parent;
78
- if (((_property = property) === null || _property === void 0 ? void 0 : _property.type) !== 'Property' || property.value !== value) {
99
+ var _object;
100
+ const {
101
+ node: wrappedValue,
102
+ parent: property
103
+ } = climbTypeWrappers(value);
104
+ if ((property === null || property === void 0 ? void 0 : property.type) !== 'Property' || property.value !== wrappedValue) {
79
105
  return null;
80
106
  }
81
107
  let object = property.parent;
@@ -84,20 +110,22 @@ function findContainingCall(value) {
84
110
  }
85
111
  while (object) {
86
112
  var _parent$parent;
87
- const parent = object.parent;
88
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === object) {
113
+ const {
114
+ node: wrappedObject,
115
+ parent
116
+ } = climbTypeWrappers(object);
117
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === wrappedObject) {
89
118
  var _object2;
90
- property = parent;
91
- object = property.parent;
119
+ object = parent.parent;
92
120
  if (((_object2 = object) === null || _object2 === void 0 ? void 0 : _object2.type) !== 'ObjectExpression') {
93
121
  return null;
94
122
  }
95
123
  continue;
96
124
  }
97
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(object)) {
125
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(wrappedObject)) {
98
126
  return parent;
99
127
  }
100
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body === object && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === 'CallExpression' && parent.parent.arguments.includes(parent)) {
128
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body === wrappedObject && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === 'CallExpression' && parent.parent.arguments.includes(parent)) {
101
129
  return parent.parent;
102
130
  }
103
131
  return null;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * TypeScript-only wrappers around an expression that ESTree does not model. None of them change
3
+ * the runtime value, so a rule reading a style key, value or argument should look through them:
4
+ *
5
+ * - `['.foo' satisfies `.${typeof FOO_CLASS}`]: {…}`
6
+ * - `color: 'red !important' as const`
7
+ * - `css({…} as const)`
8
+ * - `<T>{…}` and `value!`
9
+ */
10
+ const TYPE_WRAPPER_TYPES = new Set(['TSAsExpression', 'TSNonNullExpression', 'TSSatisfiesExpression', 'TSTypeAssertion']);
11
+
12
+ /**
13
+ * Whether `node` is a TypeScript wrapper (`as`, `satisfies`, `<T>`, `!`) around an expression.
14
+ */
15
+ export function isTypeWrapper(node) {
16
+ return Boolean(node && TYPE_WRAPPER_TYPES.has(node.type));
17
+ }
@@ -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::4d0de15d2213df65666693ea490b4cce>>
3
+ * @codegen <<SignedSource::856ecaae15d6d75373055852fa8db5f0>>
4
4
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
@@ -11,7 +11,6 @@ var config = {
11
11
  '@atlaskit/design-system': atlaskitDesignSystemPlugin
12
12
  },
13
13
  rules: {
14
- '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
15
14
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
16
15
  '@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
17
16
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
@@ -1,13 +1,12 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::56ecb290562bdf88a8a5b5388a39e5f9>>
3
+ * @codegen <<SignedSource::a0cc99967725d4babf6875fef77b6f62>>
4
4
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
7
7
  var config = {
8
8
  plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system'],
9
9
  rules: {
10
- '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
11
10
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
12
11
  '@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
13
12
  '@atlaskit/ui-styling-standard/local-cx-xcss': '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::4d0de15d2213df65666693ea490b4cce>>
3
+ * @codegen <<SignedSource::856ecaae15d6d75373055852fa8db5f0>>
4
4
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
@@ -11,7 +11,6 @@ var config = {
11
11
  '@atlaskit/design-system': atlaskitDesignSystemPlugin
12
12
  },
13
13
  rules: {
14
- '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
15
14
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
16
15
  '@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
17
16
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
@@ -1,13 +1,12 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::56ecb290562bdf88a8a5b5388a39e5f9>>
3
+ * @codegen <<SignedSource::a0cc99967725d4babf6875fef77b6f62>>
4
4
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
7
7
  var config = {
8
8
  plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system'],
9
9
  rules: {
10
- '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
11
10
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
12
11
  '@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
13
12
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
@@ -123,8 +123,7 @@ var rule = createLintRule({
123
123
  name: 'atlaskit-theme',
124
124
  docs: {
125
125
  description: 'Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand',
126
- recommended: true,
127
- severity: 'error'
126
+ removeFromPresets: true
128
127
  },
129
128
  messages: {
130
129
  usingTypography: 'Typography does not work with Compiled. Please utilise alternatives like Heading or tokens instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage',
@@ -1,6 +1,7 @@
1
1
  import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
2
2
  import { importSources } from '@atlaskit/eslint-utils/schema';
3
3
  import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
4
+ import { isTypeWrapper } from '../utils/is-type-wrapper';
4
5
  import { getStyleCalls } from '../utils/style-calls';
5
6
  var rule = createLintRuleWithTypedConfig({
6
7
  meta: {
@@ -71,10 +72,34 @@ function isInSupportedStyleCall(context, value, importSources) {
71
72
  return styleCall.node === call && importSources.includes(styleCall.importSource);
72
73
  }));
73
74
  }
75
+
76
+ /**
77
+ * Step up from `node` past any TypeScript wrappers (`as`, `satisfies`, `<T>`, `!`). Returns the
78
+ * outermost wrapper, which is what the next parent refers to, and that parent.
79
+ */
80
+ function climbTypeWrappers(node) {
81
+ var current = node;
82
+ var parent = current.parent;
83
+ while (parent && isTypeWrapper(parent)) {
84
+ current = parent;
85
+ parent = current.parent;
86
+ }
87
+ return {
88
+ node: current,
89
+ parent: parent
90
+ };
91
+ }
92
+
93
+ /**
94
+ * Find the style call a value belongs to, looking through TypeScript wrappers at every level:
95
+ * `color: 'red !important' as const`, `'&:hover': {…} as const` and `css({…} as const)`.
96
+ */
74
97
  function findContainingCall(value) {
75
- var _property, _object;
76
- var property = value.parent;
77
- if (((_property = property) === null || _property === void 0 ? void 0 : _property.type) !== 'Property' || property.value !== value) {
98
+ var _object;
99
+ var _climbTypeWrappers = climbTypeWrappers(value),
100
+ wrappedValue = _climbTypeWrappers.node,
101
+ property = _climbTypeWrappers.parent;
102
+ if ((property === null || property === void 0 ? void 0 : property.type) !== 'Property' || property.value !== wrappedValue) {
78
103
  return null;
79
104
  }
80
105
  var object = property.parent;
@@ -83,20 +108,21 @@ function findContainingCall(value) {
83
108
  }
84
109
  while (object) {
85
110
  var _parent$parent;
86
- var parent = object.parent;
87
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === object) {
111
+ var _climbTypeWrappers2 = climbTypeWrappers(object),
112
+ wrappedObject = _climbTypeWrappers2.node,
113
+ parent = _climbTypeWrappers2.parent;
114
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === wrappedObject) {
88
115
  var _object2;
89
- property = parent;
90
- object = property.parent;
116
+ object = parent.parent;
91
117
  if (((_object2 = object) === null || _object2 === void 0 ? void 0 : _object2.type) !== 'ObjectExpression') {
92
118
  return null;
93
119
  }
94
120
  continue;
95
121
  }
96
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(object)) {
122
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(wrappedObject)) {
97
123
  return parent;
98
124
  }
99
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body === object && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === 'CallExpression' && parent.parent.arguments.includes(parent)) {
125
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body === wrappedObject && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === 'CallExpression' && parent.parent.arguments.includes(parent)) {
100
126
  return parent.parent;
101
127
  }
102
128
  return null;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * TypeScript-only wrappers around an expression that ESTree does not model. None of them change
3
+ * the runtime value, so a rule reading a style key, value or argument should look through them:
4
+ *
5
+ * - `['.foo' satisfies `.${typeof FOO_CLASS}`]: {…}`
6
+ * - `color: 'red !important' as const`
7
+ * - `css({…} as const)`
8
+ * - `<T>{…}` and `value!`
9
+ */
10
+ var TYPE_WRAPPER_TYPES = new Set(['TSAsExpression', 'TSNonNullExpression', 'TSSatisfiesExpression', 'TSTypeAssertion']);
11
+
12
+ /**
13
+ * Whether `node` is a TypeScript wrapper (`as`, `satisfies`, `<T>`, `!`) around an expression.
14
+ */
15
+ export function isTypeWrapper(node) {
16
+ return Boolean(node && TYPE_WRAPPER_TYPES.has(node.type));
17
+ }
@@ -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::4d0de15d2213df65666693ea490b4cce>>
3
+ * @codegen <<SignedSource::856ecaae15d6d75373055852fa8db5f0>>
4
4
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import type { Linter } from 'eslint';
@@ -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::56ecb290562bdf88a8a5b5388a39e5f9>>
3
+ * @codegen <<SignedSource::a0cc99967725d4babf6875fef77b6f62>>
4
4
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import type { ESLint } from 'eslint';
@@ -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::4d0de15d2213df65666693ea490b4cce>>
3
+ * @codegen <<SignedSource::856ecaae15d6d75373055852fa8db5f0>>
4
4
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import type { Linter } from 'eslint';
@@ -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::56ecb290562bdf88a8a5b5388a39e5f9>>
3
+ * @codegen <<SignedSource::a0cc99967725d4babf6875fef77b6f62>>
4
4
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import type { ESLint } from 'eslint';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Whether `node` is a TypeScript wrapper (`as`, `satisfies`, `<T>`, `!`) around an expression.
3
+ */
4
+ export declare function isTypeWrapper(node: {
5
+ type: string;
6
+ } | null | undefined): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-ui-styling-standard",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "author": "Atlassian Pty Ltd",
5
5
  "description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
6
6
  "license": "Apache-2.0",