@atlaskit/eslint-plugin-design-system 8.29.1 → 8.31.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 (81) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/configs/deprecated.json +0 -5
  4. package/constellation/index/usage.mdx +1 -1
  5. package/constellation/use-primitives-text/usage.mdx +21 -0
  6. package/dist/cjs/ast-nodes/jsx-element.js +33 -2
  7. package/dist/cjs/presets/all.codegen.js +2 -2
  8. package/dist/cjs/presets/recommended.codegen.js +1 -2
  9. package/dist/cjs/rules/index.codegen.js +3 -3
  10. package/dist/cjs/rules/use-primitives/transformers/emotion-css/index.js +1 -2
  11. package/dist/cjs/rules/use-primitives-text/config/index.js +15 -0
  12. package/dist/cjs/rules/use-primitives-text/index.js +57 -0
  13. package/dist/cjs/rules/use-primitives-text/transformers/common.js +43 -0
  14. package/dist/cjs/rules/use-primitives-text/transformers/emphasis-elements.js +82 -0
  15. package/dist/cjs/rules/use-primitives-text/transformers/index.js +33 -0
  16. package/dist/cjs/rules/use-primitives-text/transformers/paragraph-elements.js +196 -0
  17. package/dist/cjs/rules/use-primitives-text/transformers/span-elements.js +87 -0
  18. package/dist/cjs/rules/use-primitives-text/transformers/strong-elements.js +82 -0
  19. package/dist/configs/deprecated.json +0 -5
  20. package/dist/es2019/ast-nodes/jsx-element.js +33 -2
  21. package/dist/es2019/presets/all.codegen.js +2 -2
  22. package/dist/es2019/presets/recommended.codegen.js +1 -2
  23. package/dist/es2019/rules/index.codegen.js +3 -3
  24. package/dist/es2019/rules/use-primitives/transformers/emotion-css/index.js +1 -2
  25. package/dist/es2019/rules/use-primitives-text/config/index.js +9 -0
  26. package/dist/es2019/rules/use-primitives-text/index.js +51 -0
  27. package/dist/es2019/rules/use-primitives-text/transformers/common.js +33 -0
  28. package/dist/es2019/rules/use-primitives-text/transformers/emphasis-elements.js +72 -0
  29. package/dist/es2019/rules/use-primitives-text/transformers/index.js +4 -0
  30. package/dist/es2019/rules/use-primitives-text/transformers/paragraph-elements.js +187 -0
  31. package/dist/es2019/rules/use-primitives-text/transformers/span-elements.js +77 -0
  32. package/dist/es2019/rules/use-primitives-text/transformers/strong-elements.js +72 -0
  33. package/dist/esm/ast-nodes/jsx-element.js +33 -2
  34. package/dist/esm/presets/all.codegen.js +2 -2
  35. package/dist/esm/presets/recommended.codegen.js +1 -2
  36. package/dist/esm/rules/index.codegen.js +3 -3
  37. package/dist/esm/rules/use-primitives/transformers/emotion-css/index.js +1 -2
  38. package/dist/esm/rules/use-primitives-text/config/index.js +9 -0
  39. package/dist/esm/rules/use-primitives-text/index.js +51 -0
  40. package/dist/esm/rules/use-primitives-text/transformers/common.js +33 -0
  41. package/dist/esm/rules/use-primitives-text/transformers/emphasis-elements.js +72 -0
  42. package/dist/esm/rules/use-primitives-text/transformers/index.js +4 -0
  43. package/dist/esm/rules/use-primitives-text/transformers/paragraph-elements.js +186 -0
  44. package/dist/esm/rules/use-primitives-text/transformers/span-elements.js +77 -0
  45. package/dist/esm/rules/use-primitives-text/transformers/strong-elements.js +72 -0
  46. package/dist/types/ast-nodes/jsx-element.d.ts +5 -2
  47. package/dist/types/index.codegen.d.ts +1 -2
  48. package/dist/types/presets/all.codegen.d.ts +2 -2
  49. package/dist/types/presets/recommended.codegen.d.ts +1 -2
  50. package/dist/types/rules/index.codegen.d.ts +1 -1
  51. package/dist/types/rules/use-primitives-text/config/index.d.ts +6 -0
  52. package/dist/types/rules/{local-cx-xcss → use-primitives-text}/index.d.ts +1 -1
  53. package/dist/types/rules/use-primitives-text/transformers/common.d.ts +5 -0
  54. package/dist/types/rules/use-primitives-text/transformers/emphasis-elements.d.ts +16 -0
  55. package/dist/types/rules/use-primitives-text/transformers/index.d.ts +4 -0
  56. package/dist/types/rules/use-primitives-text/transformers/paragraph-elements.d.ts +32 -0
  57. package/dist/types/rules/use-primitives-text/transformers/span-elements.d.ts +16 -0
  58. package/dist/types/rules/use-primitives-text/transformers/strong-elements.d.ts +16 -0
  59. package/dist/types-ts4.5/ast-nodes/jsx-element.d.ts +5 -2
  60. package/dist/types-ts4.5/index.codegen.d.ts +1 -2
  61. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -2
  62. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -2
  63. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -1
  64. package/dist/types-ts4.5/rules/use-primitives-text/config/index.d.ts +6 -0
  65. package/dist/types-ts4.5/rules/{local-cx-xcss → use-primitives-text}/index.d.ts +1 -1
  66. package/dist/types-ts4.5/rules/use-primitives-text/transformers/common.d.ts +5 -0
  67. package/dist/types-ts4.5/rules/use-primitives-text/transformers/emphasis-elements.d.ts +16 -0
  68. package/dist/types-ts4.5/rules/use-primitives-text/transformers/index.d.ts +4 -0
  69. package/dist/types-ts4.5/rules/use-primitives-text/transformers/paragraph-elements.d.ts +32 -0
  70. package/dist/types-ts4.5/rules/use-primitives-text/transformers/span-elements.d.ts +16 -0
  71. package/dist/types-ts4.5/rules/use-primitives-text/transformers/strong-elements.d.ts +16 -0
  72. package/package.json +1 -1
  73. package/constellation/local-cx-xcss/usage.mdx +0 -37
  74. package/dist/cjs/rules/local-cx-xcss/index.js +0 -51
  75. package/dist/cjs/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +0 -27
  76. package/dist/es2019/rules/local-cx-xcss/index.js +0 -45
  77. package/dist/es2019/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +0 -19
  78. package/dist/esm/rules/local-cx-xcss/index.js +0 -45
  79. package/dist/esm/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +0 -19
  80. package/dist/types/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.d.ts +0 -7
  81. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.d.ts +0 -7
@@ -7,7 +7,6 @@ export declare const configs: {
7
7
  '@atlaskit/design-system/ensure-design-token-usage': string;
8
8
  '@atlaskit/design-system/ensure-design-token-usage/preview': string;
9
9
  '@atlaskit/design-system/icon-label': string;
10
- '@atlaskit/design-system/local-cx-xcss': string;
11
10
  '@atlaskit/design-system/no-banned-imports': string;
12
11
  '@atlaskit/design-system/no-css-tagged-template-expression': string;
13
12
  '@atlaskit/design-system/no-deprecated-apis': string;
@@ -31,6 +30,7 @@ export declare const configs: {
31
30
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
32
31
  '@atlaskit/design-system/use-href-in-link-item': string;
33
32
  '@atlaskit/design-system/use-primitives': string;
33
+ '@atlaskit/design-system/use-primitives-text': string;
34
34
  '@atlaskit/design-system/use-visually-hidden': string;
35
35
  };
36
36
  };
@@ -40,7 +40,6 @@ export declare const configs: {
40
40
  '@atlaskit/design-system/consistent-css-prop-usage': string;
41
41
  '@atlaskit/design-system/ensure-design-token-usage': string;
42
42
  '@atlaskit/design-system/icon-label': string;
43
- '@atlaskit/design-system/local-cx-xcss': string;
44
43
  '@atlaskit/design-system/no-banned-imports': string;
45
44
  '@atlaskit/design-system/no-deprecated-apis': string;
46
45
  '@atlaskit/design-system/no-deprecated-design-token-usage': string;
@@ -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::5647ce9c10ba880cffece66b5924fd6e>>
3
+ * @codegen <<SignedSource::aa64b4343b8763cfa5aa66230faea408>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -10,7 +10,6 @@ declare const _default: {
10
10
  '@atlaskit/design-system/ensure-design-token-usage': string;
11
11
  '@atlaskit/design-system/ensure-design-token-usage/preview': string;
12
12
  '@atlaskit/design-system/icon-label': string;
13
- '@atlaskit/design-system/local-cx-xcss': string;
14
13
  '@atlaskit/design-system/no-banned-imports': string;
15
14
  '@atlaskit/design-system/no-css-tagged-template-expression': string;
16
15
  '@atlaskit/design-system/no-deprecated-apis': string;
@@ -34,6 +33,7 @@ declare const _default: {
34
33
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
35
34
  '@atlaskit/design-system/use-href-in-link-item': string;
36
35
  '@atlaskit/design-system/use-primitives': string;
36
+ '@atlaskit/design-system/use-primitives-text': string;
37
37
  '@atlaskit/design-system/use-visually-hidden': string;
38
38
  };
39
39
  };
@@ -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::577269c832952ce359cde6a50f26f4e0>>
3
+ * @codegen <<SignedSource::aebc778f0b10032cbb2941b55189d766>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -9,7 +9,6 @@ declare const _default: {
9
9
  '@atlaskit/design-system/consistent-css-prop-usage': string;
10
10
  '@atlaskit/design-system/ensure-design-token-usage': string;
11
11
  '@atlaskit/design-system/icon-label': string;
12
- '@atlaskit/design-system/local-cx-xcss': string;
13
12
  '@atlaskit/design-system/no-banned-imports': string;
14
13
  '@atlaskit/design-system/no-deprecated-apis': string;
15
14
  '@atlaskit/design-system/no-deprecated-design-token-usage': string;
@@ -3,7 +3,6 @@ declare const _default: {
3
3
  'ensure-design-token-usage': import("eslint").Rule.RuleModule;
4
4
  'ensure-design-token-usage/preview': import("eslint").Rule.RuleModule;
5
5
  'icon-label': import("eslint").Rule.RuleModule;
6
- 'local-cx-xcss': import("eslint").Rule.RuleModule;
7
6
  'no-banned-imports': import("eslint").Rule.RuleModule;
8
7
  'no-css-tagged-template-expression': import("eslint").Rule.RuleModule;
9
8
  'no-deprecated-apis': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<string, [
@@ -35,6 +34,7 @@ declare const _default: {
35
34
  'use-heading-level-in-spotlight-card': import("eslint").Rule.RuleModule;
36
35
  'use-href-in-link-item': import("eslint").Rule.RuleModule;
37
36
  'use-primitives': import("eslint").Rule.RuleModule;
37
+ 'use-primitives-text': import("eslint").Rule.RuleModule;
38
38
  'use-visually-hidden': import("eslint").Rule.RuleModule;
39
39
  };
40
40
  export default _default;
@@ -0,0 +1,6 @@
1
+ type Pattern = 'paragraph-elements' | 'span-elements' | 'strong-elements' | 'emphasis-elements';
2
+ export interface RuleConfig {
3
+ patterns: Pattern[];
4
+ }
5
+ export declare const getConfig: (overrides: Partial<RuleConfig>) => Required<RuleConfig>;
6
+ export {};
@@ -1,3 +1,3 @@
1
1
  import type { Rule } from 'eslint';
2
- export declare const rule: Rule.RuleModule;
2
+ declare const rule: Rule.RuleModule;
3
3
  export default rule;
@@ -0,0 +1,5 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ export declare function updateTestIdAttributeFix(node: JSXElement, fixer: Rule.RuleFixer): Rule.Fix | undefined;
4
+ export declare const allowedAttrs: string[];
5
+ export declare function hasTextChildrenOnly(node: JSXElement): boolean;
@@ -0,0 +1,16 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ import { RuleConfig } from '../config';
4
+ interface MetaData {
5
+ context: Rule.RuleContext;
6
+ config: RuleConfig;
7
+ }
8
+ type FixFunction = (fixer: Rule.RuleFixer) => Rule.Fix[];
9
+ export declare const EmphasisElements: {
10
+ lint(node: Rule.Node, { context, config }: MetaData): void;
11
+ _check(node: JSXElement, { context, config }: MetaData): boolean;
12
+ _fix(node: JSXElement, { context }: {
13
+ context: Rule.RuleContext;
14
+ }): FixFunction;
15
+ };
16
+ export {};
@@ -0,0 +1,4 @@
1
+ export { EmphasisElements } from './emphasis-elements';
2
+ export { SpanElements } from './span-elements';
3
+ export { StrongElements } from './strong-elements';
4
+ export { ParagraphElements } from './paragraph-elements';
@@ -0,0 +1,32 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ import { RuleConfig } from '../config';
4
+ type MetaData = {
5
+ context: Rule.RuleContext;
6
+ config: RuleConfig;
7
+ };
8
+ type CheckResult = {
9
+ success: boolean;
10
+ refs: {
11
+ siblings: JSXElement['children'];
12
+ };
13
+ };
14
+ type FixFunction = (fixer: Rule.RuleFixer) => Rule.Fix[];
15
+ export declare const ParagraphElements: {
16
+ lint(node: Rule.Node, { context, config }: MetaData): void;
17
+ _check(node: JSXElement & {
18
+ parent: Rule.Node;
19
+ }, { context, config }: MetaData): CheckResult;
20
+ _fixSingle(node: JSXElement & {
21
+ parent: Rule.Node;
22
+ }, { context }: {
23
+ context: Rule.RuleContext;
24
+ }): FixFunction;
25
+ _fixMultiple(node: JSXElement & {
26
+ parent: Rule.Node;
27
+ }, { context, refs }: {
28
+ context: Rule.RuleContext;
29
+ refs: CheckResult['refs'];
30
+ }): FixFunction;
31
+ };
32
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ import { RuleConfig } from '../config';
4
+ interface MetaData {
5
+ context: Rule.RuleContext;
6
+ config: RuleConfig;
7
+ }
8
+ type FixFunction = (fixer: Rule.RuleFixer) => Rule.Fix[];
9
+ export declare const SpanElements: {
10
+ lint(node: Rule.Node, { context, config }: MetaData): void;
11
+ _check(node: JSXElement, { context, config }: MetaData): boolean;
12
+ _fix(node: JSXElement, { context }: {
13
+ context: Rule.RuleContext;
14
+ }): FixFunction;
15
+ };
16
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ import { RuleConfig } from '../config';
4
+ interface MetaData {
5
+ context: Rule.RuleContext;
6
+ config: RuleConfig;
7
+ }
8
+ type FixFunction = (fixer: Rule.RuleFixer) => Rule.Fix[];
9
+ export declare const StrongElements: {
10
+ lint(node: Rule.Node, { context, config }: MetaData): void;
11
+ _check(node: JSXElement, { context, config }: MetaData): boolean;
12
+ _fix(node: JSXElement, { context }: {
13
+ context: Rule.RuleContext;
14
+ }): FixFunction;
15
+ };
16
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
3
  "description": "The essential plugin for use with the Atlassian Design System.",
4
- "version": "8.29.1",
4
+ "version": "8.31.0",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "publishConfig": {
7
7
  "registry": "https://registry.npmjs.org/"
@@ -1,37 +0,0 @@
1
- # local-cx-xcss
2
-
3
- This rule ensures the `cx()` function is only used within the `xcss` prop. This aids tracking what styles are applied to a jsx element.
4
-
5
- The `cx` function is checked only if it is imported from `@compiled/react` or `@atlaskit/css`.
6
-
7
- 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.
8
-
9
- ## Examples
10
-
11
- ### Incorrect
12
-
13
- ```js
14
- import { cx, cssMap } from '@compiled/react';
15
-
16
- const styles = cssMap({
17
- text: { color: 'red' },
18
- bg: { background: 'blue' },
19
- });
20
-
21
- const joinedStyles = cx(styles.text, styles.bg);
22
-
23
- <Button xcss={joinedStyles} />;
24
- ```
25
-
26
- ### Correct
27
-
28
- ```js
29
- import { cx, cssMap } from '@compiled/react';
30
-
31
- const styles = cssMap({
32
- text: { color: 'red' },
33
- bg: { background: 'blue' },
34
- });
35
-
36
- <Button xcss={cx(styles.text, styles.bg)} />;
37
- ```
@@ -1,51 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.rule = exports.default = void 0;
7
- var _createRule = require("../utils/create-rule");
8
- var _isSupportedImport = require("../utils/is-supported-import");
9
- var IMPORT_SOURCES = [_isSupportedImport.CSS_IN_JS_IMPORTS.compiled, _isSupportedImport.CSS_IN_JS_IMPORTS.atlaskitCss];
10
- function getParentJSXAttribute(node) {
11
- var parent = node.parent;
12
- while (parent && parent.type !== 'JSXAttribute') {
13
- parent = parent.parent;
14
- }
15
- if (parent && parent.type === 'JSXAttribute') {
16
- return parent;
17
- }
18
- return null;
19
- }
20
- var rule = exports.rule = (0, _createRule.createLintRule)({
21
- meta: {
22
- name: 'local-cx-xcss',
23
- docs: {
24
- description: '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.',
25
- recommended: true,
26
- severity: 'error'
27
- },
28
- messages: {
29
- 'local-cx-xcss': 'The cx function should only be declared inside the xcss prop to simplify tracking styles that are applied to a jsx element.'
30
- },
31
- type: 'problem'
32
- },
33
- create: function create(context) {
34
- return {
35
- 'CallExpression[callee.name="cx"]': function CallExpressionCalleeNameCx(node) {
36
- if (node.type === 'CallExpression' && (0, _isSupportedImport.isCxFunction)(node.callee, context.getScope().references, IMPORT_SOURCES)) {
37
- var parentJSXAttribute = getParentJSXAttribute(node);
38
- var propName = parentJSXAttribute === null || parentJSXAttribute === void 0 ? void 0 : parentJSXAttribute.name.name.toString();
39
- if (propName && /[xX]css$/.test(propName)) {
40
- return;
41
- }
42
- context.report({
43
- node: node,
44
- messageId: 'local-cx-xcss'
45
- });
46
- }
47
- }
48
- };
49
- }
50
- });
51
- var _default = exports.default = rule;
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- var _typeof = require("@babel/runtime/helpers/typeof");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.containsOnlySupportedAttrs = void 0;
8
- var _eslintCodemodUtils = require("eslint-codemod-utils");
9
- var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
10
- var supported = _interopRequireWildcard(require("./supported"));
11
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
- /**
14
- * Check that every attribute in the JSXElement is something we support.
15
- * We do this via a whitelist in `this.attributes`. The result is we exclude
16
- * dangerous attrs like `id` and `style`.
17
- */
18
- var containsOnlySupportedAttrs = exports.containsOnlySupportedAttrs = function containsOnlySupportedAttrs(node) {
19
- var attrs = ast.JSXElement.getAttributes(node);
20
- return attrs.every(function (attr) {
21
- if (!(0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXAttribute')) {
22
- return false;
23
- }
24
- var name = ast.JSXAttribute.getName(attr);
25
- return supported.attributes.includes(name);
26
- });
27
- };
@@ -1,45 +0,0 @@
1
- import { createLintRule } from '../utils/create-rule';
2
- import { CSS_IN_JS_IMPORTS, isCxFunction } from '../utils/is-supported-import';
3
- const IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.compiled, CSS_IN_JS_IMPORTS.atlaskitCss];
4
- function getParentJSXAttribute(node) {
5
- let parent = node.parent;
6
- while (parent && parent.type !== 'JSXAttribute') {
7
- parent = parent.parent;
8
- }
9
- if (parent && parent.type === 'JSXAttribute') {
10
- return parent;
11
- }
12
- return null;
13
- }
14
- export const rule = createLintRule({
15
- meta: {
16
- name: 'local-cx-xcss',
17
- docs: {
18
- description: '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.',
19
- recommended: true,
20
- severity: 'error'
21
- },
22
- messages: {
23
- 'local-cx-xcss': 'The cx function should only be declared inside the xcss prop to simplify tracking styles that are applied to a jsx element.'
24
- },
25
- type: 'problem'
26
- },
27
- create(context) {
28
- return {
29
- 'CallExpression[callee.name="cx"]': node => {
30
- if (node.type === 'CallExpression' && isCxFunction(node.callee, context.getScope().references, IMPORT_SOURCES)) {
31
- const parentJSXAttribute = getParentJSXAttribute(node);
32
- const propName = parentJSXAttribute === null || parentJSXAttribute === void 0 ? void 0 : parentJSXAttribute.name.name.toString();
33
- if (propName && /[xX]css$/.test(propName)) {
34
- return;
35
- }
36
- context.report({
37
- node,
38
- messageId: 'local-cx-xcss'
39
- });
40
- }
41
- }
42
- };
43
- }
44
- });
45
- export default rule;
@@ -1,19 +0,0 @@
1
- import { isNodeOfType } from 'eslint-codemod-utils';
2
- import * as ast from '../../../../ast-nodes';
3
- import * as supported from './supported';
4
-
5
- /**
6
- * Check that every attribute in the JSXElement is something we support.
7
- * We do this via a whitelist in `this.attributes`. The result is we exclude
8
- * dangerous attrs like `id` and `style`.
9
- */
10
- export const containsOnlySupportedAttrs = node => {
11
- const attrs = ast.JSXElement.getAttributes(node);
12
- return attrs.every(attr => {
13
- if (!isNodeOfType(attr, 'JSXAttribute')) {
14
- return false;
15
- }
16
- const name = ast.JSXAttribute.getName(attr);
17
- return supported.attributes.includes(name);
18
- });
19
- };
@@ -1,45 +0,0 @@
1
- import { createLintRule } from '../utils/create-rule';
2
- import { CSS_IN_JS_IMPORTS, isCxFunction } from '../utils/is-supported-import';
3
- var IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.compiled, CSS_IN_JS_IMPORTS.atlaskitCss];
4
- function getParentJSXAttribute(node) {
5
- var parent = node.parent;
6
- while (parent && parent.type !== 'JSXAttribute') {
7
- parent = parent.parent;
8
- }
9
- if (parent && parent.type === 'JSXAttribute') {
10
- return parent;
11
- }
12
- return null;
13
- }
14
- export var rule = createLintRule({
15
- meta: {
16
- name: 'local-cx-xcss',
17
- docs: {
18
- description: '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.',
19
- recommended: true,
20
- severity: 'error'
21
- },
22
- messages: {
23
- 'local-cx-xcss': 'The cx function should only be declared inside the xcss prop to simplify tracking styles that are applied to a jsx element.'
24
- },
25
- type: 'problem'
26
- },
27
- create: function create(context) {
28
- return {
29
- 'CallExpression[callee.name="cx"]': function CallExpressionCalleeNameCx(node) {
30
- if (node.type === 'CallExpression' && isCxFunction(node.callee, context.getScope().references, IMPORT_SOURCES)) {
31
- var parentJSXAttribute = getParentJSXAttribute(node);
32
- var propName = parentJSXAttribute === null || parentJSXAttribute === void 0 ? void 0 : parentJSXAttribute.name.name.toString();
33
- if (propName && /[xX]css$/.test(propName)) {
34
- return;
35
- }
36
- context.report({
37
- node: node,
38
- messageId: 'local-cx-xcss'
39
- });
40
- }
41
- }
42
- };
43
- }
44
- });
45
- export default rule;
@@ -1,19 +0,0 @@
1
- import { isNodeOfType } from 'eslint-codemod-utils';
2
- import * as ast from '../../../../ast-nodes';
3
- import * as supported from './supported';
4
-
5
- /**
6
- * Check that every attribute in the JSXElement is something we support.
7
- * We do this via a whitelist in `this.attributes`. The result is we exclude
8
- * dangerous attrs like `id` and `style`.
9
- */
10
- export var containsOnlySupportedAttrs = function containsOnlySupportedAttrs(node) {
11
- var attrs = ast.JSXElement.getAttributes(node);
12
- return attrs.every(function (attr) {
13
- if (!isNodeOfType(attr, 'JSXAttribute')) {
14
- return false;
15
- }
16
- var name = ast.JSXAttribute.getName(attr);
17
- return supported.attributes.includes(name);
18
- });
19
- };
@@ -1,7 +0,0 @@
1
- import { JSXElement } from 'eslint-codemod-utils';
2
- /**
3
- * Check that every attribute in the JSXElement is something we support.
4
- * We do this via a whitelist in `this.attributes`. The result is we exclude
5
- * dangerous attrs like `id` and `style`.
6
- */
7
- export declare const containsOnlySupportedAttrs: (node: JSXElement) => boolean;
@@ -1,7 +0,0 @@
1
- import { JSXElement } from 'eslint-codemod-utils';
2
- /**
3
- * Check that every attribute in the JSXElement is something we support.
4
- * We do this via a whitelist in `this.attributes`. The result is we exclude
5
- * dangerous attrs like `id` and `style`.
6
- */
7
- export declare const containsOnlySupportedAttrs: (node: JSXElement) => boolean;