@atlaskit/eslint-plugin-ui-styling-standard 0.13.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +1 -0
  3. package/constellation/index/overview.mdx +1 -0
  4. package/constellation/no-styled/usage.mdx +89 -0
  5. package/constellation/use-compiled/usage.mdx +2 -2
  6. package/dist/cjs/presets/all.codegen.js +2 -1
  7. package/dist/cjs/presets/recommended.codegen.js +2 -1
  8. package/dist/cjs/rules/index.codegen.js +3 -1
  9. package/dist/cjs/rules/no-important-styles/index.js +11 -17
  10. package/dist/cjs/rules/no-styled/index.js +67 -0
  11. package/dist/cjs/rules/utils/create-rule-with-typed-config.js +60 -0
  12. package/dist/es2019/presets/all.codegen.js +2 -1
  13. package/dist/es2019/presets/recommended.codegen.js +2 -1
  14. package/dist/es2019/rules/index.codegen.js +3 -1
  15. package/dist/es2019/rules/no-important-styles/index.js +13 -18
  16. package/dist/es2019/rules/no-styled/index.js +45 -0
  17. package/dist/es2019/rules/utils/create-rule-with-typed-config.js +53 -0
  18. package/dist/esm/presets/all.codegen.js +2 -1
  19. package/dist/esm/presets/recommended.codegen.js +2 -1
  20. package/dist/esm/rules/index.codegen.js +3 -1
  21. package/dist/esm/rules/no-important-styles/index.js +12 -18
  22. package/dist/esm/rules/no-styled/index.js +61 -0
  23. package/dist/esm/rules/utils/create-rule-with-typed-config.js +53 -0
  24. package/dist/types/index.codegen.d.ts +2 -0
  25. package/dist/types/presets/all.codegen.d.ts +2 -1
  26. package/dist/types/presets/recommended.codegen.d.ts +2 -1
  27. package/dist/types/rules/index.codegen.d.ts +1 -0
  28. package/dist/types/rules/no-styled/index.d.ts +2 -0
  29. package/dist/types/rules/utils/create-rule-with-typed-config.d.ts +18 -0
  30. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  31. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  32. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
  33. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  34. package/dist/types-ts4.5/rules/no-styled/index.d.ts +2 -0
  35. package/dist/types-ts4.5/rules/utils/create-rule-with-typed-config.d.ts +18 -0
  36. package/package.json +3 -2
  37. package/src/presets/all.codegen.tsx +2 -1
  38. package/src/presets/recommended.codegen.tsx +2 -1
  39. package/src/rules/index.codegen.tsx +3 -1
  40. package/src/rules/no-important-styles/__tests__/rule.test.tsx +12 -0
  41. package/src/rules/no-important-styles/index.tsx +11 -24
  42. package/src/rules/no-styled/README.md +82 -0
  43. package/src/rules/no-styled/__tests__/rule.test.tsx +73 -0
  44. package/src/rules/no-styled/index.tsx +52 -0
  45. package/src/rules/utils/create-rule-with-typed-config.tsx +87 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 0.14.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#99639](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/99639)
8
+ [`e9887b5c7698`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e9887b5c7698) -
9
+ Internal refactoring of `no-important-styles` rule
10
+ - Updated dependencies
11
+
12
+ ## 0.14.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#99733](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/99733)
17
+ [`7051e483ab6d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/7051e483ab6d) -
18
+ Added no-styled eslint rule to prevent usage of styled imports
19
+
3
20
  ## 0.13.0
4
21
 
5
22
  ### Minor Changes
package/README.md CHANGED
@@ -55,6 +55,7 @@ module.exports = {
55
55
  | <a href="./src/rules/no-important-styles/README.md">no-important-styles</a> | Disallows important style declarations | Yes | | |
56
56
  | <a href="./src/rules/no-imported-style-values/README.md">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
57
57
  | <a href="./src/rules/no-nested-selectors/README.md">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
58
+ | <a href="./src/rules/no-styled/README.md">no-styled</a> | Disallows usage of the `styled` imports | Yes | | |
58
59
  | <a href="./src/rules/no-unsafe-values/README.md">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
59
60
  | <a href="./src/rules/use-compiled/README.md">use-compiled</a> | Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries | Yes | Yes | |
60
61
  | <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 | |
@@ -24,6 +24,7 @@ but more are planned to support the standard over time.
24
24
  | <a href="no-important-styles/usage">no-important-styles</a> | Disallows important style declarations | Yes | | |
25
25
  | <a href="no-imported-style-values/usage">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
26
26
  | <a href="no-nested-selectors/usage">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
27
+ | <a href="no-styled/usage">no-styled</a> | Disallows usage of the `styled` imports | Yes | | |
27
28
  | <a href="no-unsafe-values/usage">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
28
29
  | <a href="use-compiled/usage">use-compiled</a> | Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries | Yes | Yes | |
29
30
  | <a href="consistent-css-prop-usage/usage">@atlaskit/design-system/consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
@@ -0,0 +1,89 @@
1
+ # no-styled
2
+
3
+ This rule prevents usage of `styled` imports'.
4
+
5
+ Avoid usages of styled, eg. `styled.div`, `styled('div')`, `styled(Component)`, etc.
6
+
7
+ ## Examples
8
+
9
+ ### Incorrect
10
+
11
+ ```tsx
12
+ import styled from 'styled-components';
13
+
14
+ const Component = styled.div`
15
+ color: red;
16
+ `;
17
+ export default styled.div({ color: 'red' });
18
+ ```
19
+
20
+ ```tsx
21
+ import styled2 from '@emotion/styled';
22
+
23
+ export const Component = styled2('div')`…`;
24
+ ```
25
+
26
+ ```tsx
27
+ import styled from 'styled-components';
28
+ import { styled as styled3 } from '@compiled/react';
29
+
30
+ const Component = styled.div`color: red;`
31
+ export const ComponentTwo = styled3(Component)({ … });
32
+ ```
33
+
34
+ ```tsx
35
+ import styled from 'styled-components';
36
+
37
+ export default styled.div.attrs((props) => ({ 'data-testid': props.testId }))({
38
+ color: 'red',
39
+ });
40
+ ```
41
+
42
+ ```tsx
43
+ import styled from 'styled-components';
44
+
45
+ export default styled.div.attrs((props) => ({ 'data-testid': props.testId }))`
46
+ color: red;
47
+ `;
48
+ ```
49
+
50
+ ### Correct
51
+
52
+ ```tsx
53
+ import { css, jsx } from '@emotion/react';
54
+
55
+ const styles = css({ color: 'red' });
56
+
57
+ const Component = ({ children }) => {
58
+ return <div css={styles}>{children}</div>;
59
+ };
60
+ ```
61
+
62
+ ```tsx
63
+ // Using Primitives
64
+ import { Box, xcss } from '@atlaskit/primitives';
65
+
66
+ const styles = xcss({
67
+ color: 'color.text.subtlest',
68
+ });
69
+
70
+ const Component = ({ children }) => {
71
+ return <Box xcss={styles}>{children}</Box>;
72
+ };
73
+ ```
74
+
75
+ ## FAQ
76
+
77
+ ### Why avoid using `styled` imports?
78
+
79
+ Using `styled` imports impacts file readability, has TypeScript implications, adds linting
80
+ complexity, promotes exported styles, and potential refactoring efforts. Using `css()` with the
81
+ `<div css={…}>` syntax is more performant and clear.
82
+
83
+ ### How will I extend like `styled(Button)`?
84
+
85
+ Primarily, we would suggest you don't extend styles of a component you don't own unless they have an
86
+ explicit bounded interface for you to customize against. The Atlassian Design System for example has
87
+ removed `styled(Button)` interactivity in our latest variants because they are unsafe for us to
88
+ evolve the system with. Instead, make use of reusable component patterns to pass props around which
89
+ impact the styles of that component.
@@ -23,8 +23,8 @@ import styled, { css } from 'styled-components';
23
23
 
24
24
  ### Correct
25
25
 
26
- We expect usage of `@atlaskit/primitives.xcss` when working with Primitives and
27
- `@compiled/react.css` when working with custom or native code.
26
+ We expect usage of `xcss` with `@atlaskit/primitives` when working with Primitives, and `css` with
27
+ `@compiled/react` when working with custom or native code.
28
28
 
29
29
  ```js
30
30
  /** @jsx jsx */
@@ -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::9ac05c3cbd30f6209164b7a24f7a7a19>>
9
+ * @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -25,6 +25,7 @@ var _default = exports.default = {
25
25
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
26
26
  '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
27
27
  '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
28
+ '@atlaskit/ui-styling-standard/no-styled': 'warn',
28
29
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
29
30
  '@atlaskit/ui-styling-standard/use-compiled': 'warn',
30
31
  '@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::9ac05c3cbd30f6209164b7a24f7a7a19>>
9
+ * @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -25,6 +25,7 @@ var _default = exports.default = {
25
25
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
26
26
  '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
27
27
  '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
28
+ '@atlaskit/ui-styling-standard/no-styled': 'warn',
28
29
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
29
30
  '@atlaskit/ui-styling-standard/use-compiled': 'warn',
30
31
  '@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
@@ -18,11 +18,12 @@ var _noGlobalStyles = _interopRequireDefault(require("./no-global-styles"));
18
18
  var _noImportantStyles = _interopRequireDefault(require("./no-important-styles"));
19
19
  var _noImportedStyleValues = _interopRequireDefault(require("./no-imported-style-values"));
20
20
  var _noNestedSelectors = _interopRequireDefault(require("./no-nested-selectors"));
21
+ var _noStyled = _interopRequireDefault(require("./no-styled"));
21
22
  var _noUnsafeValues = _interopRequireDefault(require("./no-unsafe-values"));
22
23
  var _useCompiled = _interopRequireDefault(require("./use-compiled"));
23
24
  /**
24
25
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
25
- * @codegen <<SignedSource::3cea683df6e31f816db56abf1fd65c1e>>
26
+ * @codegen <<SignedSource::417762b5fc4a56c3b69c22b8ac0d12e7>>
26
27
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
27
28
  */
28
29
  var _default = exports.default = {
@@ -39,6 +40,7 @@ var _default = exports.default = {
39
40
  'no-important-styles': _noImportantStyles.default,
40
41
  'no-imported-style-values': _noImportedStyleValues.default,
41
42
  'no-nested-selectors': _noNestedSelectors.default,
43
+ 'no-styled': _noStyled.default,
42
44
  'no-unsafe-values': _noUnsafeValues.default,
43
45
  'use-compiled': _useCompiled.default
44
46
  };
@@ -6,24 +6,13 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.rule = exports.default = void 0;
8
8
  var _esquery = _interopRequireDefault(require("esquery"));
9
- var _createRule = require("../utils/create-rule");
10
9
  var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
10
+ var _schema = require("@atlaskit/eslint-utils/schema");
11
+ var _createRuleWithTypedConfig = require("../utils/create-rule-with-typed-config");
11
12
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
12
13
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
14
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
14
- var schema = [{
15
- type: 'object',
16
- properties: {
17
- importSources: {
18
- type: 'array',
19
- items: {
20
- type: 'string'
21
- },
22
- uniqueItems: true
23
- }
24
- }
25
- }];
26
- var rule = exports.rule = (0, _createRule.createLintRule)({
15
+ var rule = exports.rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
27
16
  meta: {
28
17
  name: 'no-important-styles',
29
18
  docs: {
@@ -35,10 +24,15 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
35
24
  'no-important-styles': 'Important style declarations are disallowed. Refactor so the `!important` flag is not needed.'
36
25
  },
37
26
  type: 'problem',
38
- schema: schema
27
+ schema: {
28
+ type: 'object',
29
+ properties: {
30
+ importSources: _schema.importSources
31
+ }
32
+ }
39
33
  },
40
- create: function create(context) {
41
- var importSources = (0, _isSupportedImport.getImportSources)(context);
34
+ create: function create(context, _ref) {
35
+ var importSources = _ref.importSources;
42
36
  return {
43
37
  CallExpression: function CallExpression(node) {
44
38
  var _context$getScope = context.getScope(),
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.rule = exports.default = void 0;
7
+ var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
8
+ var _createRule = require("../utils/create-rule");
9
+ var rule = exports.rule = (0, _createRule.createLintRule)({
10
+ meta: {
11
+ name: 'no-styled',
12
+ docs: {
13
+ description: 'Disallows usage of the `styled` imports',
14
+ recommended: true,
15
+ severity: 'warn'
16
+ },
17
+ messages: {
18
+ 'no-styled': "Avoid usages of styled, eg. styled.div, styled('div'), styled(Component), etc."
19
+ },
20
+ type: 'problem'
21
+ },
22
+ create: function create(context) {
23
+ return {
24
+ CallExpression: function (_CallExpression) {
25
+ function CallExpression(_x) {
26
+ return _CallExpression.apply(this, arguments);
27
+ }
28
+ CallExpression.toString = function () {
29
+ return _CallExpression.toString();
30
+ };
31
+ return CallExpression;
32
+ }(function (node) {
33
+ var references = context.getScope().references;
34
+ var importSources = (0, _isSupportedImport.getImportSources)(context);
35
+ if ((0, _isSupportedImport.isStyled)(node, references, importSources)) {
36
+ context.report({
37
+ node: node,
38
+ messageId: 'no-styled'
39
+ });
40
+ }
41
+ }),
42
+ MemberExpression: function (_MemberExpression) {
43
+ function MemberExpression(_x2) {
44
+ return _MemberExpression.apply(this, arguments);
45
+ }
46
+ MemberExpression.toString = function () {
47
+ return _MemberExpression.toString();
48
+ };
49
+ return MemberExpression;
50
+ }(function (node) {
51
+ var references = context.getScope().references;
52
+ var importSources = (0, _isSupportedImport.getImportSources)(context);
53
+ if (node.object.type === 'Identifier' && (0, _isSupportedImport.isStyled)(node.object, references, importSources)) {
54
+ var parent = context.getAncestors().at(-1);
55
+ if (parent && (parent.type === 'CallExpression' || parent.type === 'MemberExpression')) {
56
+ return;
57
+ }
58
+ context.report({
59
+ node: node,
60
+ messageId: 'no-styled'
61
+ });
62
+ }
63
+ })
64
+ };
65
+ }
66
+ });
67
+ var _default = exports.default = rule;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createLintRuleWithTypedConfig = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _ajv = _interopRequireDefault(require("ajv"));
10
+ var _createRule = require("./create-rule");
11
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
+ var createLintRuleWithTypedConfig = exports.createLintRuleWithTypedConfig = function createLintRuleWithTypedConfig(rule) {
14
+ /**
15
+ * Gets the default config by running the same validator
16
+ * ESLint does against an empty config object with
17
+ * `useDefaults` option enabled.
18
+ *
19
+ * Any properties with a `default` property set in the schema
20
+ * will be populated with the specified default value.
21
+ */
22
+ function getDefaultConfig() {
23
+ var ajv = new _ajv.default({
24
+ useDefaults: true
25
+ });
26
+ var validate = ajv.compile(rule.meta.schema);
27
+ var config = {};
28
+ /**
29
+ * The `validate()` function mutates the config object.
30
+ */
31
+ validate(config);
32
+ return config;
33
+ }
34
+ return _objectSpread(_objectSpread({}, rule), {}, {
35
+ meta: _objectSpread(_objectSpread({}, rule.meta), {}, {
36
+ docs: _objectSpread(_objectSpread({}, rule.meta.docs), {}, {
37
+ url: (0, _createRule.getRuleUrl)(rule.meta.name)
38
+ }),
39
+ schema: [rule.meta.schema]
40
+ }),
41
+ create: function create(context) {
42
+ /**
43
+ * The config the user has passed.
44
+ *
45
+ * If they passed a config object, even if it is missing properties,
46
+ * ESLint will have added any default values defined using the
47
+ * `default` property in the schema.
48
+ *
49
+ * https://github.com/eslint/eslint/pull/11288
50
+ */
51
+ var userConfig = context.options[0];
52
+ /**
53
+ * If the user passed no config object at all we need to obtain
54
+ * the default ourselves.
55
+ */
56
+ var config = userConfig !== null && userConfig !== void 0 ? userConfig : getDefaultConfig();
57
+ return rule.create(context, config);
58
+ }
59
+ });
60
+ };
@@ -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::9ac05c3cbd30f6209164b7a24f7a7a19>>
3
+ * @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -19,6 +19,7 @@ export default {
19
19
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
20
20
  '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
21
21
  '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
22
+ '@atlaskit/ui-styling-standard/no-styled': 'warn',
22
23
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
23
24
  '@atlaskit/ui-styling-standard/use-compiled': 'warn',
24
25
  '@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::9ac05c3cbd30f6209164b7a24f7a7a19>>
3
+ * @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -19,6 +19,7 @@ export default {
19
19
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
20
20
  '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
21
21
  '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
22
+ '@atlaskit/ui-styling-standard/no-styled': 'warn',
22
23
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
23
24
  '@atlaskit/ui-styling-standard/use-compiled': 'warn',
24
25
  '@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::3cea683df6e31f816db56abf1fd65c1e>>
3
+ * @codegen <<SignedSource::417762b5fc4a56c3b69c22b8ac0d12e7>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import atlaskitTheme from './atlaskit-theme';
@@ -16,6 +16,7 @@ import noGlobalStyles from './no-global-styles';
16
16
  import noImportantStyles from './no-important-styles';
17
17
  import noImportedStyleValues from './no-imported-style-values';
18
18
  import noNestedSelectors from './no-nested-selectors';
19
+ import noStyled from './no-styled';
19
20
  import noUnsafeValues from './no-unsafe-values';
20
21
  import useCompiled from './use-compiled';
21
22
  export default {
@@ -32,6 +33,7 @@ export default {
32
33
  'no-important-styles': noImportantStyles,
33
34
  'no-imported-style-values': noImportedStyleValues,
34
35
  'no-nested-selectors': noNestedSelectors,
36
+ 'no-styled': noStyled,
35
37
  'no-unsafe-values': noUnsafeValues,
36
38
  'use-compiled': useCompiled
37
39
  };
@@ -1,19 +1,8 @@
1
1
  import esquery from 'esquery';
2
- import { createLintRule } from '../utils/create-rule';
3
- import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
4
- const schema = [{
5
- type: 'object',
6
- properties: {
7
- importSources: {
8
- type: 'array',
9
- items: {
10
- type: 'string'
11
- },
12
- uniqueItems: true
13
- }
14
- }
15
- }];
16
- export const rule = createLintRule({
2
+ import { hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
3
+ import { importSources } from '@atlaskit/eslint-utils/schema';
4
+ import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
5
+ export const rule = createLintRuleWithTypedConfig({
17
6
  meta: {
18
7
  name: 'no-important-styles',
19
8
  docs: {
@@ -25,10 +14,16 @@ export const rule = createLintRule({
25
14
  'no-important-styles': 'Important style declarations are disallowed. Refactor so the `!important` flag is not needed.'
26
15
  },
27
16
  type: 'problem',
28
- schema
17
+ schema: {
18
+ type: 'object',
19
+ properties: {
20
+ importSources
21
+ }
22
+ }
29
23
  },
30
- create(context) {
31
- const importSources = getImportSources(context);
24
+ create(context, {
25
+ importSources
26
+ }) {
32
27
  return {
33
28
  CallExpression(node) {
34
29
  const {
@@ -0,0 +1,45 @@
1
+ import { isStyled, getImportSources } from '@atlaskit/eslint-utils/is-supported-import';
2
+ import { createLintRule } from '../utils/create-rule';
3
+ export const rule = createLintRule({
4
+ meta: {
5
+ name: 'no-styled',
6
+ docs: {
7
+ description: 'Disallows usage of the `styled` imports',
8
+ recommended: true,
9
+ severity: 'warn'
10
+ },
11
+ messages: {
12
+ 'no-styled': "Avoid usages of styled, eg. styled.div, styled('div'), styled(Component), etc."
13
+ },
14
+ type: 'problem'
15
+ },
16
+ create(context) {
17
+ return {
18
+ CallExpression: node => {
19
+ const references = context.getScope().references;
20
+ const importSources = getImportSources(context);
21
+ if (isStyled(node, references, importSources)) {
22
+ context.report({
23
+ node,
24
+ messageId: 'no-styled'
25
+ });
26
+ }
27
+ },
28
+ MemberExpression: node => {
29
+ const references = context.getScope().references;
30
+ const importSources = getImportSources(context);
31
+ if (node.object.type === 'Identifier' && isStyled(node.object, references, importSources)) {
32
+ const parent = context.getAncestors().at(-1);
33
+ if (parent && (parent.type === 'CallExpression' || parent.type === 'MemberExpression')) {
34
+ return;
35
+ }
36
+ context.report({
37
+ node,
38
+ messageId: 'no-styled'
39
+ });
40
+ }
41
+ }
42
+ };
43
+ }
44
+ });
45
+ export default rule;
@@ -0,0 +1,53 @@
1
+ import Ajv from 'ajv';
2
+ import { getRuleUrl } from './create-rule';
3
+ export const createLintRuleWithTypedConfig = rule => {
4
+ /**
5
+ * Gets the default config by running the same validator
6
+ * ESLint does against an empty config object with
7
+ * `useDefaults` option enabled.
8
+ *
9
+ * Any properties with a `default` property set in the schema
10
+ * will be populated with the specified default value.
11
+ */
12
+ function getDefaultConfig() {
13
+ const ajv = new Ajv({
14
+ useDefaults: true
15
+ });
16
+ const validate = ajv.compile(rule.meta.schema);
17
+ const config = {};
18
+ /**
19
+ * The `validate()` function mutates the config object.
20
+ */
21
+ validate(config);
22
+ return config;
23
+ }
24
+ return {
25
+ ...rule,
26
+ meta: {
27
+ ...rule.meta,
28
+ docs: {
29
+ ...rule.meta.docs,
30
+ url: getRuleUrl(rule.meta.name)
31
+ },
32
+ schema: [rule.meta.schema]
33
+ },
34
+ create(context) {
35
+ /**
36
+ * The config the user has passed.
37
+ *
38
+ * If they passed a config object, even if it is missing properties,
39
+ * ESLint will have added any default values defined using the
40
+ * `default` property in the schema.
41
+ *
42
+ * https://github.com/eslint/eslint/pull/11288
43
+ */
44
+ const userConfig = context.options[0];
45
+ /**
46
+ * If the user passed no config object at all we need to obtain
47
+ * the default ourselves.
48
+ */
49
+ const config = userConfig !== null && userConfig !== void 0 ? userConfig : getDefaultConfig();
50
+ return rule.create(context, config);
51
+ }
52
+ };
53
+ };
@@ -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::9ac05c3cbd30f6209164b7a24f7a7a19>>
3
+ * @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -19,6 +19,7 @@ export default {
19
19
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
20
20
  '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
21
21
  '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
22
+ '@atlaskit/ui-styling-standard/no-styled': 'warn',
22
23
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
23
24
  '@atlaskit/ui-styling-standard/use-compiled': 'warn',
24
25
  '@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::9ac05c3cbd30f6209164b7a24f7a7a19>>
3
+ * @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -19,6 +19,7 @@ export default {
19
19
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
20
20
  '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
21
21
  '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
22
+ '@atlaskit/ui-styling-standard/no-styled': 'warn',
22
23
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
23
24
  '@atlaskit/ui-styling-standard/use-compiled': 'warn',
24
25
  '@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::3cea683df6e31f816db56abf1fd65c1e>>
3
+ * @codegen <<SignedSource::417762b5fc4a56c3b69c22b8ac0d12e7>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import atlaskitTheme from './atlaskit-theme';
@@ -16,6 +16,7 @@ import noGlobalStyles from './no-global-styles';
16
16
  import noImportantStyles from './no-important-styles';
17
17
  import noImportedStyleValues from './no-imported-style-values';
18
18
  import noNestedSelectors from './no-nested-selectors';
19
+ import noStyled from './no-styled';
19
20
  import noUnsafeValues from './no-unsafe-values';
20
21
  import useCompiled from './use-compiled';
21
22
  export default {
@@ -32,6 +33,7 @@ export default {
32
33
  'no-important-styles': noImportantStyles,
33
34
  'no-imported-style-values': noImportedStyleValues,
34
35
  'no-nested-selectors': noNestedSelectors,
36
+ 'no-styled': noStyled,
35
37
  'no-unsafe-values': noUnsafeValues,
36
38
  'use-compiled': useCompiled
37
39
  };