@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
@@ -3,174 +3,173 @@ import { getRuleUrl } from './utils/create-rule';
3
3
 
4
4
  /** External rules must be scoped, have a display name, and external urls. */
5
5
  export type ExternalRuleMeta = LintRuleMeta & {
6
- isExternal: true;
7
- name: `@${string}/${string}`;
8
- displayName: string;
9
- docs: { externalUrl: `https://${string}` };
6
+ isExternal: true;
7
+ name: `@${string}/${string}`;
8
+ displayName: string;
9
+ docs: { externalUrl: `https://${string}` };
10
10
  };
11
11
 
12
12
  const importSources: readonly string[] = [
13
- '@compiled/react',
14
- '@atlaskit/css',
15
- '@emotion/core',
16
- '@emotion/react',
17
- '@emotion/styled',
18
- 'styled-components',
13
+ '@compiled/react',
14
+ '@atlaskit/css',
15
+ '@emotion/core',
16
+ '@emotion/react',
17
+ '@emotion/styled',
18
+ 'styled-components',
19
19
  ];
20
20
 
21
21
  export const externalRules: ExternalRuleMeta[] = [
22
- {
23
- name: '@atlaskit/design-system/consistent-css-prop-usage',
24
- displayName: 'consistent-css-prop-usage',
25
- isExternal: true,
26
- fixable: 'code',
27
- docs: {
28
- description: 'Ensures consistency with `css` and `xcss` prop usages',
29
- url: getRuleUrl('consistent-css-prop-usage'),
30
- externalUrl:
31
- 'https://atlassian.design/components/eslint-plugin-design-system/consistent-css-prop-usage/usage',
32
- recommended: true,
33
- severity: 'warn',
34
- pluginConfig: {
35
- // When passing a css prop to a React component, we don't know whether the component
36
- // is Emotion or Compiled. Hence it is not safe to run autofixes like wrapping it in
37
- // a `css` function call.
38
- excludeReactComponents: true,
39
- },
40
- },
41
- },
42
- {
43
- name: '@atlaskit/design-system/no-css-tagged-template-expression',
44
- displayName: 'no-css-tagged-template-expression',
45
- isExternal: true,
46
- fixable: 'code',
47
- docs: {
48
- description:
49
- 'Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled',
50
- url: getRuleUrl('no-css-tagged-template-expression'),
51
- externalUrl:
52
- 'https://atlassian.design/components/eslint-plugin-design-system/no-css-tagged-template-expression/usage',
53
- recommended: true,
54
- severity: 'warn',
55
- },
56
- },
57
- {
58
- name: '@atlaskit/design-system/no-keyframes-tagged-template-expression',
59
- displayName: 'no-keyframes-tagged-template-expression',
60
- isExternal: true,
61
- fixable: 'code',
62
- docs: {
63
- description:
64
- 'Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled',
65
- url: getRuleUrl('no-keyframes-tagged-template-expression'),
66
- externalUrl:
67
- 'https://atlassian.design/components/eslint-plugin-design-system/no-keyframes-tagged-template-expression/usage',
68
- recommended: true,
69
- severity: 'warn',
70
- },
71
- },
72
- {
73
- name: '@atlaskit/design-system/no-styled-tagged-template-expression',
74
- displayName: 'no-styled-tagged-template-expression',
75
- isExternal: true,
76
- fixable: 'code',
77
- docs: {
78
- description:
79
- 'Disallows any `styled` tagged template expressions that originate from Emotion, Styled Components or Compiled',
80
- url: getRuleUrl('no-styled-tagged-template-expression'),
81
- externalUrl:
82
- 'https://atlassian.design/components/eslint-plugin-design-system/no-styled-tagged-template-expression/usage',
83
- recommended: true,
84
- severity: 'warn',
85
- },
86
- },
87
- {
88
- name: '@compiled/no-suppress-xcss',
89
- displayName: 'no-suppress-xcss',
90
- isExternal: true,
91
- docs: {
92
- description:
93
- 'Disallows supressing type violations when using the xcss prop.',
94
- url: getRuleUrl('no-suppress-xcss'),
95
- externalUrl:
96
- 'https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/no-suppress-xcss',
97
- recommended: true,
98
- severity: 'warn',
99
- },
100
- },
101
- {
102
- name: '@compiled/no-js-xcss',
103
- displayName: 'no-js-xcss',
104
- isExternal: true,
105
- docs: {
106
- description: 'Disallows using xcss prop inside JavaScript files.',
107
- url: getRuleUrl('no-js-xcss'),
108
- externalUrl:
109
- 'https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/no-js-xcss',
110
- recommended: true,
111
- severity: 'warn',
112
- },
113
- },
114
- {
115
- name: '@atlaskit/design-system/no-empty-styled-expression',
116
- displayName: 'no-empty-styled-expression',
117
- isExternal: true,
118
- docs: {
119
- description:
120
- 'Forbids any styled expression to be used when passing empty arguments to styled.div() (or other JSX elements).',
121
- url: getRuleUrl('no-empty-styled-expression'),
122
- externalUrl:
123
- 'https://atlassian.design/components/eslint-plugin-design-system/no-empty-styled-expression/usage',
124
- recommended: true,
125
- severity: 'warn',
126
- pluginConfig: { importSources },
127
- },
128
- },
129
- {
130
- name: '@atlaskit/design-system/no-exported-css',
131
- displayName: 'no-exported-css',
132
- isExternal: true,
133
- docs: {
134
- description:
135
- 'Forbid exporting `css` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable.',
136
- url: getRuleUrl('no-exported-css'),
137
- externalUrl:
138
- 'https://atlassian.design/components/eslint-plugin-design-system/no-exported-css/usage',
139
- recommended: true,
140
- severity: 'warn',
141
- pluginConfig: { importSources },
142
- },
143
- },
144
- {
145
- name: '@atlaskit/design-system/no-exported-keyframes',
146
- displayName: 'no-exported-keyframes',
147
- isExternal: true,
148
- docs: {
149
- description:
150
- 'Forbid exporting `keyframes` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable.',
151
- url: getRuleUrl('no-exported-keyframes'),
152
- externalUrl:
153
- 'https://atlassian.design/components/eslint-plugin-design-system/no-exported-keyframes/usage',
154
- recommended: true,
155
- severity: 'warn',
156
- pluginConfig: { importSources },
157
- },
158
- },
159
- {
160
- name: '@atlaskit/design-system/no-invalid-css-map',
161
- displayName: 'no-invalid-css-map',
162
- isExternal: true,
163
- docs: {
164
- description:
165
- "Checks the validity of a CSS map created through cssMap. This is intended to be used alongside TypeScript's type-checking.",
166
- url: getRuleUrl('no-invalid-css-map'),
167
- externalUrl:
168
- 'https://atlassian.design/components/eslint-plugin-design-system/no-invalid-css-map/usage',
169
- recommended: true,
170
- severity: 'warn',
171
- pluginConfig: {
172
- allowedFunctionCalls: [['@atlaskit/tokens', 'token']],
173
- },
174
- },
175
- },
22
+ {
23
+ name: '@atlaskit/design-system/consistent-css-prop-usage',
24
+ displayName: 'consistent-css-prop-usage',
25
+ isExternal: true,
26
+ fixable: 'code',
27
+ docs: {
28
+ description: 'Ensures consistency with `css` and `xcss` prop usages',
29
+ url: getRuleUrl('consistent-css-prop-usage'),
30
+ externalUrl:
31
+ 'https://atlassian.design/components/eslint-plugin-design-system/consistent-css-prop-usage/usage',
32
+ recommended: true,
33
+ severity: 'warn',
34
+ pluginConfig: {
35
+ // When passing a css prop to a React component, we don't know whether the component
36
+ // is Emotion or Compiled. Hence it is not safe to run autofixes like wrapping it in
37
+ // a `css` function call.
38
+ excludeReactComponents: true,
39
+ },
40
+ },
41
+ },
42
+ {
43
+ name: '@atlaskit/design-system/no-css-tagged-template-expression',
44
+ displayName: 'no-css-tagged-template-expression',
45
+ isExternal: true,
46
+ fixable: 'code',
47
+ docs: {
48
+ description:
49
+ 'Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled',
50
+ url: getRuleUrl('no-css-tagged-template-expression'),
51
+ externalUrl:
52
+ 'https://atlassian.design/components/eslint-plugin-design-system/no-css-tagged-template-expression/usage',
53
+ recommended: true,
54
+ severity: 'warn',
55
+ },
56
+ },
57
+ {
58
+ name: '@atlaskit/design-system/no-keyframes-tagged-template-expression',
59
+ displayName: 'no-keyframes-tagged-template-expression',
60
+ isExternal: true,
61
+ fixable: 'code',
62
+ docs: {
63
+ description:
64
+ 'Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled',
65
+ url: getRuleUrl('no-keyframes-tagged-template-expression'),
66
+ externalUrl:
67
+ 'https://atlassian.design/components/eslint-plugin-design-system/no-keyframes-tagged-template-expression/usage',
68
+ recommended: true,
69
+ severity: 'warn',
70
+ },
71
+ },
72
+ {
73
+ name: '@atlaskit/design-system/no-styled-tagged-template-expression',
74
+ displayName: 'no-styled-tagged-template-expression',
75
+ isExternal: true,
76
+ fixable: 'code',
77
+ docs: {
78
+ description:
79
+ 'Disallows any `styled` tagged template expressions that originate from Emotion, Styled Components or Compiled',
80
+ url: getRuleUrl('no-styled-tagged-template-expression'),
81
+ externalUrl:
82
+ 'https://atlassian.design/components/eslint-plugin-design-system/no-styled-tagged-template-expression/usage',
83
+ recommended: true,
84
+ severity: 'warn',
85
+ },
86
+ },
87
+ {
88
+ name: '@compiled/no-suppress-xcss',
89
+ displayName: 'no-suppress-xcss',
90
+ isExternal: true,
91
+ docs: {
92
+ description: 'Disallows supressing type violations when using the xcss prop.',
93
+ url: getRuleUrl('no-suppress-xcss'),
94
+ externalUrl:
95
+ 'https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/no-suppress-xcss',
96
+ recommended: true,
97
+ severity: 'warn',
98
+ },
99
+ },
100
+ {
101
+ name: '@compiled/no-js-xcss',
102
+ displayName: 'no-js-xcss',
103
+ isExternal: true,
104
+ docs: {
105
+ description: 'Disallows using xcss prop inside JavaScript files.',
106
+ url: getRuleUrl('no-js-xcss'),
107
+ externalUrl:
108
+ 'https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/no-js-xcss',
109
+ recommended: true,
110
+ severity: 'warn',
111
+ },
112
+ },
113
+ {
114
+ name: '@atlaskit/design-system/no-empty-styled-expression',
115
+ displayName: 'no-empty-styled-expression',
116
+ isExternal: true,
117
+ docs: {
118
+ description:
119
+ 'Forbids any styled expression to be used when passing empty arguments to styled.div() (or other JSX elements).',
120
+ url: getRuleUrl('no-empty-styled-expression'),
121
+ externalUrl:
122
+ 'https://atlassian.design/components/eslint-plugin-design-system/no-empty-styled-expression/usage',
123
+ recommended: true,
124
+ severity: 'warn',
125
+ pluginConfig: { importSources },
126
+ },
127
+ },
128
+ {
129
+ name: '@atlaskit/design-system/no-exported-css',
130
+ displayName: 'no-exported-css',
131
+ isExternal: true,
132
+ docs: {
133
+ description:
134
+ 'Forbid exporting `css` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable.',
135
+ url: getRuleUrl('no-exported-css'),
136
+ externalUrl:
137
+ 'https://atlassian.design/components/eslint-plugin-design-system/no-exported-css/usage',
138
+ recommended: true,
139
+ severity: 'warn',
140
+ pluginConfig: { importSources },
141
+ },
142
+ },
143
+ {
144
+ name: '@atlaskit/design-system/no-exported-keyframes',
145
+ displayName: 'no-exported-keyframes',
146
+ isExternal: true,
147
+ docs: {
148
+ description:
149
+ 'Forbid exporting `keyframes` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable.',
150
+ url: getRuleUrl('no-exported-keyframes'),
151
+ externalUrl:
152
+ 'https://atlassian.design/components/eslint-plugin-design-system/no-exported-keyframes/usage',
153
+ recommended: true,
154
+ severity: 'warn',
155
+ pluginConfig: { importSources },
156
+ },
157
+ },
158
+ {
159
+ name: '@atlaskit/design-system/no-invalid-css-map',
160
+ displayName: 'no-invalid-css-map',
161
+ isExternal: true,
162
+ docs: {
163
+ description:
164
+ "Checks the validity of a CSS map created through cssMap. This is intended to be used alongside TypeScript's type-checking.",
165
+ url: getRuleUrl('no-invalid-css-map'),
166
+ externalUrl:
167
+ 'https://atlassian.design/components/eslint-plugin-design-system/no-invalid-css-map/usage',
168
+ recommended: true,
169
+ severity: 'warn',
170
+ pluginConfig: {
171
+ allowedFunctionCalls: [['@atlaskit/tokens', 'token']],
172
+ },
173
+ },
174
+ },
176
175
  ];
@@ -1,8 +1,12 @@
1
- This rule ensures the `cx()` function is only used within the `xcss` prop. This aids tracking what styles are applied to a jsx element.
1
+ This rule ensures the `cx()` function is only used within the `xcss` prop. This aids tracking what
2
+ styles are applied to a jsx element.
2
3
 
3
4
  The `cx` function is checked only if it is imported from `@compiled/react` or `@atlaskit/css`.
4
5
 
5
- Passing arguments to the `cx()` function is how you compose styles (combine more than one set of styles together) with XCSS. This is a workaround for the more conventional array syntax (e.g. [in Emotion](https://emotion.sh/docs/composition)) `<div xcss={[style1, style2]} />` not giving robust enough type checking.
6
+ Passing arguments to the `cx()` function is how you compose styles (combine more than one set of
7
+ styles together) with XCSS. This is a workaround for the more conventional array syntax (e.g.
8
+ [in Emotion](https://emotion.sh/docs/composition)) `<div xcss={[style1, style2]} />` not giving
9
+ robust enough type checking.
6
10
 
7
11
  ## Examples
8
12
 
@@ -12,8 +16,8 @@ Passing arguments to the `cx()` function is how you compose styles (combine more
12
16
  import { cx, cssMap } from '@compiled/react';
13
17
 
14
18
  const styles = cssMap({
15
- text: { color: 'red' },
16
- bg: { background: 'blue' },
19
+ text: { color: 'red' },
20
+ bg: { background: 'blue' },
17
21
  });
18
22
 
19
23
  const joinedStyles = cx(styles.text, styles.bg);
@@ -27,8 +31,8 @@ const joinedStyles = cx(styles.text, styles.bg);
27
31
  import { cx, cssMap } from '@compiled/react';
28
32
 
29
33
  const styles = cssMap({
30
- text: { color: 'red' },
31
- bg: { background: 'blue' },
34
+ text: { color: 'red' },
35
+ bg: { background: 'blue' },
32
36
  });
33
37
 
34
38
  <Button xcss={cx(styles.text, styles.bg)} />;
@@ -2,18 +2,18 @@ import { tester } from '../../__tests__/utils/_tester';
2
2
  import rule from '../index';
3
3
 
4
4
  tester.run('local-cx-xcss', rule, {
5
- valid: [
6
- `
5
+ valid: [
6
+ `
7
7
  import { cx } from '@compiled/react';
8
8
 
9
9
  <Component xcss={cx({})} />
10
10
  `,
11
- `
11
+ `
12
12
  import { cx } from '@compiled/react';
13
13
 
14
14
  <Component innerXcss={cx({})} />
15
15
  `,
16
- `
16
+ `
17
17
  import { cx, cssMap } from '@compiled/react';
18
18
 
19
19
  const styles = cssMap({
@@ -23,7 +23,7 @@ tester.run('local-cx-xcss', rule, {
23
23
 
24
24
  <Button innerXcss={cx(styles.text, styles.bg)} />;
25
25
  `,
26
- `
26
+ `
27
27
  // Ignore cx usage not from compiled
28
28
  const styles = cssMap({
29
29
  text: { color: 'red' },
@@ -34,13 +34,13 @@ tester.run('local-cx-xcss', rule, {
34
34
 
35
35
  <Button xcss={joinedStyles} />;
36
36
  `,
37
- `
37
+ `
38
38
  // Ignore cx usage not from compiled
39
39
  const styles = cx({});
40
40
 
41
41
  <Component xcss={styles} />
42
42
  `,
43
- `
43
+ `
44
44
  // Ignore cx usage where
45
45
  // the library is not specified in additionalCompiledLibraries
46
46
  import { cx } from 'custom-package';
@@ -48,19 +48,19 @@ tester.run('local-cx-xcss', rule, {
48
48
 
49
49
  <Component xcss={styles} />
50
50
  `,
51
- ],
52
- invalid: [
53
- {
54
- code: `
51
+ ],
52
+ invalid: [
53
+ {
54
+ code: `
55
55
  import { cx } from '@compiled/react';
56
56
  const styles = cx({});
57
57
 
58
58
  <Component xcss={styles} />
59
59
  `,
60
- errors: [{ messageId: 'local-cx-xcss' }],
61
- },
62
- {
63
- code: `
60
+ errors: [{ messageId: 'local-cx-xcss' }],
61
+ },
62
+ {
63
+ code: `
64
64
  import { cx, cssMap } from '@compiled/react';
65
65
 
66
66
  const styles = cssMap({
@@ -72,19 +72,19 @@ tester.run('local-cx-xcss', rule, {
72
72
 
73
73
  <Button xcss={joinedStyles} />;
74
74
  `,
75
- errors: [{ messageId: 'local-cx-xcss' }],
76
- },
77
- {
78
- code: `
75
+ errors: [{ messageId: 'local-cx-xcss' }],
76
+ },
77
+ {
78
+ code: `
79
79
  import { cx } from '@compiled/react';
80
80
  const styles = cx({});
81
81
 
82
82
  <Component innerXcss={styles} />
83
83
  `,
84
- errors: [{ messageId: 'local-cx-xcss' }],
85
- },
86
- {
87
- code: `
84
+ errors: [{ messageId: 'local-cx-xcss' }],
85
+ },
86
+ {
87
+ code: `
88
88
  import { cx, cssMap } from '@compiled/react';
89
89
 
90
90
  const styles = cssMap({
@@ -96,7 +96,7 @@ tester.run('local-cx-xcss', rule, {
96
96
 
97
97
  <Button innerXcss={joinedStyles} />;
98
98
  `,
99
- errors: [{ messageId: 'local-cx-xcss' }],
100
- },
101
- ],
99
+ errors: [{ messageId: 'local-cx-xcss' }],
100
+ },
101
+ ],
102
102
  });
@@ -2,71 +2,61 @@ import type { Rule } from 'eslint';
2
2
  import type { JSXAttribute } from 'estree-jsx';
3
3
 
4
4
  import { createLintRule } from '../utils/create-rule';
5
- import {
6
- CSS_IN_JS_IMPORTS,
7
- isCxFunction,
8
- } from '@atlaskit/eslint-utils/is-supported-import';
5
+ import { CSS_IN_JS_IMPORTS, isCxFunction } from '@atlaskit/eslint-utils/is-supported-import';
9
6
 
10
- const IMPORT_SOURCES = [
11
- CSS_IN_JS_IMPORTS.compiled,
12
- CSS_IN_JS_IMPORTS.atlaskitCss,
13
- ];
7
+ const IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.compiled, CSS_IN_JS_IMPORTS.atlaskitCss];
14
8
 
15
9
  function getParentJSXAttribute(node: Rule.Node): JSXAttribute | null {
16
- let parent: Rule.Node | null = node.parent;
10
+ let parent: Rule.Node | null = node.parent;
17
11
 
18
- while (parent && parent.type !== 'JSXAttribute') {
19
- parent = parent.parent;
20
- }
12
+ while (parent && parent.type !== 'JSXAttribute') {
13
+ parent = parent.parent;
14
+ }
21
15
 
22
- if (parent && parent.type === 'JSXAttribute') {
23
- return parent;
24
- }
16
+ if (parent && parent.type === 'JSXAttribute') {
17
+ return parent;
18
+ }
25
19
 
26
- return null;
20
+ return null;
27
21
  }
28
22
 
29
23
  export const rule = createLintRule({
30
- meta: {
31
- name: 'local-cx-xcss',
32
- docs: {
33
- description:
34
- '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.',
35
- recommended: true,
36
- severity: 'warn',
37
- },
38
- messages: {
39
- 'local-cx-xcss':
40
- 'The cx function should only be declared inside the xcss prop to simplify tracking styles that are applied to a jsx element.',
41
- },
42
- type: 'problem',
43
- },
44
- create(context) {
45
- return {
46
- 'CallExpression[callee.name="cx"]': (node: Rule.Node) => {
47
- if (
48
- node.type === 'CallExpression' &&
49
- isCxFunction(
50
- node.callee,
51
- context.getScope().references,
52
- IMPORT_SOURCES,
53
- )
54
- ) {
55
- const parentJSXAttribute = getParentJSXAttribute(node);
56
- const propName = parentJSXAttribute?.name.name.toString();
57
-
58
- if (propName && /[xX]css$/.test(propName)) {
59
- return;
60
- }
61
-
62
- context.report({
63
- node,
64
- messageId: 'local-cx-xcss',
65
- });
66
- }
67
- },
68
- };
69
- },
24
+ meta: {
25
+ name: 'local-cx-xcss',
26
+ docs: {
27
+ description:
28
+ '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.',
29
+ recommended: true,
30
+ severity: 'warn',
31
+ },
32
+ messages: {
33
+ 'local-cx-xcss':
34
+ 'The cx function should only be declared inside the xcss prop to simplify tracking styles that are applied to a jsx element.',
35
+ },
36
+ type: 'problem',
37
+ },
38
+ create(context) {
39
+ return {
40
+ 'CallExpression[callee.name="cx"]': (node: Rule.Node) => {
41
+ if (
42
+ node.type === 'CallExpression' &&
43
+ isCxFunction(node.callee, context.getScope().references, IMPORT_SOURCES)
44
+ ) {
45
+ const parentJSXAttribute = getParentJSXAttribute(node);
46
+ const propName = parentJSXAttribute?.name.name.toString();
47
+
48
+ if (propName && /[xX]css$/.test(propName)) {
49
+ return;
50
+ }
51
+
52
+ context.report({
53
+ node,
54
+ messageId: 'local-cx-xcss',
55
+ });
56
+ }
57
+ },
58
+ };
59
+ },
70
60
  });
71
61
 
72
62
  export default rule;
@@ -40,4 +40,5 @@ By default, this rule will check `css` usages from:
40
40
  - `@emotion/styled`
41
41
  - `styled-components`
42
42
 
43
- To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
43
+ To change this list of libraries, you can define a custom set of `importSources`, which accepts an
44
+ array of package names (strings).