@atlaskit/eslint-plugin-ui-styling-standard 0.15.2 → 0.16.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 (95) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/constellation/index/migration-guide.mdx +309 -0
  3. package/constellation/index/overview.mdx +4 -0
  4. package/constellation/index/props.mdx +9 -5
  5. package/dist/types/rules/no-unsafe-selectors/constants.d.ts +1 -4
  6. package/index.js +9 -9
  7. package/package.json +3 -3
  8. package/scripts/codegen.tsx +223 -284
  9. package/src/rules/__tests__/utils/_tester.tsx +24 -24
  10. package/src/rules/atlaskit-theme/README.md +21 -19
  11. package/src/rules/atlaskit-theme/__tests__/test.ts +53 -53
  12. package/src/rules/atlaskit-theme/index.ts +107 -115
  13. package/src/rules/convert-props-syntax/README.md +32 -22
  14. package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +46 -46
  15. package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +175 -175
  16. package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +52 -52
  17. package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +33 -33
  18. package/src/rules/convert-props-syntax/index.tsx +356 -386
  19. package/src/rules/enforce-style-prop/README.md +21 -18
  20. package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +90 -96
  21. package/src/rules/enforce-style-prop/index.tsx +144 -160
  22. package/src/rules/external-rules.tsx +163 -164
  23. package/src/rules/local-cx-xcss/README.md +10 -6
  24. package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +26 -26
  25. package/src/rules/local-cx-xcss/index.tsx +46 -56
  26. package/src/rules/no-array-arguments/README.md +2 -1
  27. package/src/rules/no-array-arguments/__tests__/rule.test.tsx +37 -46
  28. package/src/rules/no-array-arguments/index.tsx +68 -69
  29. package/src/rules/no-classname-prop/README.md +7 -4
  30. package/src/rules/no-classname-prop/__tests__/rule.test.tsx +22 -22
  31. package/src/rules/no-classname-prop/index.tsx +25 -25
  32. package/src/rules/no-container-queries/README.md +11 -9
  33. package/src/rules/no-container-queries/__tests__/rule.test.tsx +47 -50
  34. package/src/rules/no-container-queries/index.tsx +75 -81
  35. package/src/rules/no-dynamic-styles/README.md +16 -19
  36. package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +58 -67
  37. package/src/rules/no-dynamic-styles/index.tsx +45 -48
  38. package/src/rules/no-exported-styles/README.md +17 -12
  39. package/src/rules/no-exported-styles/__tests__/rule.test.tsx +102 -111
  40. package/src/rules/no-exported-styles/index.tsx +36 -36
  41. package/src/rules/no-global-styles/README.md +15 -14
  42. package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +28 -28
  43. package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +37 -37
  44. package/src/rules/no-global-styles/index.tsx +59 -62
  45. package/src/rules/no-important-styles/README.md +5 -3
  46. package/src/rules/no-important-styles/__tests__/rule.test.tsx +66 -66
  47. package/src/rules/no-important-styles/index.tsx +49 -49
  48. package/src/rules/no-imported-style-values/README.md +23 -15
  49. package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +123 -123
  50. package/src/rules/no-imported-style-values/index.tsx +116 -120
  51. package/src/rules/no-nested-selectors/README.md +15 -13
  52. package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +128 -128
  53. package/src/rules/no-styled/README.md +14 -9
  54. package/src/rules/no-styled/__tests__/rule.test.tsx +31 -31
  55. package/src/rules/no-styled/index.tsx +34 -41
  56. package/src/rules/no-unsafe-selectors/README.md +103 -93
  57. package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +21 -24
  58. package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +44 -44
  59. package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +21 -21
  60. package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +57 -57
  61. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +58 -58
  62. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +85 -85
  63. package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +12 -12
  64. package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +23 -23
  65. package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +114 -114
  66. package/src/rules/no-unsafe-selectors/constants.tsx +69 -77
  67. package/src/rules/no-unsafe-selectors/source-position-utils.tsx +38 -38
  68. package/src/rules/no-unsafe-selectors/walk-css-map.tsx +178 -184
  69. package/src/rules/no-unsafe-values/README.md +34 -40
  70. package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +13 -13
  71. package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +18 -18
  72. package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +104 -104
  73. package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +128 -128
  74. package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +23 -23
  75. package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +38 -38
  76. package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +18 -18
  77. package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +18 -18
  78. package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +28 -28
  79. package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +47 -47
  80. package/src/rules/no-unsafe-values/index.tsx +76 -78
  81. package/src/rules/no-unsafe-values/messages.tsx +12 -12
  82. package/src/rules/no-unsafe-values/utils.tsx +370 -382
  83. package/src/rules/use-compiled/README.md +11 -8
  84. package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +32 -32
  85. package/src/rules/use-compiled/__tests__/css.test.tsx +53 -53
  86. package/src/rules/use-compiled/__tests__/imports.test.tsx +90 -95
  87. package/src/rules/use-compiled/__tests__/keyframes.test.tsx +47 -47
  88. package/src/rules/use-compiled/__tests__/pragma.test.tsx +64 -64
  89. package/src/rules/use-compiled/__tests__/styled.test.tsx +53 -53
  90. package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +10 -10
  91. package/src/rules/use-compiled/index.tsx +203 -226
  92. package/src/rules/use-compiled/is-safe.tsx +113 -117
  93. package/src/rules/use-compiled/utils.tsx +14 -18
  94. package/src/rules/utils/create-rule-with-typed-config.tsx +62 -63
  95. package/src/rules/utils/create-rule.tsx +3 -6
@@ -2,99 +2,93 @@ import estraverse from 'estraverse';
2
2
 
3
3
  import { createLintRule } from '../utils/create-rule';
4
4
  import {
5
- isCss,
6
- getImportSources,
7
- isStyled,
8
- isKeyframes,
9
- isCssMap,
10
- isXcss,
5
+ isCss,
6
+ getImportSources,
7
+ isStyled,
8
+ isKeyframes,
9
+ isCssMap,
10
+ isXcss,
11
11
  } from '@atlaskit/eslint-utils/is-supported-import';
12
12
  import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
13
13
 
14
14
  const schema: JSONSchema4 = [
15
- {
16
- type: 'object',
17
- properties: {
18
- importSources: {
19
- type: 'array',
20
- items: { type: 'string' },
21
- uniqueItems: true,
22
- },
23
- },
24
- },
15
+ {
16
+ type: 'object',
17
+ properties: {
18
+ importSources: {
19
+ type: 'array',
20
+ items: { type: 'string' },
21
+ uniqueItems: true,
22
+ },
23
+ },
24
+ },
25
25
  ];
26
26
 
27
27
  export const rule = createLintRule({
28
- meta: {
29
- name: 'no-container-queries',
30
- docs: {
31
- description: 'Prevents usage of @container query within css styling',
32
- recommended: true,
33
- severity: 'warn',
34
- },
35
- messages: {
36
- 'no-container-queries':
37
- 'We block @container queries as they break scope and are not type-safe. We suggest alternatives such as JS-based APIs or @media queries.',
38
- },
39
- type: 'problem',
40
- schema,
41
- },
42
- create(context) {
43
- const importSources = getImportSources(context);
28
+ meta: {
29
+ name: 'no-container-queries',
30
+ docs: {
31
+ description: 'Prevents usage of @container query within css styling',
32
+ recommended: true,
33
+ severity: 'warn',
34
+ },
35
+ messages: {
36
+ 'no-container-queries':
37
+ 'We block @container queries as they break scope and are not type-safe. We suggest alternatives such as JS-based APIs or @media queries.',
38
+ },
39
+ type: 'problem',
40
+ schema,
41
+ },
42
+ create(context) {
43
+ const importSources = getImportSources(context);
44
44
 
45
- return {
46
- CallExpression(node) {
47
- const { references } = context.getScope();
45
+ return {
46
+ CallExpression(node) {
47
+ const { references } = context.getScope();
48
48
 
49
- if (
50
- isCss(node.callee, references, importSources) ||
51
- isStyled(node.callee, references, importSources) ||
52
- isKeyframes(node.callee, references, importSources) ||
53
- isCssMap(node.callee, references, importSources) ||
54
- isXcss(node.callee, references, importSources)
55
- ) {
56
- estraverse.traverse(node, {
57
- enter(node) {
58
- if (node.type !== 'Property') {
59
- return;
60
- }
49
+ if (
50
+ isCss(node.callee, references, importSources) ||
51
+ isStyled(node.callee, references, importSources) ||
52
+ isKeyframes(node.callee, references, importSources) ||
53
+ isCssMap(node.callee, references, importSources) ||
54
+ isXcss(node.callee, references, importSources)
55
+ ) {
56
+ estraverse.traverse(node, {
57
+ enter(node) {
58
+ if (node.type !== 'Property') {
59
+ return;
60
+ }
61
61
 
62
- if (
63
- node.key.type !== 'Literal' &&
64
- node.key.type !== 'TemplateLiteral'
65
- ) {
66
- return;
67
- }
62
+ if (node.key.type !== 'Literal' && node.key.type !== 'TemplateLiteral') {
63
+ return;
64
+ }
68
65
 
69
- if (
70
- node.key.type === 'Literal' &&
71
- node.key.value?.toString().match(/@container/)
72
- ) {
73
- context.report({
74
- node: node.key,
75
- messageId: 'no-container-queries',
76
- });
77
- }
66
+ if (node.key.type === 'Literal' && node.key.value?.toString().match(/@container/)) {
67
+ context.report({
68
+ node: node.key,
69
+ messageId: 'no-container-queries',
70
+ });
71
+ }
78
72
 
79
- if (
80
- node.key.type === 'TemplateLiteral' &&
81
- node.key.quasis[0]?.value.raw.match(/@container/)
82
- ) {
83
- context.report({
84
- node: node.key,
85
- messageId: 'no-container-queries',
86
- });
87
- }
88
- },
89
- /**
90
- * This is needed to handle unknown node types. Otherwise an error is thrown.
91
- */
92
- fallback: 'iteration',
93
- });
94
- }
95
- },
96
- };
97
- },
73
+ if (
74
+ node.key.type === 'TemplateLiteral' &&
75
+ node.key.quasis[0]?.value.raw.match(/@container/)
76
+ ) {
77
+ context.report({
78
+ node: node.key,
79
+ messageId: 'no-container-queries',
80
+ });
81
+ }
82
+ },
83
+ /**
84
+ * This is needed to handle unknown node types. Otherwise an error is thrown.
85
+ */
86
+ fallback: 'iteration',
87
+ });
88
+ }
89
+ },
90
+ };
91
+ },
98
92
  });
99
93
 
100
94
  export default rule;
@@ -14,7 +14,7 @@ This ensures that style declarations:
14
14
  import { styled } from '@compiled/react';
15
15
 
16
16
  const Component = styled.div<{ width: number }>((props) => ({
17
- width: props.width,
17
+ width: props.width,
18
18
  }));
19
19
  ```
20
20
 
@@ -22,7 +22,7 @@ const Component = styled.div<{ width: number }>((props) => ({
22
22
  import styled from 'styled-components';
23
23
 
24
24
  const Component = styled.div<{ width: number }>({
25
- width: (props) => props.width,
25
+ width: (props) => props.width,
26
26
  });
27
27
  ```
28
28
 
@@ -30,8 +30,7 @@ const Component = styled.div<{ width: number }>({
30
30
  import styled from 'styled-components';
31
31
 
32
32
  const Container = styled.div<hasPadding>({
33
- padding: ({ hasPadding }) =>
34
- hasPadding ? token('space.100', '8px') : token('space.0', '0px'),
33
+ padding: ({ hasPadding }) => (hasPadding ? token('space.100', '8px') : token('space.0', '0px')),
35
34
  });
36
35
  ```
37
36
 
@@ -39,8 +38,8 @@ const Container = styled.div<hasPadding>({
39
38
 
40
39
  **Flags**
41
40
 
42
- If you have a style that is on/off depending on a prop,
43
- use the `css` prop to conditionally apply it.
41
+ If you have a style that is on/off depending on a prop, use the `css` prop to conditionally apply
42
+ it.
44
43
 
45
44
  ```tsx
46
45
  import { css } from '@compiled/react';
@@ -49,14 +48,14 @@ const baseStyles = css({ padding: token('space.0') });
49
48
  const hasPaddingStyles = css({ padding: token('space.100') });
50
49
 
51
50
  const Container = ({ hasPadding = false }: { hasPadding?: boolean }) => {
52
- return <div css={[baseStyles, hasPadding && hasPaddingStyles]} />;
51
+ return <div css={[baseStyles, hasPadding && hasPaddingStyles]} />;
53
52
  };
54
53
  ```
55
54
 
56
55
  **Variants**
57
56
 
58
- If you have variants which are known ahead of time,
59
- use `cssMap` to define them and the `css` prop to conditionally apply it.
57
+ If you have variants which are known ahead of time, use `cssMap` to define them and the `css` prop
58
+ to conditionally apply it.
60
59
 
61
60
  ```tsx
62
61
  import { css } from '@compiled/react';
@@ -80,8 +79,7 @@ const Wrapper = ({ appearance = 'primary' }: { appearance?: 'primary' | 'error'
80
79
 
81
80
  **Dynamic values**
82
81
 
83
- If you have styles which are truly dynamic,
84
- use the `style` prop.
82
+ If you have styles which are truly dynamic, use the `style` prop.
85
83
 
86
84
  This approach should be used as a last resort.
87
85
 
@@ -89,7 +87,7 @@ This approach should be used as a last resort.
89
87
  import { css } from '@compiled/react';
90
88
 
91
89
  const Component = ({ width }: { width: number }) => {
92
- return <div style={{ width }} />;
90
+ return <div style={{ width }} />;
93
91
  };
94
92
  ```
95
93
 
@@ -97,15 +95,13 @@ const Component = ({ width }: { width: number }) => {
97
95
  import { css } from '@compiled/react';
98
96
 
99
97
  const containerStyles = css({
100
- '::before': {
101
- width: 'var(--ak-example-width)',
102
- },
98
+ '::before': {
99
+ width: 'var(--ak-example-width)',
100
+ },
103
101
  });
104
102
 
105
103
  function Example({ width }: { width: number }) {
106
- return (
107
- <div css={containerStyles} style={{ '--ak-example-width': `${width}px` }} />
108
- );
104
+ return <div css={containerStyles} style={{ '--ak-example-width': `${width}px` }} />;
109
105
  }
110
106
  ```
111
107
 
@@ -123,4 +119,5 @@ By default, this rule will check usages from:
123
119
  - `@emotion/styled`
124
120
  - `styled-components`
125
121
 
126
- To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
122
+ To change this list of libraries, you can define a custom set of `importSources`, which accepts an
123
+ array of package names (strings).
@@ -2,72 +2,72 @@ import { tester } from '../../__tests__/utils/_tester';
2
2
  import rule from '../index';
3
3
 
4
4
  tester.run('no-dynamic-styles', rule, {
5
- valid: [
6
- {
7
- name: 'arrow function expression outside of a styling context',
8
- code: `
5
+ valid: [
6
+ {
7
+ name: 'arrow function expression outside of a styling context',
8
+ code: `
9
9
  const arrowFunctionExpression = (props) => ({
10
10
  width: props.width
11
11
  });
12
12
  `,
13
- },
14
- {
15
- name: 'function expression outside of a styling context',
16
- code: `
13
+ },
14
+ {
15
+ name: 'function expression outside of a styling context',
16
+ code: `
17
17
  const functionExpression = function(props) {
18
18
  return {
19
19
  height: props.height
20
20
  };
21
21
  }
22
22
  `,
23
- },
24
- {
25
- name: 'function expressions as object values outside of a styling context',
26
- code: `
23
+ },
24
+ {
25
+ name: 'function expressions as object values outside of a styling context',
26
+ code: `
27
27
  const styles = {
28
28
  width: props => props.width,
29
29
  height: function(props) { return props.height }
30
30
  };
31
31
  `,
32
- },
33
- {
34
- name: "importSources doesn't include the styling library",
35
- code: `
32
+ },
33
+ {
34
+ name: "importSources doesn't include the styling library",
35
+ code: `
36
36
  import { css } from '@compiled/react';
37
37
 
38
38
  const styles = css(props => ({
39
39
  width: props.width
40
40
  }));
41
41
  `,
42
- options: [{ importSources: [] }],
43
- },
44
- ],
45
- invalid: [
46
- {
47
- name: 'function as argument to css',
48
- code: `
42
+ options: [{ importSources: [] }],
43
+ },
44
+ ],
45
+ invalid: [
46
+ {
47
+ name: 'function as argument to css',
48
+ code: `
49
49
  import { css } from '@compiled/react';
50
50
 
51
51
  const styles = css(props => ({
52
52
  width: props.width
53
53
  }));
54
54
  `,
55
- errors: [{ messageId: 'no-dynamic-styles' }],
56
- },
57
- {
58
- name: 'function as argument to styled',
59
- code: `
55
+ errors: [{ messageId: 'no-dynamic-styles' }],
56
+ },
57
+ {
58
+ name: 'function as argument to styled',
59
+ code: `
60
60
  import { styled } from '@compiled/react';
61
61
 
62
62
  const Component = styled.div(props => ({
63
63
  width: props.width
64
64
  }));
65
65
  `,
66
- errors: [{ messageId: 'no-dynamic-styles' }],
67
- },
68
- {
69
- name: 'multiple functions as arguments',
70
- code: `
66
+ errors: [{ messageId: 'no-dynamic-styles' }],
67
+ },
68
+ {
69
+ name: 'multiple functions as arguments',
70
+ code: `
71
71
  import { styled } from '@compiled/react';
72
72
 
73
73
  const Component = styled.div(
@@ -80,14 +80,11 @@ tester.run('no-dynamic-styles', rule, {
80
80
  })
81
81
  );
82
82
  `,
83
- errors: [
84
- { messageId: 'no-dynamic-styles' },
85
- { messageId: 'no-dynamic-styles' },
86
- ],
87
- },
88
- {
89
- name: 'functions as values',
90
- code: `
83
+ errors: [{ messageId: 'no-dynamic-styles' }, { messageId: 'no-dynamic-styles' }],
84
+ },
85
+ {
86
+ name: 'functions as values',
87
+ code: `
91
88
  import { styled } from '@compiled/react';
92
89
 
93
90
  const Component = styled.div({
@@ -95,38 +92,35 @@ tester.run('no-dynamic-styles', rule, {
95
92
  height: function(props) { return props.height; }
96
93
  });
97
94
  `,
98
- errors: [
99
- { messageId: 'no-dynamic-styles' },
100
- { messageId: 'no-dynamic-styles' },
101
- ],
102
- },
103
- {
104
- name: 'importSources includes styling library not in built-in list',
105
- code: `
95
+ errors: [{ messageId: 'no-dynamic-styles' }, { messageId: 'no-dynamic-styles' }],
96
+ },
97
+ {
98
+ name: 'importSources includes styling library not in built-in list',
99
+ code: `
106
100
  import { css } from 'my-package';
107
101
 
108
102
  const styles = css(props => ({
109
103
  width: props.width
110
104
  }));
111
105
  `,
112
- options: [{ importSources: ['my-package'] }],
113
- errors: [{ messageId: 'no-dynamic-styles' }],
114
- },
115
- {
116
- // This fails type-checking anyway, but doesn't hurt to test
117
- name: 'arrow function in template literal',
118
- code: `
106
+ options: [{ importSources: ['my-package'] }],
107
+ errors: [{ messageId: 'no-dynamic-styles' }],
108
+ },
109
+ {
110
+ // This fails type-checking anyway, but doesn't hurt to test
111
+ name: 'arrow function in template literal',
112
+ code: `
119
113
  import { css } from '@compiled/react';
120
114
 
121
115
  const styles = css({
122
116
  height: \`\${(props) => props.height}px\`,
123
117
  });
124
118
  `,
125
- errors: [{ messageId: 'no-dynamic-styles' }],
126
- },
127
- {
128
- name: 'dynamic styles when using styled and overriding another component',
129
- code: `
119
+ errors: [{ messageId: 'no-dynamic-styles' }],
120
+ },
121
+ {
122
+ name: 'dynamic styles when using styled and overriding another component',
123
+ code: `
130
124
  import { styled } from '@compiled/react';
131
125
  import { BaseComponent } from './base-component';
132
126
 
@@ -135,10 +129,7 @@ tester.run('no-dynamic-styles', rule, {
135
129
  height: function(props) { return props.height; }
136
130
  });
137
131
  `,
138
- errors: [
139
- { messageId: 'no-dynamic-styles' },
140
- { messageId: 'no-dynamic-styles' },
141
- ],
142
- },
143
- ],
132
+ errors: [{ messageId: 'no-dynamic-styles' }, { messageId: 'no-dynamic-styles' }],
133
+ },
134
+ ],
144
135
  });
@@ -2,62 +2,59 @@ import esquery from 'esquery';
2
2
  import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
3
3
 
4
4
  import {
5
- getImportSources,
6
- hasStyleObjectArguments,
5
+ getImportSources,
6
+ hasStyleObjectArguments,
7
7
  } from '@atlaskit/eslint-utils/is-supported-import';
8
8
 
9
9
  import { createLintRule } from '../utils/create-rule';
10
10
 
11
11
  const schema: JSONSchema4 = [
12
- {
13
- type: 'object',
14
- properties: {
15
- importSources: {
16
- type: 'array',
17
- items: { type: 'string' },
18
- uniqueItems: true,
19
- },
20
- },
21
- },
12
+ {
13
+ type: 'object',
14
+ properties: {
15
+ importSources: {
16
+ type: 'array',
17
+ items: { type: 'string' },
18
+ uniqueItems: true,
19
+ },
20
+ },
21
+ },
22
22
  ];
23
23
 
24
24
  export const rule = createLintRule({
25
- meta: {
26
- name: 'no-dynamic-styles',
27
- docs: {
28
- description: 'Disallows use of dynamic styles in CSS-in-JS calls',
29
- recommended: true,
30
- severity: 'warn',
31
- },
32
- schema,
33
- messages: {
34
- 'no-dynamic-styles':
35
- 'Dynamic styles are not allowed. Instead use the style prop to apply styles derived from component props.',
36
- },
37
- type: 'problem',
38
- },
39
- create(context) {
40
- const importSources = getImportSources(context);
41
-
42
- return {
43
- CallExpression(node) {
44
- const { references } = context.sourceCode.getScope(node);
45
-
46
- if (!hasStyleObjectArguments(node.callee, references, importSources)) {
47
- return;
48
- }
49
-
50
- const matches = esquery(
51
- node,
52
- 'ArrowFunctionExpression, FunctionExpression',
53
- );
54
-
55
- for (const match of matches) {
56
- context.report({ node: match, messageId: 'no-dynamic-styles' });
57
- }
58
- },
59
- };
60
- },
25
+ meta: {
26
+ name: 'no-dynamic-styles',
27
+ docs: {
28
+ description: 'Disallows use of dynamic styles in CSS-in-JS calls',
29
+ recommended: true,
30
+ severity: 'warn',
31
+ },
32
+ schema,
33
+ messages: {
34
+ 'no-dynamic-styles':
35
+ 'Dynamic styles are not allowed. Instead use the style prop to apply styles derived from component props.',
36
+ },
37
+ type: 'problem',
38
+ },
39
+ create(context) {
40
+ const importSources = getImportSources(context);
41
+
42
+ return {
43
+ CallExpression(node) {
44
+ const { references } = context.sourceCode.getScope(node);
45
+
46
+ if (!hasStyleObjectArguments(node.callee, references, importSources)) {
47
+ return;
48
+ }
49
+
50
+ const matches = esquery(node, 'ArrowFunctionExpression, FunctionExpression');
51
+
52
+ for (const match of matches) {
53
+ context.report({ node: match, messageId: 'no-dynamic-styles' });
54
+ }
55
+ },
56
+ };
57
+ },
61
58
  });
62
59
 
63
60
  export default rule;
@@ -1,6 +1,8 @@
1
1
  This rule disallows exports of `css`, `cssMap`, `keyframes`, `styled`, `xcss` styles.
2
2
 
3
- Exporting style declarations from these libraries may result in unexpected errors when imported, because its value will be null at runtime. Additionally, co-locating style definitions with their usage is considered best practice in order to improve code readability and build performance.
3
+ Exporting style declarations from these libraries may result in unexpected errors when imported,
4
+ because its value will be null at runtime. Additionally, co-locating style definitions with their
5
+ usage is considered best practice in order to improve code readability and build performance.
4
6
 
5
7
  ## Examples
6
8
 
@@ -22,12 +24,13 @@ export const animation = keyframes({});
22
24
  export default keyframes({});
23
25
  ```
24
26
 
25
- Avoid exporting any style-like objects or values for consumption as well as these will violate our `no-imported-style-values` rule which blocks consumption of imported styles.
27
+ Avoid exporting any style-like objects or values for consumption as well as these will violate our
28
+ `no-imported-style-values` rule which blocks consumption of imported styles.
26
29
 
27
30
  ```js
28
31
  export default {
29
- color: 'red',
30
- margin: '0px',
32
+ color: 'red',
33
+ margin: '0px',
31
34
  };
32
35
  ```
33
36
 
@@ -35,15 +38,15 @@ export default {
35
38
  import { css } from '@compiled/react';
36
39
 
37
40
  const color = css({
38
- /* */
41
+ /* */
39
42
  });
40
43
 
41
44
  const styles = {
42
- primary: {
43
- text: {
44
- color,
45
- },
46
- },
45
+ primary: {
46
+ text: {
47
+ color,
48
+ },
49
+ },
47
50
  };
48
51
 
49
52
  export default styles.primary.text.color;
@@ -51,7 +54,8 @@ export default styles.primary.text.color;
51
54
 
52
55
  ### Correct
53
56
 
54
- Co-locate your styles next to your components to improve code readability, linting, and build performance.
57
+ Co-locate your styles next to your components to improve code readability, linting, and build
58
+ performance.
55
59
 
56
60
  ```js
57
61
  import { css } from '@compiled/react';
@@ -82,4 +86,5 @@ By default, this rule will check `css` usages from:
82
86
  - `@emotion/styled`
83
87
  - `styled-components`
84
88
 
85
- To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
89
+ To change this list of libraries, you can define a custom set of `importSources`, which accepts an
90
+ array of package names (strings).