@atlaskit/eslint-plugin-ui-styling-standard 0.17.0 → 0.18.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 (152) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/presets/all.codegen.js +3 -2
  3. package/dist/cjs/presets/recommended.codegen.js +3 -2
  4. package/dist/cjs/rules/external-rules.js +3 -1
  5. package/dist/es2019/presets/all.codegen.js +3 -2
  6. package/dist/es2019/presets/recommended.codegen.js +3 -2
  7. package/dist/es2019/rules/external-rules.js +3 -1
  8. package/dist/esm/presets/all.codegen.js +3 -2
  9. package/dist/esm/presets/recommended.codegen.js +3 -2
  10. package/dist/esm/rules/external-rules.js +3 -1
  11. package/dist/types/index.codegen.d.ts +2 -0
  12. package/dist/types/presets/all.codegen.d.ts +2 -1
  13. package/dist/types/presets/recommended.codegen.d.ts +2 -1
  14. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  15. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  16. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
  17. package/package.json +2 -2
  18. package/afm-cc/tsconfig.json +0 -28
  19. package/afm-jira/tsconfig.json +0 -28
  20. package/build/tsconfig.json +0 -18
  21. package/constellation/atlaskit-theme/usage.mdx +0 -132
  22. package/constellation/consistent-css-prop-usage/usage.mdx +0 -7
  23. package/constellation/convert-props-syntax/usage.mdx +0 -130
  24. package/constellation/enforce-style-prop/usage.mdx +0 -47
  25. package/constellation/index/migration-guide.mdx +0 -309
  26. package/constellation/index/overview.mdx +0 -250
  27. package/constellation/index/props.mdx +0 -30
  28. package/constellation/local-cx-xcss/usage.mdx +0 -53
  29. package/constellation/no-array-arguments/usage.mdx +0 -49
  30. package/constellation/no-classname-prop/usage.mdx +0 -49
  31. package/constellation/no-container-queries/usage.mdx +0 -101
  32. package/constellation/no-css-tagged-template-expression/usage.mdx +0 -8
  33. package/constellation/no-dynamic-styles/usage.mdx +0 -130
  34. package/constellation/no-empty-styled-expression/usage.mdx +0 -8
  35. package/constellation/no-exported-css/usage.mdx +0 -8
  36. package/constellation/no-exported-keyframes/usage.mdx +0 -8
  37. package/constellation/no-exported-styles/usage.mdx +0 -87
  38. package/constellation/no-global-styles/usage.mdx +0 -60
  39. package/constellation/no-important-styles/usage.mdx +0 -33
  40. package/constellation/no-imported-style-values/usage.mdx +0 -157
  41. package/constellation/no-invalid-css-map/usage.mdx +0 -8
  42. package/constellation/no-js-xcss/usage.mdx +0 -7
  43. package/constellation/no-keyframes-tagged-template-expression/usage.mdx +0 -8
  44. package/constellation/no-nested-selectors/usage.mdx +0 -95
  45. package/constellation/no-styled/usage.mdx +0 -92
  46. package/constellation/no-styled-tagged-template-expression/usage.mdx +0 -8
  47. package/constellation/no-suppress-xcss/usage.mdx +0 -28
  48. package/constellation/no-unsafe-selectors/usage.mdx +0 -370
  49. package/constellation/no-unsafe-values/usage.mdx +0 -318
  50. package/constellation/use-compiled/usage.mdx +0 -54
  51. package/index.js +0 -24
  52. package/scripts/codegen.tsx +0 -373
  53. package/src/index.codegen.tsx +0 -14
  54. package/src/index.tsx +0 -1
  55. package/src/presets/all.codegen.tsx +0 -79
  56. package/src/presets/recommended.codegen.tsx +0 -79
  57. package/src/rules/TEMPLATE.md +0 -29
  58. package/src/rules/__tests__/utils/_tester.tsx +0 -40
  59. package/src/rules/atlaskit-theme/README.md +0 -130
  60. package/src/rules/atlaskit-theme/__tests__/test.ts +0 -133
  61. package/src/rules/atlaskit-theme/index.ts +0 -134
  62. package/src/rules/convert-props-syntax/README.md +0 -128
  63. package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +0 -76
  64. package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +0 -584
  65. package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +0 -140
  66. package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +0 -69
  67. package/src/rules/convert-props-syntax/index.tsx +0 -414
  68. package/src/rules/enforce-style-prop/README.md +0 -45
  69. package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +0 -243
  70. package/src/rules/enforce-style-prop/index.tsx +0 -172
  71. package/src/rules/external-rules.tsx +0 -175
  72. package/src/rules/index.codegen.tsx +0 -42
  73. package/src/rules/local-cx-xcss/README.md +0 -51
  74. package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +0 -102
  75. package/src/rules/local-cx-xcss/index.tsx +0 -62
  76. package/src/rules/no-array-arguments/README.md +0 -47
  77. package/src/rules/no-array-arguments/__tests__/rule.test.tsx +0 -107
  78. package/src/rules/no-array-arguments/index.tsx +0 -86
  79. package/src/rules/no-classname-prop/README.md +0 -47
  80. package/src/rules/no-classname-prop/__tests__/rule.test.tsx +0 -39
  81. package/src/rules/no-classname-prop/index.tsx +0 -34
  82. package/src/rules/no-container-queries/README.md +0 -99
  83. package/src/rules/no-container-queries/__tests__/rule.test.tsx +0 -139
  84. package/src/rules/no-container-queries/index.tsx +0 -94
  85. package/src/rules/no-dynamic-styles/README.md +0 -128
  86. package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +0 -135
  87. package/src/rules/no-dynamic-styles/index.tsx +0 -60
  88. package/src/rules/no-exported-styles/README.md +0 -85
  89. package/src/rules/no-exported-styles/__tests__/rule.test.tsx +0 -216
  90. package/src/rules/no-exported-styles/index.tsx +0 -52
  91. package/src/rules/no-global-styles/README.md +0 -58
  92. package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +0 -33
  93. package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +0 -46
  94. package/src/rules/no-global-styles/index.tsx +0 -82
  95. package/src/rules/no-important-styles/README.md +0 -31
  96. package/src/rules/no-important-styles/__tests__/rule.test.tsx +0 -165
  97. package/src/rules/no-important-styles/index.tsx +0 -70
  98. package/src/rules/no-imported-style-values/README.md +0 -155
  99. package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +0 -491
  100. package/src/rules/no-imported-style-values/index.tsx +0 -188
  101. package/src/rules/no-nested-selectors/README.md +0 -93
  102. package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +0 -335
  103. package/src/rules/no-nested-selectors/index.tsx +0 -99
  104. package/src/rules/no-styled/README.md +0 -90
  105. package/src/rules/no-styled/__tests__/rule.test.tsx +0 -73
  106. package/src/rules/no-styled/index.tsx +0 -45
  107. package/src/rules/no-unsafe-selectors/README.md +0 -368
  108. package/src/rules/no-unsafe-selectors/__tests__/no-ambiguous-pseudos.test.tsx +0 -368
  109. package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +0 -57
  110. package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +0 -73
  111. package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +0 -40
  112. package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +0 -101
  113. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +0 -131
  114. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +0 -132
  115. package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +0 -25
  116. package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +0 -35
  117. package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +0 -257
  118. package/src/rules/no-unsafe-selectors/constants.tsx +0 -91
  119. package/src/rules/no-unsafe-selectors/index.tsx +0 -198
  120. package/src/rules/no-unsafe-selectors/lint-selector.tsx +0 -155
  121. package/src/rules/no-unsafe-selectors/source-position-utils.tsx +0 -55
  122. package/src/rules/no-unsafe-selectors/walk-css-map.tsx +0 -226
  123. package/src/rules/no-unsafe-values/README.md +0 -316
  124. package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +0 -27
  125. package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +0 -37
  126. package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +0 -229
  127. package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +0 -267
  128. package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +0 -52
  129. package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +0 -106
  130. package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +0 -44
  131. package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +0 -48
  132. package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +0 -75
  133. package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +0 -121
  134. package/src/rules/no-unsafe-values/index.tsx +0 -94
  135. package/src/rules/no-unsafe-values/messages.tsx +0 -86
  136. package/src/rules/no-unsafe-values/utils.tsx +0 -387
  137. package/src/rules/use-compiled/README.md +0 -52
  138. package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +0 -73
  139. package/src/rules/use-compiled/__tests__/css.test.tsx +0 -126
  140. package/src/rules/use-compiled/__tests__/imports.test.tsx +0 -158
  141. package/src/rules/use-compiled/__tests__/keyframes.test.tsx +0 -140
  142. package/src/rules/use-compiled/__tests__/pragma.test.tsx +0 -108
  143. package/src/rules/use-compiled/__tests__/styled.test.tsx +0 -114
  144. package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +0 -15
  145. package/src/rules/use-compiled/index.tsx +0 -252
  146. package/src/rules/use-compiled/is-safe.tsx +0 -159
  147. package/src/rules/use-compiled/utils.tsx +0 -33
  148. package/src/rules/utils/create-rule-with-typed-config.tsx +0 -86
  149. package/src/rules/utils/create-rule.tsx +0 -13
  150. package/tsconfig.app.json +0 -47
  151. package/tsconfig.dev.json +0 -45
  152. package/tsconfig.json +0 -25
@@ -1,139 +0,0 @@
1
- import { typescriptEslintTester } from '../../__tests__/utils/_tester';
2
- import rule from '../index';
3
-
4
- typescriptEslintTester.run(
5
- 'no-container-queries',
6
- // @ts-expect-error
7
- rule,
8
- {
9
- valid: [
10
- {
11
- name: 'Basic valid test',
12
- code: `
13
- import { css } from '@compiled/react';
14
- const containerStyles = css({
15
- display: 'flex',
16
- flexDirection: 'column',
17
- });
18
- `,
19
- },
20
- {
21
- name: 'Custom import sources (subtractive)',
22
- code: `
23
- import { css } from '@compiled/react';
24
- const styles = css({
25
- '@container (width > 400px)': {
26
- h2: {
27
- fontSize: '1.5rem',
28
- }
29
- }
30
- });
31
- `,
32
- options: [
33
- {
34
- importSources: [],
35
- },
36
- ],
37
- },
38
- ],
39
- invalid: [
40
- {
41
- name: 'Basic test for @container',
42
- code: `
43
- import { css } from '@compiled/react';
44
-
45
- const styles = css({
46
- '@container (width > 400px)': {
47
- h2: {
48
- fontSize: '1.5rem',
49
- }
50
- }
51
- });
52
- `,
53
- errors: [{ messageId: 'no-container-queries' }],
54
- },
55
- {
56
- name: '@container template literal in styled div',
57
- code: `
58
- import { styled } from '@compiled/react';
59
-
60
- const Component = styled.div({
61
- [\`@container cardContainer (max-width: \${(CARD_MIN_WIDTH + CARD_MARGIN) * 2}px)\`]: {
62
- ul: {
63
- gridTemplateColumns: '1fr 1fr',
64
- },
65
- },
66
- [\`@container cardContainer (max-width: \${CARD_MIN_WIDTH}px)\`]: {
67
- ul: {
68
- gridTemplateColumns: '1fr',
69
- },
70
- },
71
- });
72
- `,
73
- errors: [{ messageId: 'no-container-queries' }, { messageId: 'no-container-queries' }],
74
- },
75
- {
76
- name: '@container in styled div under feature flag',
77
- code: `
78
- import { styled } from "@compiled/react";
79
- const Container = styled.div(
80
- {
81
- display: 'flex',
82
- flexDirection: 'column',
83
- position: 'relative',
84
- zIndex: '0',
85
- '&:empty': {
86
- display: 'none',
87
- },
88
- },
89
- () =>
90
- ff('a-feature-flag') && {
91
- [\`@container cardContainer (max-width: \${DISPLAYING_FIELDS_MIN_CARD_WIDTH}px)\`]: {
92
- width: 0,
93
- overflow: 'hidden',
94
- visibility: 'hidden',
95
- },
96
- },
97
- );
98
- `,
99
- errors: [{ messageId: 'no-container-queries' }],
100
- },
101
- {
102
- name: '@container in a styled div with TS type parameter',
103
- code: `
104
- import { styled } from "@compiled/react";
105
-
106
- const Component = styled.div<{
107
- flexGrow?: number;
108
- }>({
109
- flexGrow: 1,
110
- flexBasis: 0,
111
- "@container AdminCenterPage (min-width: 840px)": {
112
- flexGrow: (props) => props.flexGrow || 1
113
- },
114
- });
115
- `,
116
- errors: [{ messageId: 'no-container-queries' }],
117
- },
118
- {
119
- name: '@container in template literal within styled div with TS type parameter',
120
- code: `
121
- import { styled } from "@compiled/react";
122
- const Container = styled.div<{
123
- paddingBottom: number;
124
- }>({
125
- display: 'flex',
126
- flexDirection: 'column',
127
- boxSizing: 'border-box',
128
-
129
- [\`@container cardContainer (max-width: \${DISPLAYING_FIELDS_MIN_CARD_WIDTH}px)\`]: {
130
- paddingLeft: '10px',
131
- paddingRight: 0,
132
- },
133
- });
134
- `,
135
- errors: [{ messageId: 'no-container-queries' }],
136
- },
137
- ],
138
- },
139
- );
@@ -1,94 +0,0 @@
1
- import estraverse from 'estraverse';
2
-
3
- import { createLintRule } from '../utils/create-rule';
4
- import {
5
- isCss,
6
- getImportSources,
7
- isStyled,
8
- isKeyframes,
9
- isCssMap,
10
- isXcss,
11
- } from '@atlaskit/eslint-utils/is-supported-import';
12
- import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
13
-
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
- },
25
- ];
26
-
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: 'error',
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
-
45
- return {
46
- CallExpression(node) {
47
- const { references } = context.getScope();
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
- }
61
-
62
- if (node.key.type !== 'Literal' && node.key.type !== 'TemplateLiteral') {
63
- return;
64
- }
65
-
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
- }
72
-
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
- },
92
- });
93
-
94
- export default rule;
@@ -1,128 +0,0 @@
1
- Blocks dynamic styles (function expressions) in style declarations.
2
-
3
- This ensures that style declarations:
4
-
5
- - are statically analyzable
6
- - can be efficiently extracted into atomic CSS
7
- - are more readable and deterministic, thus easier to maintain
8
-
9
- ## Examples
10
-
11
- ### Incorrect
12
-
13
- ```tsx
14
- import { styled } from '@compiled/react';
15
-
16
- const Component = styled.div<{ width: number }>((props) => ({
17
- width: props.width,
18
- }));
19
- ```
20
-
21
- ```tsx
22
- import styled from 'styled-components';
23
-
24
- const Component = styled.div<{ width: number }>({
25
- width: (props) => props.width,
26
- });
27
- ```
28
-
29
- ```tsx
30
- import styled from 'styled-components';
31
-
32
- const Container = styled.div<{ hasPadding: boolean }>({
33
- padding: ({ hasPadding }) => (hasPadding ? token('space.100', '8px') : token('space.0', '0px')),
34
- });
35
- ```
36
-
37
- ### Correct
38
-
39
- Define all styles statically, and dynamically apply them using the `css` prop. Use the `style` prop
40
- for values that are only known at runtime.
41
-
42
- For further guidance, consult our
43
- [migration guide](https://atlassian.design/components/eslint-plugin-ui-styling-standard/migration-guide).
44
-
45
- #### Flags
46
-
47
- If you have a style that is on/off depending on a prop, use the `css` prop to conditionally apply
48
- it.
49
-
50
- ```tsx
51
- import { css } from '@compiled/react';
52
-
53
- const baseStyles = css({ padding: token('space.0') });
54
- const hasPaddingStyles = css({ padding: token('space.100') });
55
-
56
- const Container = ({ hasPadding = false }: { hasPadding?: boolean }) => {
57
- return <div css={[baseStyles, hasPadding && hasPaddingStyles]} />;
58
- };
59
- ```
60
-
61
- #### Variants
62
-
63
- If you have variants which are known ahead of time, use `cssMap` to define them and the `css` prop
64
- to conditionally apply it.
65
-
66
- ```tsx
67
- import { css } from '@compiled/react';
68
-
69
- const baseStyles = css({ width: 100 });
70
- const stylesMap = cssMap({
71
- primary: {
72
- background: token('color.background.brand.bold'),
73
- '&:hover': { background: token('color.background.brand.bold.hovered') },
74
- },
75
- error: {
76
- background: token('color.background.warning.bold'),
77
- '&:hover': { background: token('color.background.warning.bold.hovered') },
78
- }
79
- });
80
-
81
- const Wrapper = ({ appearance = 'primary' }: { appearance?: 'primary' | 'error' }) => (
82
- <div css={[baseStyles, stylesMap[appearance]} />
83
- );
84
- ```
85
-
86
- #### Dynamic values
87
-
88
- If you have styles which are truly dynamic, use the `style` prop.
89
-
90
- This approach should be used as a last resort.
91
-
92
- ```tsx
93
- import { css } from '@compiled/react';
94
-
95
- const Component = ({ width }: { width: number }) => {
96
- return <div style={{ width }} />;
97
- };
98
- ```
99
-
100
- ```tsx
101
- import { css } from '@compiled/react';
102
-
103
- const containerStyles = css({
104
- '&::before': {
105
- width: 'var(--ak-example-width)',
106
- },
107
- });
108
-
109
- function Example({ width }: { width: number }) {
110
- return <div css={containerStyles} style={{ '--ak-example-width': `${width}px` }} />;
111
- }
112
- ```
113
-
114
- ## Options
115
-
116
- ### `importSources: string[]`
117
-
118
- By default, this rule will check styles using:
119
-
120
- - `@atlaskit/css`
121
- - `@atlaskit/primitives`
122
- - `@compiled/react`
123
- - `@emotion/react`
124
- - `@emotion/core`
125
- - `@emotion/styled`
126
- - `styled-components`
127
-
128
- Override this list with the `importSources` option, which accepts an array of package names.
@@ -1,135 +0,0 @@
1
- import { tester } from '../../__tests__/utils/_tester';
2
- import rule from '../index';
3
-
4
- tester.run('no-dynamic-styles', rule, {
5
- valid: [
6
- {
7
- name: 'arrow function expression outside of a styling context',
8
- code: `
9
- const arrowFunctionExpression = (props) => ({
10
- width: props.width
11
- });
12
- `,
13
- },
14
- {
15
- name: 'function expression outside of a styling context',
16
- code: `
17
- const functionExpression = function(props) {
18
- return {
19
- height: props.height
20
- };
21
- }
22
- `,
23
- },
24
- {
25
- name: 'function expressions as object values outside of a styling context',
26
- code: `
27
- const styles = {
28
- width: props => props.width,
29
- height: function(props) { return props.height }
30
- };
31
- `,
32
- },
33
- {
34
- name: "importSources doesn't include the styling library",
35
- code: `
36
- import { css } from '@compiled/react';
37
-
38
- const styles = css(props => ({
39
- width: props.width
40
- }));
41
- `,
42
- options: [{ importSources: [] }],
43
- },
44
- ],
45
- invalid: [
46
- {
47
- name: 'function as argument to css',
48
- code: `
49
- import { css } from '@compiled/react';
50
-
51
- const styles = css(props => ({
52
- width: props.width
53
- }));
54
- `,
55
- errors: [{ messageId: 'no-dynamic-styles' }],
56
- },
57
- {
58
- name: 'function as argument to styled',
59
- code: `
60
- import { styled } from '@compiled/react';
61
-
62
- const Component = styled.div(props => ({
63
- width: props.width
64
- }));
65
- `,
66
- errors: [{ messageId: 'no-dynamic-styles' }],
67
- },
68
- {
69
- name: 'multiple functions as arguments',
70
- code: `
71
- import { styled } from '@compiled/react';
72
-
73
- const Component = styled.div(
74
- props => ({
75
- width: props.width
76
- }),
77
- { color: 'red' },
78
- props => ({
79
- height: props.height
80
- })
81
- );
82
- `,
83
- errors: [{ messageId: 'no-dynamic-styles' }, { messageId: 'no-dynamic-styles' }],
84
- },
85
- {
86
- name: 'functions as values',
87
- code: `
88
- import { styled } from '@compiled/react';
89
-
90
- const Component = styled.div({
91
- width: props => props.width,
92
- height: function(props) { return props.height; }
93
- });
94
- `,
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: `
100
- import { css } from 'my-package';
101
-
102
- const styles = css(props => ({
103
- width: props.width
104
- }));
105
- `,
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: `
113
- import { css } from '@compiled/react';
114
-
115
- const styles = css({
116
- height: \`\${(props) => props.height}px\`,
117
- });
118
- `,
119
- errors: [{ messageId: 'no-dynamic-styles' }],
120
- },
121
- {
122
- name: 'dynamic styles when using styled and overriding another component',
123
- code: `
124
- import { styled } from '@compiled/react';
125
- import { BaseComponent } from './base-component';
126
-
127
- const Component = styled(BaseComponent)({
128
- width: props => props.width,
129
- height: function(props) { return props.height; }
130
- });
131
- `,
132
- errors: [{ messageId: 'no-dynamic-styles' }, { messageId: 'no-dynamic-styles' }],
133
- },
134
- ],
135
- });
@@ -1,60 +0,0 @@
1
- import esquery from 'esquery';
2
- import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
3
-
4
- import {
5
- getImportSources,
6
- hasStyleObjectArguments,
7
- } from '@atlaskit/eslint-utils/is-supported-import';
8
-
9
- import { createLintRule } from '../utils/create-rule';
10
-
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
- },
22
- ];
23
-
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: 'error',
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.getScope();
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
- },
58
- });
59
-
60
- export default rule;
@@ -1,85 +0,0 @@
1
- Blocks exports of `css`, `cssMap`, `keyframes`, `styled`, `xcss` styles, which are unsafe.
2
-
3
- Use alongside `no-imported-style-values` which blocks consumption of imported styles.
4
-
5
- Compiled style declarations are null at runtime, so using imported styles will cause unexpected
6
- errors.
7
-
8
- Co-locate style definitions with their usage instead. This will also improve code readability,
9
- maintainability and build performance.
10
-
11
- ## Examples
12
-
13
- ### Incorrect
14
-
15
- ```tsx
16
- import { css } from '@compiled/react';
17
-
18
- export const styles = css({});
19
-
20
- export default css({});
21
- ```
22
-
23
- ```tsx
24
- import { keyframes } from '@compiled/react';
25
-
26
- export const animation = keyframes({});
27
-
28
- export default keyframes({});
29
- ```
30
-
31
- ```tsx
32
- import { css } from '@compiled/react';
33
- import { token } from '@atlaskit/tokens';
34
-
35
- const colorStyles = css({
36
- color: token('color.text'),
37
- });
38
-
39
- const styles = {
40
- primary: {
41
- text: {
42
- color,
43
- },
44
- },
45
- };
46
-
47
- export default styles.primary.text.color;
48
- ```
49
-
50
- ### Correct
51
-
52
- Co-locate styles with components to improve code readability, linting, and build performance.
53
-
54
- ```tsx
55
- import { css } from '@compiled/react';
56
-
57
- const styles = css({});
58
-
59
- export const Component = () => <div css={styles} />;
60
- ```
61
-
62
- ```tsx
63
- import { css, keyframes } from '@compiled/react';
64
-
65
- const animation = keyframes({});
66
- const styles = css({ animate: `${animation} 1s ease-in` });
67
-
68
- export const Component = () => <div css={styles} />;
69
- ```
70
-
71
- ## Options
72
-
73
- ### `importSources: string[]`
74
-
75
- By default, this rule will check styles using:
76
-
77
- - `@atlaskit/css`
78
- - `@atlaskit/primitives`
79
- - `@compiled/react`
80
- - `@emotion/react`
81
- - `@emotion/core`
82
- - `@emotion/styled`
83
- - `styled-components`
84
-
85
- Override this list with the `importSources` option, which accepts an array of package names.