@atlaskit/eslint-plugin-ui-styling-standard 0.21.0 → 1.0.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 (31) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +2 -5
  3. package/dist/cjs/presets/all-flat.codegen.js +2 -11
  4. package/dist/cjs/presets/all.codegen.js +2 -9
  5. package/dist/cjs/presets/recommended-flat.codegen.js +2 -11
  6. package/dist/cjs/presets/recommended.codegen.js +2 -9
  7. package/dist/cjs/rules/enforce-style-prop/index.js +45 -17
  8. package/dist/cjs/rules/external-rules.js +0 -38
  9. package/dist/es2019/presets/all-flat.codegen.js +2 -11
  10. package/dist/es2019/presets/all.codegen.js +2 -9
  11. package/dist/es2019/presets/recommended-flat.codegen.js +2 -11
  12. package/dist/es2019/presets/recommended.codegen.js +2 -9
  13. package/dist/es2019/rules/enforce-style-prop/index.js +45 -17
  14. package/dist/es2019/rules/external-rules.js +0 -38
  15. package/dist/esm/presets/all-flat.codegen.js +2 -11
  16. package/dist/esm/presets/all.codegen.js +2 -9
  17. package/dist/esm/presets/recommended-flat.codegen.js +2 -11
  18. package/dist/esm/presets/recommended.codegen.js +2 -9
  19. package/dist/esm/rules/enforce-style-prop/index.js +45 -17
  20. package/dist/esm/rules/external-rules.js +0 -38
  21. package/dist/types/index.codegen.d.ts +4 -64
  22. package/dist/types/presets/all-flat.codegen.d.ts +1 -10
  23. package/dist/types/presets/all.codegen.d.ts +2 -9
  24. package/dist/types/presets/recommended-flat.codegen.d.ts +1 -10
  25. package/dist/types/presets/recommended.codegen.d.ts +2 -9
  26. package/dist/types-ts4.5/index.codegen.d.ts +4 -108
  27. package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +1 -15
  28. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -15
  29. package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +1 -15
  30. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -15
  31. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#162439](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/162439)
8
+ [`d4e7809eb2373`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d4e7809eb2373) -
9
+ Remove Compiled rules from plugin, please use @compiled/eslint-plugin directly
10
+
11
+ ### Patch Changes
12
+
13
+ - [#157624](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/157624)
14
+ [`1734bd61b5d9e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/1734bd61b5d9e) -
15
+ Fix enforce-style-prop from erroring on type assertion, eg. '{…} as React.CSSProperties' which is
16
+ a common pattern
17
+
3
18
  ## 0.21.0
4
19
 
5
20
  ### Minor Changes
package/README.md CHANGED
@@ -20,8 +20,8 @@ module.exports = {
20
20
  ```
21
21
 
22
22
  We don't recommended maintaining your own configuration. If you do not use our config you will need
23
- to specify individual rules and configuration. Add the plugin to your `.eslintrc.js` file and enable
24
- individual rules as you're ready to adopt.
23
+ to specify individual rules and configuration. Add the plugin to your `eslint.config.cjs` file and
24
+ enable individual rules as you're ready to adopt.
25
25
 
26
26
  ```diff
27
27
  module.exports = {
@@ -63,10 +63,7 @@ module.exports = {
63
63
  | <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 | |
64
64
  | <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 | |
65
65
  | <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-styled-tagged-template-expression/usage">@atlaskit/design-system/no-styled-tagged-template-expression</a> | Disallows any `styled` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
66
- | <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-suppress-xcss/usage">@compiled/no-suppress-xcss</a> | Disallows supressing type violations when using the xcss prop. | Yes | | |
67
- | <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-js-xcss/usage">@compiled/no-js-xcss</a> | Disallows using xcss prop inside JavaScript files. | Yes | | |
68
66
  | <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-empty-styled-expression/usage">@atlaskit/design-system/no-empty-styled-expression</a> | Forbids any styled expression to be used when passing empty arguments to styled.div() (or other JSX elements). | Yes | | |
69
67
  | <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-invalid-css-map/usage">@atlaskit/design-system/no-invalid-css-map</a> | Checks the validity of a CSS map created through cssMap. This is intended to be used alongside TypeScript's type-checking. | Yes | | |
70
- | <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/jsx-pragma/usage">@compiled/jsx-pragma</a> | Ensures that the Compiled JSX pragma is set when using Compiled | Yes | | |
71
68
 
72
69
  <!-- END_RULE_TABLE_CODEGEN -->
@@ -6,19 +6,17 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var atlaskitDesignSystemPlugin = _interopRequireWildcard(require("@atlaskit/eslint-plugin-design-system"));
9
- var compiledPlugin = _interopRequireWildcard(require("@compiled/eslint-plugin"));
10
9
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
11
10
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
11
  /**
13
12
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
14
- * @codegen <<SignedSource::1cccef68eb9733d840f31dd863aad5ab>>
13
+ * @codegen <<SignedSource::4595bc1a07f9da4186e2df84cea56831>>
15
14
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
16
15
  */
17
16
  var _default = exports.default = {
18
17
  plugins: {
19
18
  // NOTE: The reference to this plugin is inserted dynamically while creating the plugin in `index.codegen.tsx`
20
- '@atlaskit/design-system': atlaskitDesignSystemPlugin,
21
- '@compiled': compiledPlugin
19
+ '@atlaskit/design-system': atlaskitDesignSystemPlugin
22
20
  },
23
21
  rules: {
24
22
  '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
@@ -45,18 +43,11 @@ var _default = exports.default = {
45
43
  '@atlaskit/design-system/no-css-tagged-template-expression': 'error',
46
44
  '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'error',
47
45
  '@atlaskit/design-system/no-styled-tagged-template-expression': 'error',
48
- '@compiled/no-suppress-xcss': 'error',
49
- '@compiled/no-js-xcss': 'error',
50
46
  '@atlaskit/design-system/no-empty-styled-expression': ['error', {
51
47
  importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components']
52
48
  }],
53
49
  '@atlaskit/design-system/no-invalid-css-map': ['error', {
54
50
  allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
55
- }],
56
- '@compiled/jsx-pragma': ['error', {
57
- runtime: 'classic',
58
- onlyRunIfImportingCompiled: true,
59
- importSources: ['@atlaskit/css']
60
51
  }]
61
52
  }
62
53
  };
@@ -6,11 +6,11 @@ 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::3488c902f0db00c9b39ff91abeff0c91>>
9
+ * @codegen <<SignedSource::884e28457d7860b1abca070fca8ab853>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
  var _default = exports.default = {
13
- plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
13
+ plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system'],
14
14
  rules: {
15
15
  '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
16
16
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
@@ -36,18 +36,11 @@ var _default = exports.default = {
36
36
  '@atlaskit/design-system/no-css-tagged-template-expression': 'error',
37
37
  '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'error',
38
38
  '@atlaskit/design-system/no-styled-tagged-template-expression': 'error',
39
- '@compiled/no-suppress-xcss': 'error',
40
- '@compiled/no-js-xcss': 'error',
41
39
  '@atlaskit/design-system/no-empty-styled-expression': ['error', {
42
40
  importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components']
43
41
  }],
44
42
  '@atlaskit/design-system/no-invalid-css-map': ['error', {
45
43
  allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
46
- }],
47
- '@compiled/jsx-pragma': ['error', {
48
- runtime: 'classic',
49
- onlyRunIfImportingCompiled: true,
50
- importSources: ['@atlaskit/css']
51
44
  }]
52
45
  }
53
46
  };
@@ -6,19 +6,17 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var atlaskitDesignSystemPlugin = _interopRequireWildcard(require("@atlaskit/eslint-plugin-design-system"));
9
- var compiledPlugin = _interopRequireWildcard(require("@compiled/eslint-plugin"));
10
9
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
11
10
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
11
  /**
13
12
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
14
- * @codegen <<SignedSource::1cccef68eb9733d840f31dd863aad5ab>>
13
+ * @codegen <<SignedSource::4595bc1a07f9da4186e2df84cea56831>>
15
14
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
16
15
  */
17
16
  var _default = exports.default = {
18
17
  plugins: {
19
18
  // NOTE: The reference to this plugin is inserted dynamically while creating the plugin in `index.codegen.tsx`
20
- '@atlaskit/design-system': atlaskitDesignSystemPlugin,
21
- '@compiled': compiledPlugin
19
+ '@atlaskit/design-system': atlaskitDesignSystemPlugin
22
20
  },
23
21
  rules: {
24
22
  '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
@@ -45,18 +43,11 @@ var _default = exports.default = {
45
43
  '@atlaskit/design-system/no-css-tagged-template-expression': 'error',
46
44
  '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'error',
47
45
  '@atlaskit/design-system/no-styled-tagged-template-expression': 'error',
48
- '@compiled/no-suppress-xcss': 'error',
49
- '@compiled/no-js-xcss': 'error',
50
46
  '@atlaskit/design-system/no-empty-styled-expression': ['error', {
51
47
  importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components']
52
48
  }],
53
49
  '@atlaskit/design-system/no-invalid-css-map': ['error', {
54
50
  allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
55
- }],
56
- '@compiled/jsx-pragma': ['error', {
57
- runtime: 'classic',
58
- onlyRunIfImportingCompiled: true,
59
- importSources: ['@atlaskit/css']
60
51
  }]
61
52
  }
62
53
  };
@@ -6,11 +6,11 @@ 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::3488c902f0db00c9b39ff91abeff0c91>>
9
+ * @codegen <<SignedSource::884e28457d7860b1abca070fca8ab853>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
  var _default = exports.default = {
13
- plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
13
+ plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system'],
14
14
  rules: {
15
15
  '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
16
16
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
@@ -36,18 +36,11 @@ var _default = exports.default = {
36
36
  '@atlaskit/design-system/no-css-tagged-template-expression': 'error',
37
37
  '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'error',
38
38
  '@atlaskit/design-system/no-styled-tagged-template-expression': 'error',
39
- '@compiled/no-suppress-xcss': 'error',
40
- '@compiled/no-js-xcss': 'error',
41
39
  '@atlaskit/design-system/no-empty-styled-expression': ['error', {
42
40
  importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components']
43
41
  }],
44
42
  '@atlaskit/design-system/no-invalid-css-map': ['error', {
45
43
  allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
46
- }],
47
- '@compiled/jsx-pragma': ['error', {
48
- runtime: 'classic',
49
- onlyRunIfImportingCompiled: true,
50
- importSources: ['@atlaskit/css']
51
44
  }]
52
45
  }
53
46
  };
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.rule = exports.default = void 0;
7
7
  var _eslintCodemodUtils = require("eslint-codemod-utils");
8
- var _createRule = require("../utils/create-rule");
9
8
  var _allowedFunctionCalls = require("@atlaskit/eslint-utils/allowed-function-calls");
10
9
  var _findVariable3 = require("@atlaskit/eslint-utils/find-variable");
10
+ var _createRule = require("../utils/create-rule");
11
11
  var isParameter = function isParameter(context, identifier) {
12
12
  var _findVariable;
13
13
  var definitions = (_findVariable = (0, _findVariable3.findVariable)({
@@ -21,7 +21,7 @@ var isParameter = function isParameter(context, identifier) {
21
21
  return result.type === 'Parameter';
22
22
  };
23
23
  var isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
24
- var _parent;
24
+ var _variable$identifiers;
25
25
  var variable = (0, _findVariable3.findVariable)({
26
26
  sourceCode: context.getSourceCode(),
27
27
  identifier: identifier
@@ -31,30 +31,44 @@ var isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
31
31
  }
32
32
  var variableDefinition = variable.defs[0].node;
33
33
 
34
+ // console.log('@@variableDefinition', variableDefinition);
35
+
34
36
  // If identifier is a RestElement, report warning
35
- if (((_parent = variable.identifiers[0].parent) === null || _parent === void 0 ? void 0 : _parent.type) === 'RestElement') {
37
+ if (((_variable$identifiers = variable.identifiers[0]) === null || _variable$identifiers === void 0 || (_variable$identifiers = _variable$identifiers.parent) === null || _variable$identifiers === void 0 ? void 0 : _variable$identifiers.type) === 'RestElement') {
36
38
  return false;
37
39
  }
38
40
 
39
41
  // Checking if identifier has been destructured from props within function
40
42
  if (variableDefinition.type === 'VariableDeclarator') {
41
- var _variableDefinition$i, _variableDefinition$i2;
43
+ var _init, _init2, _init3, _init4;
42
44
  // If it's a let variable, ignore
43
45
  if (variableDefinition.parent.kind === 'let') {
44
46
  return true;
45
47
  }
48
+
49
+ // Allow for `const { width } = props as Props` (etc)
50
+ var init = variableDefinition.init;
51
+ if (((_init = init) === null || _init === void 0 ? void 0 : _init.type) === 'TSAsExpression') {
52
+ init = init.expression;
53
+ }
54
+
46
55
  // If it's initialised by a call expression, ignore
47
- if (((_variableDefinition$i = variableDefinition.init) === null || _variableDefinition$i === void 0 ? void 0 : _variableDefinition$i.type) === 'CallExpression') {
56
+ if (((_init2 = init) === null || _init2 === void 0 ? void 0 : _init2.type) === 'CallExpression') {
48
57
  return true;
49
58
  }
50
59
  // Destructured from member expression
51
60
  // e.g. const width = props.width
52
- if (((_variableDefinition$i2 = variableDefinition.init) === null || _variableDefinition$i2 === void 0 ? void 0 : _variableDefinition$i2.type) === 'MemberExpression') {
53
- return isParameter(context, variableDefinition.init.object);
61
+ if (((_init3 = init) === null || _init3 === void 0 ? void 0 : _init3.type) === 'MemberExpression') {
62
+ return isParameter(context, init.object);
63
+ }
64
+ // Destructured from an asserted
65
+ // e.g. const width = props.width
66
+ if (((_init4 = init) === null || _init4 === void 0 ? void 0 : _init4.type) === 'MemberExpression') {
67
+ return isParameter(context, init.object);
54
68
  }
55
69
  // Destructured from object pattern
56
70
  // e.g. const { width } = props
57
- return isParameter(context, variableDefinition.init);
71
+ return isParameter(context, init);
58
72
  }
59
73
  // If identifier has not been deconstructed from parameter or is a RestElement, report warning
60
74
  return isParameter(context, identifier);
@@ -127,26 +141,40 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
127
141
  create: function create(context) {
128
142
  return {
129
143
  'JSXAttribute[name.name="style"] > JSXExpressionContainer': function JSXAttributeNameNameStyleJSXExpressionContainer(node) {
144
+ var _node$expression$expr;
130
145
  if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXExpressionContainer')) {
131
146
  return;
132
147
  }
148
+
133
149
  // we've reached an attribute named style
134
150
 
135
- if (node.expression.type === 'ObjectExpression') {
136
- node.expression.properties.forEach(function (value) {
137
- if (!isPropertyValueAllowed(value, context)) {
138
- context.report({
139
- node: value,
140
- messageId: 'enforce-style-prop'
141
- });
142
- }
143
- });
151
+ var expression;
152
+ if (
153
+ // @ts-expect-error -- TSAsExpression is not valid in estree
154
+ node.expression.type === 'TSAsExpression' &&
155
+ // @ts-expect-error -- TSAsExpression is not valid in estree
156
+ ((_node$expression$expr = node.expression.expression) === null || _node$expression$expr === void 0 ? void 0 : _node$expression$expr.type) === 'ObjectExpression') {
157
+ // This is a `style={{ … } as React.CSSProperties}` scenario
158
+ // @ts-expect-error -- TSAsExpression is not valid in estree
159
+ expression = node.expression.expression;
160
+ } else if (node.expression.type === 'ObjectExpression') {
161
+ // Typical `style={{ … }}` scenario
162
+ expression = node.expression;
144
163
  } else {
145
164
  context.report({
146
165
  node: node,
147
166
  messageId: 'enforce-style-prop'
148
167
  });
168
+ return;
149
169
  }
170
+ expression.properties.forEach(function (value) {
171
+ if (!isPropertyValueAllowed(value, context)) {
172
+ context.report({
173
+ node: value,
174
+ messageId: 'enforce-style-prop'
175
+ });
176
+ }
177
+ });
150
178
  }
151
179
  };
152
180
  }
@@ -66,28 +66,6 @@ var externalRules = exports.externalRules = [{
66
66
  recommended: true,
67
67
  severity: 'error'
68
68
  }
69
- }, {
70
- name: '@compiled/no-suppress-xcss',
71
- displayName: 'no-suppress-xcss',
72
- isExternal: true,
73
- docs: {
74
- description: 'Disallows supressing type violations when using the xcss prop.',
75
- url: (0, _createRule.getRuleUrl)('no-suppress-xcss'),
76
- externalUrl: 'https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/no-suppress-xcss',
77
- recommended: true,
78
- severity: 'error'
79
- }
80
- }, {
81
- name: '@compiled/no-js-xcss',
82
- displayName: 'no-js-xcss',
83
- isExternal: true,
84
- docs: {
85
- description: 'Disallows using xcss prop inside JavaScript files.',
86
- url: (0, _createRule.getRuleUrl)('no-js-xcss'),
87
- externalUrl: 'https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/no-js-xcss',
88
- recommended: true,
89
- severity: 'error'
90
- }
91
69
  }, {
92
70
  name: '@atlaskit/design-system/no-empty-styled-expression',
93
71
  displayName: 'no-empty-styled-expression',
@@ -116,20 +94,4 @@ var externalRules = exports.externalRules = [{
116
94
  allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
117
95
  }
118
96
  }
119
- }, {
120
- name: '@compiled/jsx-pragma',
121
- displayName: 'jsx-pragma',
122
- isExternal: true,
123
- docs: {
124
- description: 'Ensures that the Compiled JSX pragma is set when using Compiled',
125
- url: (0, _createRule.getRuleUrl)('jsx-pragma'),
126
- externalUrl: 'https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/jsx-pragma',
127
- recommended: true,
128
- severity: 'error',
129
- pluginConfig: {
130
- runtime: 'classic',
131
- onlyRunIfImportingCompiled: true,
132
- importSources: ['@atlaskit/css']
133
- }
134
- }
135
97
  }];
@@ -1,15 +1,13 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::1cccef68eb9733d840f31dd863aad5ab>>
3
+ * @codegen <<SignedSource::4595bc1a07f9da4186e2df84cea56831>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import * as atlaskitDesignSystemPlugin from '@atlaskit/eslint-plugin-design-system';
7
- import * as compiledPlugin from '@compiled/eslint-plugin';
8
7
  export default {
9
8
  plugins: {
10
9
  // NOTE: The reference to this plugin is inserted dynamically while creating the plugin in `index.codegen.tsx`
11
- '@atlaskit/design-system': atlaskitDesignSystemPlugin,
12
- '@compiled': compiledPlugin
10
+ '@atlaskit/design-system': atlaskitDesignSystemPlugin
13
11
  },
14
12
  rules: {
15
13
  '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
@@ -36,18 +34,11 @@ export default {
36
34
  '@atlaskit/design-system/no-css-tagged-template-expression': 'error',
37
35
  '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'error',
38
36
  '@atlaskit/design-system/no-styled-tagged-template-expression': 'error',
39
- '@compiled/no-suppress-xcss': 'error',
40
- '@compiled/no-js-xcss': 'error',
41
37
  '@atlaskit/design-system/no-empty-styled-expression': ['error', {
42
38
  importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components']
43
39
  }],
44
40
  '@atlaskit/design-system/no-invalid-css-map': ['error', {
45
41
  allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
46
- }],
47
- '@compiled/jsx-pragma': ['error', {
48
- runtime: 'classic',
49
- onlyRunIfImportingCompiled: true,
50
- importSources: ['@atlaskit/css']
51
42
  }]
52
43
  }
53
44
  };
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::3488c902f0db00c9b39ff91abeff0c91>>
3
+ * @codegen <<SignedSource::884e28457d7860b1abca070fca8ab853>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
7
- plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
7
+ plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system'],
8
8
  rules: {
9
9
  '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
10
10
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
@@ -30,18 +30,11 @@ export default {
30
30
  '@atlaskit/design-system/no-css-tagged-template-expression': 'error',
31
31
  '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'error',
32
32
  '@atlaskit/design-system/no-styled-tagged-template-expression': 'error',
33
- '@compiled/no-suppress-xcss': 'error',
34
- '@compiled/no-js-xcss': 'error',
35
33
  '@atlaskit/design-system/no-empty-styled-expression': ['error', {
36
34
  importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components']
37
35
  }],
38
36
  '@atlaskit/design-system/no-invalid-css-map': ['error', {
39
37
  allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
40
- }],
41
- '@compiled/jsx-pragma': ['error', {
42
- runtime: 'classic',
43
- onlyRunIfImportingCompiled: true,
44
- importSources: ['@atlaskit/css']
45
38
  }]
46
39
  }
47
40
  };
@@ -1,15 +1,13 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::1cccef68eb9733d840f31dd863aad5ab>>
3
+ * @codegen <<SignedSource::4595bc1a07f9da4186e2df84cea56831>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import * as atlaskitDesignSystemPlugin from '@atlaskit/eslint-plugin-design-system';
7
- import * as compiledPlugin from '@compiled/eslint-plugin';
8
7
  export default {
9
8
  plugins: {
10
9
  // NOTE: The reference to this plugin is inserted dynamically while creating the plugin in `index.codegen.tsx`
11
- '@atlaskit/design-system': atlaskitDesignSystemPlugin,
12
- '@compiled': compiledPlugin
10
+ '@atlaskit/design-system': atlaskitDesignSystemPlugin
13
11
  },
14
12
  rules: {
15
13
  '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
@@ -36,18 +34,11 @@ export default {
36
34
  '@atlaskit/design-system/no-css-tagged-template-expression': 'error',
37
35
  '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'error',
38
36
  '@atlaskit/design-system/no-styled-tagged-template-expression': 'error',
39
- '@compiled/no-suppress-xcss': 'error',
40
- '@compiled/no-js-xcss': 'error',
41
37
  '@atlaskit/design-system/no-empty-styled-expression': ['error', {
42
38
  importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components']
43
39
  }],
44
40
  '@atlaskit/design-system/no-invalid-css-map': ['error', {
45
41
  allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
46
- }],
47
- '@compiled/jsx-pragma': ['error', {
48
- runtime: 'classic',
49
- onlyRunIfImportingCompiled: true,
50
- importSources: ['@atlaskit/css']
51
42
  }]
52
43
  }
53
44
  };
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::3488c902f0db00c9b39ff91abeff0c91>>
3
+ * @codegen <<SignedSource::884e28457d7860b1abca070fca8ab853>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
7
- plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
7
+ plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system'],
8
8
  rules: {
9
9
  '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
10
10
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
@@ -30,18 +30,11 @@ export default {
30
30
  '@atlaskit/design-system/no-css-tagged-template-expression': 'error',
31
31
  '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'error',
32
32
  '@atlaskit/design-system/no-styled-tagged-template-expression': 'error',
33
- '@compiled/no-suppress-xcss': 'error',
34
- '@compiled/no-js-xcss': 'error',
35
33
  '@atlaskit/design-system/no-empty-styled-expression': ['error', {
36
34
  importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components']
37
35
  }],
38
36
  '@atlaskit/design-system/no-invalid-css-map': ['error', {
39
37
  allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
40
- }],
41
- '@compiled/jsx-pragma': ['error', {
42
- runtime: 'classic',
43
- onlyRunIfImportingCompiled: true,
44
- importSources: ['@atlaskit/css']
45
38
  }]
46
39
  }
47
40
  };
@@ -1,7 +1,7 @@
1
1
  import { isNodeOfType } from 'eslint-codemod-utils';
2
- import { createLintRule } from '../utils/create-rule';
3
2
  import { getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
4
3
  import { findVariable } from '@atlaskit/eslint-utils/find-variable';
4
+ import { createLintRule } from '../utils/create-rule';
5
5
  const isParameter = (context, identifier) => {
6
6
  var _findVariable;
7
7
  const definitions = (_findVariable = findVariable({
@@ -15,7 +15,7 @@ const isParameter = (context, identifier) => {
15
15
  return result.type === 'Parameter';
16
16
  };
17
17
  const isIdentifierAllowed = (context, identifier) => {
18
- var _parent;
18
+ var _variable$identifiers, _variable$identifiers2;
19
19
  const variable = findVariable({
20
20
  sourceCode: context.getSourceCode(),
21
21
  identifier: identifier
@@ -25,30 +25,44 @@ const isIdentifierAllowed = (context, identifier) => {
25
25
  }
26
26
  const variableDefinition = variable.defs[0].node;
27
27
 
28
+ // console.log('@@variableDefinition', variableDefinition);
29
+
28
30
  // If identifier is a RestElement, report warning
29
- if (((_parent = variable.identifiers[0].parent) === null || _parent === void 0 ? void 0 : _parent.type) === 'RestElement') {
31
+ if (((_variable$identifiers = variable.identifiers[0]) === null || _variable$identifiers === void 0 ? void 0 : (_variable$identifiers2 = _variable$identifiers.parent) === null || _variable$identifiers2 === void 0 ? void 0 : _variable$identifiers2.type) === 'RestElement') {
30
32
  return false;
31
33
  }
32
34
 
33
35
  // Checking if identifier has been destructured from props within function
34
36
  if (variableDefinition.type === 'VariableDeclarator') {
35
- var _variableDefinition$i, _variableDefinition$i2;
37
+ var _init, _init2, _init3, _init4;
36
38
  // If it's a let variable, ignore
37
39
  if (variableDefinition.parent.kind === 'let') {
38
40
  return true;
39
41
  }
42
+
43
+ // Allow for `const { width } = props as Props` (etc)
44
+ let init = variableDefinition.init;
45
+ if (((_init = init) === null || _init === void 0 ? void 0 : _init.type) === 'TSAsExpression') {
46
+ init = init.expression;
47
+ }
48
+
40
49
  // If it's initialised by a call expression, ignore
41
- if (((_variableDefinition$i = variableDefinition.init) === null || _variableDefinition$i === void 0 ? void 0 : _variableDefinition$i.type) === 'CallExpression') {
50
+ if (((_init2 = init) === null || _init2 === void 0 ? void 0 : _init2.type) === 'CallExpression') {
42
51
  return true;
43
52
  }
44
53
  // Destructured from member expression
45
54
  // e.g. const width = props.width
46
- if (((_variableDefinition$i2 = variableDefinition.init) === null || _variableDefinition$i2 === void 0 ? void 0 : _variableDefinition$i2.type) === 'MemberExpression') {
47
- return isParameter(context, variableDefinition.init.object);
55
+ if (((_init3 = init) === null || _init3 === void 0 ? void 0 : _init3.type) === 'MemberExpression') {
56
+ return isParameter(context, init.object);
57
+ }
58
+ // Destructured from an asserted
59
+ // e.g. const width = props.width
60
+ if (((_init4 = init) === null || _init4 === void 0 ? void 0 : _init4.type) === 'MemberExpression') {
61
+ return isParameter(context, init.object);
48
62
  }
49
63
  // Destructured from object pattern
50
64
  // e.g. const { width } = props
51
- return isParameter(context, variableDefinition.init);
65
+ return isParameter(context, init);
52
66
  }
53
67
  // If identifier has not been deconstructed from parameter or is a RestElement, report warning
54
68
  return isParameter(context, identifier);
@@ -121,26 +135,40 @@ export const rule = createLintRule({
121
135
  create(context) {
122
136
  return {
123
137
  'JSXAttribute[name.name="style"] > JSXExpressionContainer': node => {
138
+ var _node$expression$expr;
124
139
  if (!isNodeOfType(node, 'JSXExpressionContainer')) {
125
140
  return;
126
141
  }
142
+
127
143
  // we've reached an attribute named style
128
144
 
129
- if (node.expression.type === 'ObjectExpression') {
130
- node.expression.properties.forEach(value => {
131
- if (!isPropertyValueAllowed(value, context)) {
132
- context.report({
133
- node: value,
134
- messageId: 'enforce-style-prop'
135
- });
136
- }
137
- });
145
+ let expression;
146
+ if (
147
+ // @ts-expect-error -- TSAsExpression is not valid in estree
148
+ node.expression.type === 'TSAsExpression' &&
149
+ // @ts-expect-error -- TSAsExpression is not valid in estree
150
+ ((_node$expression$expr = node.expression.expression) === null || _node$expression$expr === void 0 ? void 0 : _node$expression$expr.type) === 'ObjectExpression') {
151
+ // This is a `style={{ … } as React.CSSProperties}` scenario
152
+ // @ts-expect-error -- TSAsExpression is not valid in estree
153
+ expression = node.expression.expression;
154
+ } else if (node.expression.type === 'ObjectExpression') {
155
+ // Typical `style={{ … }}` scenario
156
+ expression = node.expression;
138
157
  } else {
139
158
  context.report({
140
159
  node: node,
141
160
  messageId: 'enforce-style-prop'
142
161
  });
162
+ return;
143
163
  }
164
+ expression.properties.forEach(value => {
165
+ if (!isPropertyValueAllowed(value, context)) {
166
+ context.report({
167
+ node: value,
168
+ messageId: 'enforce-style-prop'
169
+ });
170
+ }
171
+ });
144
172
  }
145
173
  };
146
174
  }