@atlaskit/eslint-plugin-ui-styling-standard 0.7.0 → 0.7.2

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 (53) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +17 -16
  3. package/constellation/index/overview.mdx +17 -16
  4. package/constellation/no-container-queries/usage.mdx +50 -0
  5. package/dist/cjs/presets/all.codegen.js +2 -1
  6. package/dist/cjs/presets/recommended.codegen.js +2 -1
  7. package/dist/cjs/rules/convert-props-syntax/index.js +1 -1
  8. package/dist/cjs/rules/index.codegen.js +3 -1
  9. package/dist/cjs/rules/local-cx-xcss/index.js +1 -1
  10. package/dist/cjs/rules/no-container-queries/index.js +76 -0
  11. package/dist/cjs/rules/no-important-styles/index.js +1 -1
  12. package/dist/es2019/presets/all.codegen.js +2 -1
  13. package/dist/es2019/presets/recommended.codegen.js +2 -1
  14. package/dist/es2019/rules/convert-props-syntax/index.js +1 -1
  15. package/dist/es2019/rules/index.codegen.js +3 -1
  16. package/dist/es2019/rules/local-cx-xcss/index.js +1 -1
  17. package/dist/es2019/rules/no-container-queries/index.js +70 -0
  18. package/dist/es2019/rules/no-important-styles/index.js +1 -1
  19. package/dist/esm/presets/all.codegen.js +2 -1
  20. package/dist/esm/presets/recommended.codegen.js +2 -1
  21. package/dist/esm/rules/convert-props-syntax/index.js +1 -1
  22. package/dist/esm/rules/index.codegen.js +3 -1
  23. package/dist/esm/rules/local-cx-xcss/index.js +1 -1
  24. package/dist/esm/rules/no-container-queries/index.js +69 -0
  25. package/dist/esm/rules/no-important-styles/index.js +1 -1
  26. package/dist/types/index.codegen.d.ts +2 -0
  27. package/dist/types/presets/all.codegen.d.ts +2 -1
  28. package/dist/types/presets/recommended.codegen.d.ts +2 -1
  29. package/dist/types/rules/index.codegen.d.ts +1 -0
  30. package/dist/types/rules/no-container-queries/index.d.ts +2 -0
  31. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  32. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  33. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
  34. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  35. package/dist/types-ts4.5/rules/no-container-queries/index.d.ts +2 -0
  36. package/package.json +3 -2
  37. package/src/presets/all.codegen.tsx +2 -1
  38. package/src/presets/recommended.codegen.tsx +2 -1
  39. package/src/rules/convert-props-syntax/index.tsx +4 -1
  40. package/src/rules/index.codegen.tsx +3 -1
  41. package/src/rules/local-cx-xcss/index.tsx +4 -1
  42. package/src/rules/no-container-queries/README.md +48 -0
  43. package/src/rules/no-container-queries/__tests__/rule.test.tsx +142 -0
  44. package/src/rules/no-container-queries/index.tsx +100 -0
  45. package/src/rules/no-important-styles/index.tsx +1 -1
  46. package/tsconfig.app.json +3 -0
  47. package/dist/cjs/rules/utils/is-supported-import.js +0 -160
  48. package/dist/es2019/rules/utils/is-supported-import.js +0 -150
  49. package/dist/esm/rules/utils/is-supported-import.js +0 -154
  50. package/dist/types/rules/utils/is-supported-import.d.ts +0 -46
  51. package/dist/types-ts4.5/rules/utils/is-supported-import.d.ts +0 -46
  52. package/src/rules/utils/README.md +0 -1
  53. package/src/rules/utils/is-supported-import.tsx +0 -227
@@ -0,0 +1,69 @@
1
+ import estraverse from 'estraverse';
2
+ import { createLintRule } from '../utils/create-rule';
3
+ import { isCss, getImportSources, isStyled, isKeyframes, isCssMap, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
4
+ var schema = [{
5
+ type: 'object',
6
+ properties: {
7
+ importSources: {
8
+ type: 'array',
9
+ items: {
10
+ type: 'string'
11
+ },
12
+ uniqueItems: true
13
+ }
14
+ }
15
+ }];
16
+ export var rule = createLintRule({
17
+ meta: {
18
+ name: 'no-container-queries',
19
+ docs: {
20
+ description: 'Prevents usage of @container query within css styling',
21
+ recommended: true,
22
+ severity: 'warn'
23
+ },
24
+ messages: {
25
+ 'no-container-queries': 'We block @container queries as they break scope and are not type-safe. We suggest alternatives such as JS-based APIs or @media queries.'
26
+ },
27
+ type: 'problem',
28
+ schema: schema
29
+ },
30
+ create: function create(context) {
31
+ var importSources = getImportSources(context);
32
+ return {
33
+ CallExpression: function CallExpression(node) {
34
+ var _context$getScope = context.getScope(),
35
+ references = _context$getScope.references;
36
+ if (isCss(node.callee, references, importSources) || isStyled(node.callee, references, importSources) || isKeyframes(node.callee, references, importSources) || isCssMap(node.callee, references, importSources) || isXcss(node.callee, references, importSources)) {
37
+ estraverse.traverse(node, {
38
+ enter: function enter(node) {
39
+ var _node$key$value, _node$key$quasis$;
40
+ if (node.type !== 'Property') {
41
+ return;
42
+ }
43
+ if (node.key.type !== 'Literal' && node.key.type !== 'TemplateLiteral') {
44
+ return;
45
+ }
46
+ if (node.key.type === 'Literal' && (_node$key$value = node.key.value) !== null && _node$key$value !== void 0 && _node$key$value.toString().match(/@container/)) {
47
+ context.report({
48
+ node: node.key,
49
+ messageId: 'no-container-queries'
50
+ });
51
+ }
52
+ if (node.key.type === 'TemplateLiteral' && (_node$key$quasis$ = node.key.quasis[0]) !== null && _node$key$quasis$ !== void 0 && _node$key$quasis$.value.raw.match(/@container/)) {
53
+ context.report({
54
+ node: node.key,
55
+ messageId: 'no-container-queries'
56
+ });
57
+ }
58
+ },
59
+ /**
60
+ * This is needed to handle unknown node types. Otherwise an error is thrown.
61
+ */
62
+ fallback: 'iteration'
63
+ });
64
+ }
65
+ }
66
+ };
67
+ }
68
+ });
69
+ export default rule;
@@ -1,6 +1,6 @@
1
1
  import estraverse from 'estraverse';
2
2
  import { createLintRule } from '../utils/create-rule';
3
- import { isCss, getImportSources, isStyled, isKeyframes, isCssMap, isXcss } from '../utils/is-supported-import';
3
+ import { isCss, getImportSources, isStyled, isKeyframes, isCssMap, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
4
4
  var schema = [{
5
5
  type: 'object',
6
6
  properties: {
@@ -6,6 +6,7 @@ export declare const configs: {
6
6
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
7
7
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
8
8
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
9
+ '@atlaskit/ui-styling-standard/no-container-queries': string;
9
10
  '@atlaskit/ui-styling-standard/no-important-styles': string;
10
11
  '@atlaskit/design-system/consistent-css-prop-usage': (string | {
11
12
  excludeReactComponents: boolean;
@@ -37,6 +38,7 @@ export declare const configs: {
37
38
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
38
39
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
39
40
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
41
+ '@atlaskit/ui-styling-standard/no-container-queries': string;
40
42
  '@atlaskit/ui-styling-standard/no-important-styles': string;
41
43
  '@atlaskit/design-system/consistent-css-prop-usage': (string | {
42
44
  excludeReactComponents: boolean;
@@ -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::c4a9648d888d86d752ea2b3442d395ba>>
3
+ * @codegen <<SignedSource::2e134e292f949b29bfd0b29d128e684a>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  declare const _default: {
@@ -9,6 +9,7 @@ declare const _default: {
9
9
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
10
10
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
11
11
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
12
+ '@atlaskit/ui-styling-standard/no-container-queries': string;
12
13
  '@atlaskit/ui-styling-standard/no-important-styles': string;
13
14
  '@atlaskit/design-system/consistent-css-prop-usage': (string | {
14
15
  excludeReactComponents: boolean;
@@ -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::c4a9648d888d86d752ea2b3442d395ba>>
3
+ * @codegen <<SignedSource::2e134e292f949b29bfd0b29d128e684a>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  declare const _default: {
@@ -9,6 +9,7 @@ declare const _default: {
9
9
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
10
10
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
11
11
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
12
+ '@atlaskit/ui-styling-standard/no-container-queries': string;
12
13
  '@atlaskit/ui-styling-standard/no-important-styles': string;
13
14
  '@atlaskit/design-system/consistent-css-prop-usage': (string | {
14
15
  excludeReactComponents: boolean;
@@ -2,6 +2,7 @@ declare const _default: {
2
2
  'convert-props-syntax': import("eslint").Rule.RuleModule;
3
3
  'local-cx-xcss': import("eslint").Rule.RuleModule;
4
4
  'no-classname-prop': import("eslint").Rule.RuleModule;
5
+ 'no-container-queries': import("eslint").Rule.RuleModule;
5
6
  'no-important-styles': import("eslint").Rule.RuleModule;
6
7
  };
7
8
  export default _default;
@@ -0,0 +1,2 @@
1
+ export declare const rule: import("eslint").Rule.RuleModule;
2
+ export default rule;
@@ -6,6 +6,7 @@ export declare const configs: {
6
6
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
7
7
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
8
8
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
9
+ '@atlaskit/ui-styling-standard/no-container-queries': string;
9
10
  '@atlaskit/ui-styling-standard/no-important-styles': string;
10
11
  '@atlaskit/design-system/consistent-css-prop-usage': (string | {
11
12
  excludeReactComponents: boolean;
@@ -37,6 +38,7 @@ export declare const configs: {
37
38
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
38
39
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
39
40
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
41
+ '@atlaskit/ui-styling-standard/no-container-queries': string;
40
42
  '@atlaskit/ui-styling-standard/no-important-styles': string;
41
43
  '@atlaskit/design-system/consistent-css-prop-usage': (string | {
42
44
  excludeReactComponents: boolean;
@@ -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::c4a9648d888d86d752ea2b3442d395ba>>
3
+ * @codegen <<SignedSource::2e134e292f949b29bfd0b29d128e684a>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  declare const _default: {
@@ -9,6 +9,7 @@ declare const _default: {
9
9
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
10
10
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
11
11
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
12
+ '@atlaskit/ui-styling-standard/no-container-queries': string;
12
13
  '@atlaskit/ui-styling-standard/no-important-styles': string;
13
14
  '@atlaskit/design-system/consistent-css-prop-usage': (string | {
14
15
  excludeReactComponents: boolean;
@@ -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::c4a9648d888d86d752ea2b3442d395ba>>
3
+ * @codegen <<SignedSource::2e134e292f949b29bfd0b29d128e684a>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  declare const _default: {
@@ -9,6 +9,7 @@ declare const _default: {
9
9
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
10
10
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
11
11
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
12
+ '@atlaskit/ui-styling-standard/no-container-queries': string;
12
13
  '@atlaskit/ui-styling-standard/no-important-styles': string;
13
14
  '@atlaskit/design-system/consistent-css-prop-usage': (string | {
14
15
  excludeReactComponents: boolean;
@@ -2,6 +2,7 @@ declare const _default: {
2
2
  'convert-props-syntax': import("eslint").Rule.RuleModule;
3
3
  'local-cx-xcss': import("eslint").Rule.RuleModule;
4
4
  'no-classname-prop': import("eslint").Rule.RuleModule;
5
+ 'no-container-queries': import("eslint").Rule.RuleModule;
5
6
  'no-important-styles': import("eslint").Rule.RuleModule;
6
7
  };
7
8
  export default _default;
@@ -0,0 +1,2 @@
1
+ export declare const rule: import("eslint").Rule.RuleModule;
2
+ export default rule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-ui-styling-standard",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
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",
@@ -36,6 +36,7 @@
36
36
  ".": "./src/index.tsx"
37
37
  },
38
38
  "dependencies": {
39
+ "@atlaskit/eslint-utils": "^1.0.0",
39
40
  "@babel/runtime": "^7.0.0",
40
41
  "@typescript-eslint/utils": "^5.48.1",
41
42
  "eslint-codemod-utils": "^1.8.6",
@@ -44,7 +45,7 @@
44
45
  },
45
46
  "devDependencies": {
46
47
  "@atlaskit/ds-lib": "^2.2.0",
47
- "@atlaskit/eslint-plugin-design-system": "^9.0.0",
48
+ "@atlaskit/eslint-plugin-design-system": "^9.2.0",
48
49
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
49
50
  "@atlassian/codegen": "*",
50
51
  "@compiled/eslint-plugin": "^0.13.6",
@@ -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::c4a9648d888d86d752ea2b3442d395ba>>
3
+ * @codegen <<SignedSource::2e134e292f949b29bfd0b29d128e684a>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -13,6 +13,7 @@ export default {
13
13
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
14
14
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
15
15
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
16
+ '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
16
17
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
17
18
  '@atlaskit/design-system/consistent-css-prop-usage': [
18
19
  'warn',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::c4a9648d888d86d752ea2b3442d395ba>>
3
+ * @codegen <<SignedSource::2e134e292f949b29bfd0b29d128e684a>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -13,6 +13,7 @@ export default {
13
13
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
14
14
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
15
15
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
16
+ '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
16
17
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
17
18
  '@atlaskit/design-system/consistent-css-prop-usage': [
18
19
  'warn',
@@ -8,7 +8,10 @@ import type {
8
8
  ObjectExpression,
9
9
  } from 'estree-jsx';
10
10
  import { createLintRule } from '../utils/create-rule';
11
- import { isStyledComponents, isEmotion } from '../utils/is-supported-import';
11
+ import {
12
+ isStyledComponents,
13
+ isEmotion,
14
+ } from '@atlaskit/eslint-utils/is-supported-import';
12
15
  import type { Rule, Scope, SourceCode } from 'eslint';
13
16
  import ESTraverse from 'estraverse';
14
17
 
@@ -1,16 +1,18 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::7c8793f6c12f32e915fd9b4dc7a6edef>>
3
+ * @codegen <<SignedSource::3504ce124f49b7eca8abafb5a0bd6884>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import convertPropsSyntax from './convert-props-syntax';
7
7
  import localCxXcss from './local-cx-xcss';
8
8
  import noClassnameProp from './no-classname-prop';
9
+ import noContainerQueries from './no-container-queries';
9
10
  import noImportantStyles from './no-important-styles';
10
11
 
11
12
  export default {
12
13
  'convert-props-syntax': convertPropsSyntax,
13
14
  'local-cx-xcss': localCxXcss,
14
15
  'no-classname-prop': noClassnameProp,
16
+ 'no-container-queries': noContainerQueries,
15
17
  'no-important-styles': noImportantStyles,
16
18
  };
@@ -2,7 +2,10 @@ 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 { CSS_IN_JS_IMPORTS, isCxFunction } from '../utils/is-supported-import';
5
+ import {
6
+ CSS_IN_JS_IMPORTS,
7
+ isCxFunction,
8
+ } from '@atlaskit/eslint-utils/is-supported-import';
6
9
 
7
10
  const IMPORT_SOURCES = [
8
11
  CSS_IN_JS_IMPORTS.compiled,
@@ -0,0 +1,48 @@
1
+ This rule prevents the usage of the `@container` query in style declarations.
2
+
3
+ Container queries break the rules of scope and aren’t guaranteed to be deterministic or type safe and isn’t fully supported across our frontend tech stacks.
4
+
5
+ We suggest you explore the use alternatives such as client JavaScript-based APIs or media queries.
6
+
7
+ ## Examples
8
+
9
+ ### Incorrect
10
+
11
+ ```js
12
+ import { css } from '@compiled/react';
13
+
14
+ const styles = css({
15
+ '@container (width > 400px)': {
16
+ h2: {
17
+ fontSize: '1.5rem',
18
+ },
19
+ },
20
+ });
21
+ ```
22
+
23
+ ### Correct
24
+
25
+ ```js
26
+ import { css } from '@compiled/react';
27
+
28
+ const containerStyles = css({
29
+ display: 'flex',
30
+ flexDirection: 'column',
31
+ });
32
+ ```
33
+
34
+ ## Options
35
+
36
+ ### importSources
37
+
38
+ By default, this rule will check `css` usages from:
39
+
40
+ - `@atlaskit/css`
41
+ - `@atlaskit/primitives`
42
+ - `@compiled/react`
43
+ - `@emotion/react`
44
+ - `@emotion/core`
45
+ - `@emotion/styled`
46
+ - `styled-components`
47
+
48
+ To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
@@ -0,0 +1,142 @@
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: [
74
+ { messageId: 'no-container-queries' },
75
+ { messageId: 'no-container-queries' },
76
+ ],
77
+ },
78
+ {
79
+ name: '@container in styled div under feature flag',
80
+ code: `
81
+ import { styled } from "@compiled/react";
82
+ const Container = styled.div(
83
+ {
84
+ display: 'flex',
85
+ flexDirection: 'column',
86
+ position: 'relative',
87
+ zIndex: '0',
88
+ '&:empty': {
89
+ display: 'none',
90
+ },
91
+ },
92
+ () =>
93
+ ff('a-feature-flag') && {
94
+ [\`@container cardContainer (max-width: \${DISPLAYING_FIELDS_MIN_CARD_WIDTH}px)\`]: {
95
+ width: 0,
96
+ overflow: 'hidden',
97
+ visibility: 'hidden',
98
+ },
99
+ },
100
+ );
101
+ `,
102
+ errors: [{ messageId: 'no-container-queries' }],
103
+ },
104
+ {
105
+ name: '@container in a styled div with TS type parameter',
106
+ code: `
107
+ import { styled } from "@compiled/react";
108
+
109
+ const Component = styled.div<{
110
+ flexGrow?: number;
111
+ }>({
112
+ flexGrow: 1,
113
+ flexBasis: 0,
114
+ "@container AdminCenterPage (min-width: 840px)": {
115
+ flexGrow: (props) => props.flexGrow || 1
116
+ },
117
+ });
118
+ `,
119
+ errors: [{ messageId: 'no-container-queries' }],
120
+ },
121
+ {
122
+ name: '@container in template literal within styled div with TS type parameter',
123
+ code: `
124
+ import { styled } from "@compiled/react";
125
+ const Container = styled.div<{
126
+ paddingBottom: number;
127
+ }>({
128
+ display: 'flex',
129
+ flexDirection: 'column',
130
+ boxSizing: 'border-box',
131
+
132
+ [\`@container cardContainer (max-width: \${DISPLAYING_FIELDS_MIN_CARD_WIDTH}px)\`]: {
133
+ paddingLeft: '10px',
134
+ paddingRight: 0,
135
+ },
136
+ });
137
+ `,
138
+ errors: [{ messageId: 'no-container-queries' }],
139
+ },
140
+ ],
141
+ },
142
+ );
@@ -0,0 +1,100 @@
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: '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
+
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 (
63
+ node.key.type !== 'Literal' &&
64
+ node.key.type !== 'TemplateLiteral'
65
+ ) {
66
+ return;
67
+ }
68
+
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
+ }
78
+
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
+ },
98
+ });
99
+
100
+ export default rule;
@@ -8,7 +8,7 @@ import {
8
8
  isKeyframes,
9
9
  isCssMap,
10
10
  isXcss,
11
- } from '../utils/is-supported-import';
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 = [
package/tsconfig.app.json CHANGED
@@ -33,6 +33,9 @@
33
33
  "outDir": "../../../tsDist/@atlaskit__eslint-plugin-ui-styling-standard/app"
34
34
  },
35
35
  "references": [
36
+ {
37
+ "path": "../eslint-utils/tsconfig.app.json"
38
+ },
36
39
  {
37
40
  "path": "../codegen/tsconfig.app.json"
38
41
  }