@atlaskit/eslint-plugin-ui-styling-standard 0.11.6 → 0.13.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 (61) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +2 -0
  3. package/constellation/index/overview.mdx +3 -1
  4. package/constellation/no-global-styles/usage.mdx +59 -0
  5. package/constellation/use-compiled/usage.mdx +54 -0
  6. package/dist/cjs/presets/all.codegen.js +3 -1
  7. package/dist/cjs/presets/recommended.codegen.js +3 -1
  8. package/dist/cjs/rules/index.codegen.js +6 -2
  9. package/dist/cjs/rules/no-global-styles/index.js +100 -0
  10. package/dist/cjs/rules/use-compiled/index.js +257 -0
  11. package/dist/cjs/rules/use-compiled/is-safe.js +130 -0
  12. package/dist/cjs/rules/use-compiled/utils.js +26 -0
  13. package/dist/es2019/presets/all.codegen.js +3 -1
  14. package/dist/es2019/presets/recommended.codegen.js +3 -1
  15. package/dist/es2019/rules/index.codegen.js +6 -2
  16. package/dist/es2019/rules/no-global-styles/index.js +67 -0
  17. package/dist/es2019/rules/use-compiled/index.js +182 -0
  18. package/dist/es2019/rules/use-compiled/is-safe.js +118 -0
  19. package/dist/es2019/rules/use-compiled/utils.js +15 -0
  20. package/dist/esm/presets/all.codegen.js +3 -1
  21. package/dist/esm/presets/recommended.codegen.js +3 -1
  22. package/dist/esm/rules/index.codegen.js +6 -2
  23. package/dist/esm/rules/no-global-styles/index.js +94 -0
  24. package/dist/esm/rules/use-compiled/index.js +250 -0
  25. package/dist/esm/rules/use-compiled/is-safe.js +121 -0
  26. package/dist/esm/rules/use-compiled/utils.js +17 -0
  27. package/dist/types/index.codegen.d.ts +4 -0
  28. package/dist/types/presets/all.codegen.d.ts +3 -1
  29. package/dist/types/presets/recommended.codegen.d.ts +3 -1
  30. package/dist/types/rules/index.codegen.d.ts +2 -0
  31. package/dist/types/rules/no-global-styles/index.d.ts +2 -0
  32. package/dist/types/rules/use-compiled/index.d.ts +3 -0
  33. package/dist/types/rules/use-compiled/is-safe.d.ts +10 -0
  34. package/dist/types/rules/use-compiled/utils.d.ts +6 -0
  35. package/dist/types-ts4.5/index.codegen.d.ts +4 -0
  36. package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -1
  37. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +3 -1
  38. package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
  39. package/dist/types-ts4.5/rules/no-global-styles/index.d.ts +2 -0
  40. package/dist/types-ts4.5/rules/use-compiled/index.d.ts +3 -0
  41. package/dist/types-ts4.5/rules/use-compiled/is-safe.d.ts +10 -0
  42. package/dist/types-ts4.5/rules/use-compiled/utils.d.ts +6 -0
  43. package/package.json +3 -2
  44. package/src/presets/all.codegen.tsx +3 -1
  45. package/src/presets/recommended.codegen.tsx +3 -1
  46. package/src/rules/index.codegen.tsx +5 -1
  47. package/src/rules/no-global-styles/README.md +56 -0
  48. package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +33 -0
  49. package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +46 -0
  50. package/src/rules/no-global-styles/index.tsx +85 -0
  51. package/src/rules/use-compiled/README.md +49 -0
  52. package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +73 -0
  53. package/src/rules/use-compiled/__tests__/css.test.tsx +126 -0
  54. package/src/rules/use-compiled/__tests__/imports.test.tsx +163 -0
  55. package/src/rules/use-compiled/__tests__/keyframes.test.tsx +140 -0
  56. package/src/rules/use-compiled/__tests__/pragma.test.tsx +108 -0
  57. package/src/rules/use-compiled/__tests__/styled.test.tsx +114 -0
  58. package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +15 -0
  59. package/src/rules/use-compiled/index.tsx +275 -0
  60. package/src/rules/use-compiled/is-safe.tsx +163 -0
  61. package/src/rules/use-compiled/utils.tsx +37 -0
@@ -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::a0c326baf3aa4e87ac809b303ba34682>>
3
+ * @codegen <<SignedSource::9ac05c3cbd30f6209164b7a24f7a7a19>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  declare const _default: {
@@ -15,10 +15,12 @@ declare const _default: {
15
15
  '@atlaskit/ui-styling-standard/no-container-queries': string;
16
16
  '@atlaskit/ui-styling-standard/no-dynamic-styles': string;
17
17
  '@atlaskit/ui-styling-standard/no-exported-styles': string;
18
+ '@atlaskit/ui-styling-standard/no-global-styles': string;
18
19
  '@atlaskit/ui-styling-standard/no-important-styles': string;
19
20
  '@atlaskit/ui-styling-standard/no-imported-style-values': string;
20
21
  '@atlaskit/ui-styling-standard/no-nested-selectors': string;
21
22
  '@atlaskit/ui-styling-standard/no-unsafe-values': string;
23
+ '@atlaskit/ui-styling-standard/use-compiled': string;
22
24
  '@atlaskit/design-system/consistent-css-prop-usage': (string | {
23
25
  excludeReactComponents: boolean;
24
26
  })[];
@@ -8,9 +8,11 @@ declare const _default: {
8
8
  'no-container-queries': import("eslint").Rule.RuleModule;
9
9
  'no-dynamic-styles': import("eslint").Rule.RuleModule;
10
10
  'no-exported-styles': import("eslint").Rule.RuleModule;
11
+ 'no-global-styles': import("eslint").Rule.RuleModule;
11
12
  'no-important-styles': import("eslint").Rule.RuleModule;
12
13
  'no-imported-style-values': import("eslint").Rule.RuleModule;
13
14
  'no-nested-selectors': import("eslint").Rule.RuleModule;
14
15
  'no-unsafe-values': import("eslint").Rule.RuleModule;
16
+ 'use-compiled': import("eslint").Rule.RuleModule;
15
17
  };
16
18
  export default _default;
@@ -0,0 +1,2 @@
1
+ export declare const rule: import("eslint").Rule.RuleModule;
2
+ export default rule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ export declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,10 @@
1
+ import type { Rule, Scope } from 'eslint';
2
+ import type * as ESTree from 'eslint-codemod-utils';
3
+ export declare function isSafeUsage({ context, specifier, supportedImports, }: {
4
+ context: Rule.RuleContext;
5
+ specifier: ESTree.ImportSpecifier;
6
+ supportedImports: Set<string>;
7
+ }): boolean;
8
+ export declare function isSafeKeyframes(keyframes: Scope.Variable): boolean;
9
+ export declare function isSafeCss(css: Scope.Variable): boolean;
10
+ export declare function isSafeStyled(styled: Scope.Variable): boolean;
@@ -0,0 +1,6 @@
1
+ import type { Rule } from 'eslint';
2
+ import type * as ESTree from 'eslint-codemod-utils';
3
+ export declare function getFirstImportFromSource(context: Rule.RuleContext, source: string): ESTree.ImportDeclaration | undefined;
4
+ export declare function isImportSpecifier(specifier: ESTree.Node): specifier is ESTree.ImportSpecifier;
5
+ export declare function isImportDefaultSpecifier(specifier: ESTree.Node): specifier is ESTree.ImportDefaultSpecifier;
6
+ export declare function isImportNamespaceSpecifier(specifier: ESTree.Node): specifier is ESTree.ImportNamespaceSpecifier;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-ui-styling-standard",
3
- "version": "0.11.6",
3
+ "version": "0.13.0",
4
4
  "author": "Atlassian Pty Ltd",
5
5
  "description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
6
6
  "license": "Apache-2.0",
@@ -51,13 +51,14 @@
51
51
  "devDependencies": {
52
52
  "@af/formatting": "*",
53
53
  "@atlaskit/ds-lib": "^2.3.0",
54
- "@atlaskit/eslint-plugin-design-system": "^10.0.0",
54
+ "@atlaskit/eslint-plugin-design-system": "^10.2.0",
55
55
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
56
56
  "@atlassian/codegen": "*",
57
57
  "@compiled/eslint-plugin": "^0.13.6",
58
58
  "@types/eslint": "^8.56.6",
59
59
  "@types/estraverse": "^5.1.7",
60
60
  "eslint": "^8.49.0",
61
+ "json-schema-to-ts": "^3.1.0",
61
62
  "lodash": "^4.17.21",
62
63
  "ts-node": "^10.9.1",
63
64
  "tsconfig-paths": "^4.2.0",
@@ -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::a0c326baf3aa4e87ac809b303ba34682>>
3
+ * @codegen <<SignedSource::9ac05c3cbd30f6209164b7a24f7a7a19>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -15,10 +15,12 @@ export default {
15
15
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
16
16
  '@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
17
17
  '@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
18
+ '@atlaskit/ui-styling-standard/no-global-styles': 'warn',
18
19
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
19
20
  '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
20
21
  '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
21
22
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
23
+ '@atlaskit/ui-styling-standard/use-compiled': 'warn',
22
24
  '@atlaskit/design-system/consistent-css-prop-usage': [
23
25
  'warn',
24
26
  { excludeReactComponents: true },
@@ -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::a0c326baf3aa4e87ac809b303ba34682>>
3
+ * @codegen <<SignedSource::9ac05c3cbd30f6209164b7a24f7a7a19>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -15,10 +15,12 @@ export default {
15
15
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
16
16
  '@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
17
17
  '@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
18
+ '@atlaskit/ui-styling-standard/no-global-styles': 'warn',
18
19
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
19
20
  '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
20
21
  '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
21
22
  '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
23
+ '@atlaskit/ui-styling-standard/use-compiled': 'warn',
22
24
  '@atlaskit/design-system/consistent-css-prop-usage': [
23
25
  'warn',
24
26
  { excludeReactComponents: true },
@@ -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::78ffc29d20fd2fe3727a620cb4ddf192>>
3
+ * @codegen <<SignedSource::3cea683df6e31f816db56abf1fd65c1e>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import atlaskitTheme from './atlaskit-theme';
@@ -12,10 +12,12 @@ import noClassnameProp from './no-classname-prop';
12
12
  import noContainerQueries from './no-container-queries';
13
13
  import noDynamicStyles from './no-dynamic-styles';
14
14
  import noExportedStyles from './no-exported-styles';
15
+ import noGlobalStyles from './no-global-styles';
15
16
  import noImportantStyles from './no-important-styles';
16
17
  import noImportedStyleValues from './no-imported-style-values';
17
18
  import noNestedSelectors from './no-nested-selectors';
18
19
  import noUnsafeValues from './no-unsafe-values';
20
+ import useCompiled from './use-compiled';
19
21
 
20
22
  export default {
21
23
  'atlaskit-theme': atlaskitTheme,
@@ -27,8 +29,10 @@ export default {
27
29
  'no-container-queries': noContainerQueries,
28
30
  'no-dynamic-styles': noDynamicStyles,
29
31
  'no-exported-styles': noExportedStyles,
32
+ 'no-global-styles': noGlobalStyles,
30
33
  'no-important-styles': noImportantStyles,
31
34
  'no-imported-style-values': noImportedStyleValues,
32
35
  'no-nested-selectors': noNestedSelectors,
33
36
  'no-unsafe-values': noUnsafeValues,
37
+ 'use-compiled': useCompiled,
34
38
  };
@@ -0,0 +1,56 @@
1
+ This rule prevents global styles through CSS-in-JS or CSS module imports.
2
+
3
+ Requiring local definition of styles helps to ensure that style dependencies are statically resolvable.
4
+
5
+ ## Examples
6
+
7
+ ### Incorrect
8
+
9
+ ```tsx
10
+ import { Global } from '@emotion/react';
11
+
12
+ <Global
13
+ styles={{
14
+ '.some-class': {
15
+ fontSize: 50,
16
+ textAlign: 'center',
17
+ },
18
+ }}
19
+ />;
20
+ ```
21
+
22
+ ```tsx
23
+ import { createGlobalStyle } from 'styled-components';
24
+
25
+ const GlobalStyle = createGlobalStyle({
26
+ body: {
27
+ margin: 0,
28
+ },
29
+ });
30
+ ```
31
+
32
+ ```tsx
33
+ import { injectGlobal } from 'styled-components';
34
+
35
+ injectGlobal({
36
+ body: {
37
+ margin: 0,
38
+ },
39
+ });
40
+ ```
41
+
42
+ ```tsx
43
+ <style>
44
+ {`
45
+ .some-class {
46
+ color: red;
47
+ }
48
+ `}
49
+ </style>
50
+ ```
51
+
52
+ ### Correct
53
+
54
+ ```tsx
55
+ import '@atlaskit/css-reset';
56
+ ```
@@ -0,0 +1,33 @@
1
+ import { tester } from '../../__tests__/utils/_tester';
2
+ import rule from '../index';
3
+
4
+ tester.run('no-css-modules', rule, {
5
+ valid: [
6
+ "import 'styles-css';",
7
+ "import 'less';",
8
+ "import 'sass-module';",
9
+ "import 'something-scss-something';",
10
+ ],
11
+ invalid: [
12
+ {
13
+ name: '.css import',
14
+ code: "import 'styles.css';",
15
+ errors: [{ messageId: 'no-css-modules' }],
16
+ },
17
+ {
18
+ name: '.less import',
19
+ code: "import 'styles.less';",
20
+ errors: [{ messageId: 'no-css-modules' }],
21
+ },
22
+ {
23
+ name: '.sass import',
24
+ code: "import 'styles.sass';",
25
+ errors: [{ messageId: 'no-css-modules' }],
26
+ },
27
+ {
28
+ name: '.scss import',
29
+ code: "import 'styles.scss';",
30
+ errors: [{ messageId: 'no-css-modules' }],
31
+ },
32
+ ],
33
+ });
@@ -0,0 +1,46 @@
1
+ import { tester } from '../../__tests__/utils/_tester';
2
+ import rule from '../index';
3
+
4
+ tester.run('no-global-styles', rule, {
5
+ valid: [
6
+ "import { css } from '@emotion/react';",
7
+ "import { keyframes } from '@emotion/core';",
8
+ "import styled from 'styled-components';",
9
+ ],
10
+ invalid: [
11
+ {
12
+ name: '[@emotion/react] Global',
13
+ code: "import { Global } from '@emotion/react';",
14
+ errors: [{ messageId: 'no-global-styles' }],
15
+ },
16
+ {
17
+ name: '[@emotion/core] Global',
18
+ code: "import { Global } from '@emotion/core';",
19
+ errors: [{ messageId: 'no-global-styles' }],
20
+ },
21
+ {
22
+ name: '[styled-components] injectGlobal',
23
+ code: "import { injectGlobal } from 'styled-components';",
24
+ errors: [{ messageId: 'no-global-styles' }],
25
+ },
26
+ {
27
+ name: '[styled-components] createGlobalStyle',
28
+ code: "import { createGlobalStyle } from 'styled-components';",
29
+ errors: [{ messageId: 'no-global-styles' }],
30
+ },
31
+ {
32
+ name: 'aliasing',
33
+ code: "import { Global as EmotionGlobal } from '@emotion/react';",
34
+ errors: [{ messageId: 'no-global-styles' }],
35
+ },
36
+ {
37
+ name: 'style tag',
38
+ code: `
39
+ <style>
40
+ {'.my-class { color: red; }'}
41
+ </style>
42
+ `,
43
+ errors: [{ messageId: 'no-global-styles' }],
44
+ },
45
+ ],
46
+ });
@@ -0,0 +1,85 @@
1
+ import type * as ESTree from 'eslint-codemod-utils';
2
+
3
+ import { createLintRule } from '../utils/create-rule';
4
+
5
+ const restrictedFileTypes = ['.css', '.less', '.sass', '.scss'];
6
+
7
+ const restrictedImports = {
8
+ '@emotion/core': ['Global'],
9
+ '@emotion/react': ['Global'],
10
+ 'styled-components': ['createGlobalStyle', 'injectGlobal'],
11
+ };
12
+
13
+ type RestrictedImportSource = keyof typeof restrictedImports;
14
+ function isRestrictedImportSource(
15
+ importSource: string,
16
+ ): importSource is RestrictedImportSource {
17
+ return importSource in restrictedImports;
18
+ }
19
+
20
+ export const rule = createLintRule({
21
+ meta: {
22
+ name: 'no-global-styles',
23
+ docs: {
24
+ description:
25
+ 'Prevents global styles through CSS-in-JS or CSS module imports',
26
+ recommended: true,
27
+ severity: 'warn',
28
+ },
29
+ messages: {
30
+ 'no-global-styles': 'Global styles are not allowed.',
31
+ 'no-css-modules': 'Importing CSS files is not allowed.',
32
+ },
33
+ type: 'problem',
34
+ },
35
+ create(context) {
36
+ function checkFileType(node: ESTree.ImportDeclaration) {
37
+ const importSource = node.source.value as string;
38
+ if (restrictedFileTypes.some((suffix) => importSource.endsWith(suffix))) {
39
+ context.report({
40
+ node: node.source,
41
+ messageId: 'no-css-modules',
42
+ });
43
+ }
44
+ }
45
+
46
+ function checkImports(node: ESTree.ImportDeclaration) {
47
+ const importSource = node.source.value as string;
48
+ if (!isRestrictedImportSource(importSource)) {
49
+ return;
50
+ }
51
+
52
+ for (const importName of restrictedImports[importSource]) {
53
+ const specifier = node.specifiers
54
+ .filter(isImportSpecifier)
55
+ .find((specifier) => specifier.imported.name === importName);
56
+
57
+ if (specifier) {
58
+ context.report({
59
+ node: specifier,
60
+ messageId: 'no-global-styles',
61
+ });
62
+ }
63
+ }
64
+ }
65
+
66
+ return {
67
+ ImportDeclaration(node: ESTree.ImportDeclaration) {
68
+ checkFileType(node);
69
+ checkImports(node);
70
+ },
71
+ 'JSXOpeningElement[name.name="style"]'(node: ESTree.Node) {
72
+ context.report({
73
+ node,
74
+ messageId: 'no-global-styles',
75
+ });
76
+ },
77
+ };
78
+ },
79
+ });
80
+
81
+ export default rule;
82
+
83
+ function isImportSpecifier(node: ESTree.Node): node is ESTree.ImportSpecifier {
84
+ return node.type === 'ImportSpecifier';
85
+ }
@@ -0,0 +1,49 @@
1
+ Ensures usage of `@compiled/react` over other CSS-in-JS libraries like Emotion or styled-components.
2
+
3
+ **WARNING**
4
+ It may be unsafe to mix usages of `@compiled/react` with other CSS-in-JS libraries on the same component. When converting to `@compiled/react` verify ALL changes. For this reason, the auto-fixer has been disabled by default, but it may be useful to enable to empower a migration.
5
+
6
+ ## Examples
7
+
8
+ ### Incorrect
9
+
10
+ ```js
11
+ /** @jsx jsx */
12
+ import { css } from '@emotion/core';
13
+ import { jsx } from '@emotion/react';
14
+ import styled from '@emotion/styled';
15
+ ```
16
+
17
+ ```js
18
+ import styled, { css } from 'styled-components';
19
+ ```
20
+
21
+ ### Correct
22
+
23
+ We expect usage of `xcss` with `@atlaskit/primitives` when working with Primitives, and `css` with `@compiled/react` when working with custom or native code. 
24
+
25
+ ```js
26
+ /** @jsx jsx */
27
+ import { jsx, css, styled } from '@compiled/react';
28
+
29
+ const styles = css({ color: 'var(--ds-color-text)' });
30
+ export default () => <div css={styles}>…</div>
31
+ ```
32
+
33
+ ```js
34
+ import { xcss, Box } from '@atlaskit/primitives';
35
+
36
+ const styles = xcss({ color: 'color.text' });
37
+ export default () => <Box xcss={styles}>…</Box>
38
+ ```
39
+
40
+ ## Options
41
+
42
+ ### `canAutoFix: boolean`
43
+
44
+ Determines whether or not the auto-fixer is enabled.
45
+
46
+ Defaults to `false` due to safety concerns when mixing Compiled and other CSS-in-JS libraries on the same component.
47
+
48
+ Even when enabled, the auto-fixer will only convert usages that are deemed safe.
49
+ Currently this is limited to purely static styles where all keys and values are simple literals.
@@ -0,0 +1,73 @@
1
+ import type { RuleTester } from 'eslint';
2
+ import { tester } from '../../__tests__/utils/_tester';
3
+ import rule from '../index';
4
+
5
+ const invalid: RuleTester.InvalidTestCase[] = [
6
+ {
7
+ name: 'css API',
8
+ code: `
9
+ import { css } from '@emotion/react';
10
+
11
+ const Component = css({
12
+ color: 'red',
13
+ });
14
+ `,
15
+ errors: [{ messageId: 'use-compiled' }],
16
+ },
17
+ {
18
+ name: 'imports',
19
+ code: `
20
+ import { css as c, keyframes as kf } from '@emotion/core';
21
+ `,
22
+ errors: [{ messageId: 'use-compiled' }],
23
+ },
24
+ {
25
+ name: `keyframes API`,
26
+ code: `
27
+ import { keyframes } from 'styled-components';
28
+
29
+ const fadeIn = keyframes({
30
+ from: {
31
+ opacity: 0,
32
+ },
33
+ to: {
34
+ opacity: 1,
35
+ }
36
+ });
37
+ `,
38
+ errors: [{ messageId: 'use-compiled' }],
39
+ },
40
+ {
41
+ name: 'pragma fix',
42
+ code: `
43
+ /** @jsxImportSource @emotion/react */
44
+
45
+ import { css } from '@compiled/react';
46
+ `,
47
+ errors: [{ messageId: 'use-compiled' }],
48
+ },
49
+ {
50
+ name: `styles are a plain object with literal values`,
51
+ code: `
52
+ import styled from '@emotion/styled';
53
+
54
+ const Component = styled.div({
55
+ color: 'red',
56
+ });
57
+ `,
58
+ errors: [{ messageId: 'use-compiled' }],
59
+ },
60
+ ];
61
+
62
+ tester.run('canAutoFix is not provided', rule, {
63
+ valid: [],
64
+ invalid,
65
+ });
66
+
67
+ tester.run('canAutoFix is false', rule, {
68
+ valid: [],
69
+ invalid: invalid.map((testCase) => ({
70
+ ...testCase,
71
+ options: [{ canAutoFix: false }],
72
+ })),
73
+ });
@@ -0,0 +1,126 @@
1
+ import { tester } from '../../__tests__/utils/_tester';
2
+ import rule from '../index';
3
+
4
+ const importSources = ['@emotion/core', '@emotion/react', 'styled-components'];
5
+
6
+ tester.run('css API - fixable', rule, {
7
+ valid: [],
8
+ invalid: importSources.flatMap((importSource) => [
9
+ {
10
+ name: `[${importSource}] styles are a plain object with literal values`,
11
+ code: `
12
+ import { css } from '${importSource}';
13
+
14
+ const Component = css({
15
+ color: 'red',
16
+ });
17
+ `,
18
+ output: `
19
+ import { css } from '@compiled/react';
20
+
21
+ const Component = css({
22
+ color: 'red',
23
+ });
24
+ `,
25
+ errors: [{ messageId: 'use-compiled' }],
26
+ options: [{ canAutoFix: true }],
27
+ },
28
+ ]),
29
+ });
30
+
31
+ /**
32
+ * These test cases have no auto-fix because we are considering
33
+ * them unsafe to automatically convert.
34
+ */
35
+ tester.run('css API - not fixable', rule, {
36
+ valid: [],
37
+ invalid: importSources.flatMap((importSource) => [
38
+ {
39
+ name: `[${importSource}] function as style argument`,
40
+ code: `
41
+ import { css } from '${importSource}';
42
+
43
+ const Component = css(() => ({
44
+ color: 'red',
45
+ }));
46
+ `,
47
+ errors: [{ messageId: 'use-compiled' }],
48
+ options: [{ canAutoFix: true }],
49
+ },
50
+ {
51
+ name: `[${importSource}] function as style object value`,
52
+ code: `
53
+ import { css } from '${importSource}';
54
+
55
+ const Component = css({
56
+ color: () => 'red',
57
+ });
58
+ `,
59
+ errors: [{ messageId: 'use-compiled' }],
60
+ options: [{ canAutoFix: true }],
61
+ },
62
+ {
63
+ name: `[${importSource}] identifier as style object value`,
64
+ code: `
65
+ import { css } from '${importSource}';
66
+
67
+ const textColor = 'red';
68
+ const Component = css({
69
+ color: textColor,
70
+ });
71
+ `,
72
+ errors: [{ messageId: 'use-compiled' }],
73
+ options: [{ canAutoFix: true }],
74
+ },
75
+ {
76
+ /**
77
+ * We could auto-fix this safely but intentionally
78
+ * keeping this rule very simple for now.
79
+ */
80
+ name: `[${importSource}] function call as style object value`,
81
+ code: `
82
+ import { css } from '${importSource}';
83
+ import { token } from '@atlaskit/tokens';
84
+
85
+ const Component = css({
86
+ color: token('color.text'),
87
+ });
88
+ `,
89
+ errors: [{ messageId: 'use-compiled' }],
90
+ options: [{ canAutoFix: true }],
91
+ },
92
+ {
93
+ name: `[${importSource}] with unsupported named import`,
94
+ code: `
95
+ import { css, type CSSObject } from '${importSource}';
96
+
97
+ const Component = css({
98
+ color: 'red',
99
+ });
100
+ `,
101
+ errors: [{ messageId: 'use-compiled' }],
102
+ options: [{ canAutoFix: true }],
103
+ },
104
+ {
105
+ name: `[${importSource}] with unsafe usage of other import`,
106
+ code: `
107
+ import { css, keyframes } from '${importSource}';
108
+
109
+ const Component = css({
110
+ color: 'red',
111
+ });
112
+
113
+ const animation = keyframes({
114
+ from: {
115
+ opacity: () => 0
116
+ },
117
+ to: {
118
+ opacity: 1
119
+ }
120
+ })
121
+ `,
122
+ errors: [{ messageId: 'use-compiled' }],
123
+ options: [{ canAutoFix: true }],
124
+ },
125
+ ]),
126
+ });