@atlaskit/eslint-plugin-design-system 8.25.2 → 8.27.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 (80) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +4 -0
  3. package/constellation/index/usage.mdx +402 -6
  4. package/dist/cjs/presets/all.codegen.js +5 -1
  5. package/dist/cjs/presets/recommended.codegen.js +5 -1
  6. package/dist/cjs/rules/consistent-css-prop-usage/index.js +254 -32
  7. package/dist/cjs/rules/index.codegen.js +9 -1
  8. package/dist/cjs/rules/no-empty-styled-expression/index.js +75 -0
  9. package/dist/cjs/rules/no-exported-css/index.js +37 -0
  10. package/dist/cjs/rules/no-exported-keyframes/index.js +37 -0
  11. package/dist/cjs/rules/no-invalid-css-map/index.js +102 -0
  12. package/dist/cjs/rules/no-invalid-css-map/utils.js +193 -0
  13. package/dist/cjs/rules/utils/create-no-exported-rule/check-if-supported-export.js +158 -0
  14. package/dist/cjs/rules/utils/create-no-exported-rule/is-styled-component.js +80 -0
  15. package/dist/cjs/rules/utils/create-no-exported-rule/main.js +66 -0
  16. package/dist/cjs/rules/utils/get-first-supported-import.js +28 -0
  17. package/dist/cjs/rules/utils/is-supported-import.js +53 -16
  18. package/dist/es2019/presets/all.codegen.js +5 -1
  19. package/dist/es2019/presets/recommended.codegen.js +5 -1
  20. package/dist/es2019/rules/consistent-css-prop-usage/index.js +251 -33
  21. package/dist/es2019/rules/index.codegen.js +9 -1
  22. package/dist/es2019/rules/no-empty-styled-expression/index.js +65 -0
  23. package/dist/es2019/rules/no-exported-css/index.js +31 -0
  24. package/dist/es2019/rules/no-exported-keyframes/index.js +31 -0
  25. package/dist/es2019/rules/no-invalid-css-map/index.js +95 -0
  26. package/dist/es2019/rules/no-invalid-css-map/utils.js +134 -0
  27. package/dist/es2019/rules/utils/create-no-exported-rule/check-if-supported-export.js +142 -0
  28. package/dist/es2019/rules/utils/create-no-exported-rule/is-styled-component.js +70 -0
  29. package/dist/es2019/rules/utils/create-no-exported-rule/main.js +59 -0
  30. package/dist/es2019/rules/utils/get-first-supported-import.js +22 -0
  31. package/dist/es2019/rules/utils/is-supported-import.js +50 -15
  32. package/dist/esm/presets/all.codegen.js +5 -1
  33. package/dist/esm/presets/recommended.codegen.js +5 -1
  34. package/dist/esm/rules/consistent-css-prop-usage/index.js +255 -33
  35. package/dist/esm/rules/index.codegen.js +9 -1
  36. package/dist/esm/rules/no-empty-styled-expression/index.js +68 -0
  37. package/dist/esm/rules/no-exported-css/index.js +31 -0
  38. package/dist/esm/rules/no-exported-keyframes/index.js +31 -0
  39. package/dist/esm/rules/no-invalid-css-map/index.js +96 -0
  40. package/dist/esm/rules/no-invalid-css-map/utils.js +186 -0
  41. package/dist/esm/rules/utils/create-no-exported-rule/check-if-supported-export.js +151 -0
  42. package/dist/esm/rules/utils/create-no-exported-rule/is-styled-component.js +74 -0
  43. package/dist/esm/rules/utils/create-no-exported-rule/main.js +60 -0
  44. package/dist/esm/rules/utils/get-first-supported-import.js +22 -0
  45. package/dist/esm/rules/utils/is-supported-import.js +51 -15
  46. package/dist/types/index.codegen.d.ts +8 -0
  47. package/dist/types/presets/all.codegen.d.ts +5 -1
  48. package/dist/types/presets/recommended.codegen.d.ts +5 -1
  49. package/dist/types/rules/consistent-css-prop-usage/types.d.ts +7 -2
  50. package/dist/types/rules/index.codegen.d.ts +4 -0
  51. package/dist/types/rules/no-empty-styled-expression/index.d.ts +3 -0
  52. package/dist/types/rules/no-exported-css/index.d.ts +3 -0
  53. package/dist/types/rules/no-exported-keyframes/index.d.ts +3 -0
  54. package/dist/types/rules/no-invalid-css-map/index.d.ts +3 -0
  55. package/dist/types/rules/no-invalid-css-map/utils.d.ts +14 -0
  56. package/dist/types/rules/use-primitives/utils/update-jsx-attribute-by-name.d.ts +1 -1
  57. package/dist/types/rules/utils/create-no-exported-rule/check-if-supported-export.d.ts +15 -0
  58. package/dist/types/rules/utils/create-no-exported-rule/is-styled-component.d.ts +14 -0
  59. package/dist/types/rules/utils/create-no-exported-rule/main.d.ts +19 -0
  60. package/dist/types/rules/utils/create-rule.d.ts +1 -1
  61. package/dist/types/rules/utils/get-first-supported-import.d.ts +17 -0
  62. package/dist/types/rules/utils/is-supported-import.d.ts +26 -8
  63. package/dist/types-ts4.5/index.codegen.d.ts +8 -0
  64. package/dist/types-ts4.5/presets/all.codegen.d.ts +5 -1
  65. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +5 -1
  66. package/dist/types-ts4.5/rules/consistent-css-prop-usage/types.d.ts +7 -2
  67. package/dist/types-ts4.5/rules/index.codegen.d.ts +4 -0
  68. package/dist/types-ts4.5/rules/no-empty-styled-expression/index.d.ts +3 -0
  69. package/dist/types-ts4.5/rules/no-exported-css/index.d.ts +3 -0
  70. package/dist/types-ts4.5/rules/no-exported-keyframes/index.d.ts +3 -0
  71. package/dist/types-ts4.5/rules/no-invalid-css-map/index.d.ts +3 -0
  72. package/dist/types-ts4.5/rules/no-invalid-css-map/utils.d.ts +14 -0
  73. package/dist/types-ts4.5/rules/use-primitives/utils/update-jsx-attribute-by-name.d.ts +1 -1
  74. package/dist/types-ts4.5/rules/utils/create-no-exported-rule/check-if-supported-export.d.ts +15 -0
  75. package/dist/types-ts4.5/rules/utils/create-no-exported-rule/is-styled-component.d.ts +14 -0
  76. package/dist/types-ts4.5/rules/utils/create-no-exported-rule/main.d.ts +19 -0
  77. package/dist/types-ts4.5/rules/utils/create-rule.d.ts +1 -1
  78. package/dist/types-ts4.5/rules/utils/get-first-supported-import.d.ts +17 -0
  79. package/dist/types-ts4.5/rules/utils/is-supported-import.d.ts +26 -8
  80. package/package.json +3 -1
@@ -1,3 +1,4 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  // eslint-disable-next-line import/no-extraneous-dependencies
2
3
 
3
4
  export var CSS_IN_JS_IMPORTS = {
@@ -5,34 +6,68 @@ export var CSS_IN_JS_IMPORTS = {
5
6
  emotionReact: '@emotion/react',
6
7
  emotionCore: '@emotion/core',
7
8
  styledComponents: 'styled-components',
8
- atlaskitCss: '@atlaskit/css'
9
+ atlaskitCss: '@atlaskit/css',
10
+ atlaskitPrimitives: '@atlaskit/primitives'
9
11
  };
10
12
 
11
- // List of CSS-in-JS libraries an import of a valid css, cx, cssMap, etc.
13
+ // A CSS-in-JS library an import of a valid css, cx, cssMap, etc.
12
14
  // function might originate from, e.g. @compiled/react, @emotion/core.
15
+ // All ESLint rules originating from `@compiled/eslint-plugin` should apply to these libraries.
16
+ export var DEFAULT_IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.compiled, CSS_IN_JS_IMPORTS.atlaskitCss];
17
+
18
+ /**
19
+ * Given the ESLint rule context, extract and parse the value of the importSources rule option.
20
+ * The importSources option is used to define additional libraries for which an ESLint rule
21
+ * should apply to.
22
+ *
23
+ * Note that `@compiled/react` and `@atlaskit/css` are always included in importSources, regardless
24
+ * of what importSources is configured to by the user.
25
+ *
26
+ * @param context The rule context.
27
+ * @returns An array of strings representing what CSS-in-JS packages that should be checked, based
28
+ * on the rule options configuration.
29
+ */
30
+ export var getImportSources = function getImportSources(context) {
31
+ var options = context.options;
32
+ if (!options.length) {
33
+ return DEFAULT_IMPORT_SOURCES;
34
+ }
35
+ if (options[0].importSources && Array.isArray(options[0].importSources)) {
36
+ return [].concat(DEFAULT_IMPORT_SOURCES, _toConsumableArray(options[0].importSources));
37
+ }
38
+ return DEFAULT_IMPORT_SOURCES;
39
+ };
13
40
  var isSupportedImportWrapper = function isSupportedImportWrapper(functionName) {
14
- // This will need to be extended to support default imports once we start
15
- // checking cases like `import css from '@emotion/css'`
16
41
  var checkDefinitionHasImport = function checkDefinitionHasImport(def, importSources) {
17
- var _def$parent, _def$parent2;
18
- return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && def.node.imported.name === functionName && ((_def$parent = def.parent) === null || _def$parent === void 0 ? void 0 : _def$parent.type) === 'ImportDeclaration' && importSources.includes((_def$parent2 = def.parent) === null || _def$parent2 === void 0 ? void 0 : _def$parent2.source.value);
42
+ if (def.type !== 'ImportBinding') {
43
+ return false;
44
+ }
45
+ if (!def.parent || !importSources.includes(def.parent.source.value)) {
46
+ return false;
47
+ }
48
+ return (
49
+ // import { functionName } from 'import-source';
50
+ def.node.type === 'ImportSpecifier' && def.node.imported.name === functionName ||
51
+ // import functionName from 'import-source';
52
+ def.node.type === 'ImportDefaultSpecifier' && def.node.local.name === functionName
53
+ );
19
54
  };
20
55
 
21
56
  /**
22
57
  * Checks whether:
23
58
  *
24
- * 1. a function name `nodeToCheck` matches the name of the function we
59
+ * 1. A function name `nodeToCheck` matches the name of the function we
25
60
  * want to check for (e.g. `cx`, `css`, `cssMap`, or `keyframes`), and
26
- * 2. whether `nodeToCheck` originates from one of the libraries listed
61
+ * 2. Whether `nodeToCheck` originates from one of the libraries listed
27
62
  * in `importSources`.
28
63
  *
29
- * @param nodeToCheck the function callee we are checking (e.g. the `css` in `css()`)
30
- * @param referencesInScope list of references that are in scope. We'll use this
64
+ * @param nodeToCheck The function callee we are checking (e.g. The `css` in `css()`).
65
+ * @param referencesInScope List of references that are in scope. We'll use this
31
66
  * to check where the function callee is imported from.
32
- * @param importSources list of libraries that we want to ensure `nodeToCheck`
33
- * comes from
67
+ * @param importSources List of libraries that we want to ensure `nodeToCheck`
68
+ * comes from.
34
69
  *
35
- * @returns whether the above conditions are true
70
+ * @returns Whether the above conditions are true.
36
71
  */
37
72
  var isSupportedImport = function isSupportedImport(nodeToCheck, referencesInScope, importSources) {
38
73
  return nodeToCheck.type === 'Identifier' && referencesInScope.some(function (reference) {
@@ -50,5 +85,6 @@ var isSupportedImportWrapper = function isSupportedImportWrapper(functionName) {
50
85
  //
51
86
  export var isCss = isSupportedImportWrapper('css');
52
87
  export var isCxFunction = isSupportedImportWrapper('cx');
53
- // export const isCssMap = isLibraryImportWrapper('cssMap');
54
- // export const isKeyframes = isLibraryImportWrapper('keyframes');
88
+ export var isCssMap = isSupportedImportWrapper('cssMap');
89
+ export var isKeyframes = isSupportedImportWrapper('keyframes');
90
+ export var isStyled = isSupportedImportWrapper('styled');
@@ -13,6 +13,10 @@ export declare const configs: {
13
13
  '@atlaskit/design-system/no-deprecated-apis': string;
14
14
  '@atlaskit/design-system/no-deprecated-design-token-usage': string;
15
15
  '@atlaskit/design-system/no-deprecated-imports': string;
16
+ '@atlaskit/design-system/no-empty-styled-expression': string;
17
+ '@atlaskit/design-system/no-exported-css': string;
18
+ '@atlaskit/design-system/no-exported-keyframes': string;
19
+ '@atlaskit/design-system/no-invalid-css-map': string;
16
20
  '@atlaskit/design-system/no-margin': string;
17
21
  '@atlaskit/design-system/no-nested-styles': string;
18
22
  '@atlaskit/design-system/no-physical-properties': string;
@@ -39,6 +43,10 @@ export declare const configs: {
39
43
  '@atlaskit/design-system/no-deprecated-apis': string;
40
44
  '@atlaskit/design-system/no-deprecated-design-token-usage': string;
41
45
  '@atlaskit/design-system/no-deprecated-imports': string;
46
+ '@atlaskit/design-system/no-empty-styled-expression': string;
47
+ '@atlaskit/design-system/no-exported-css': string;
48
+ '@atlaskit/design-system/no-exported-keyframes': string;
49
+ '@atlaskit/design-system/no-invalid-css-map': string;
42
50
  '@atlaskit/design-system/no-nested-styles': string;
43
51
  '@atlaskit/design-system/no-unsafe-design-token-usage': string;
44
52
  '@atlaskit/design-system/no-unsafe-style-overrides': 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::5026ba2cb55b3c1bcacbfe7fb7728a6c>>
3
+ * @codegen <<SignedSource::914085544778f4543f43e3e30d0982e0>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -16,6 +16,10 @@ declare const _default: {
16
16
  '@atlaskit/design-system/no-deprecated-apis': string;
17
17
  '@atlaskit/design-system/no-deprecated-design-token-usage': string;
18
18
  '@atlaskit/design-system/no-deprecated-imports': string;
19
+ '@atlaskit/design-system/no-empty-styled-expression': string;
20
+ '@atlaskit/design-system/no-exported-css': string;
21
+ '@atlaskit/design-system/no-exported-keyframes': string;
22
+ '@atlaskit/design-system/no-invalid-css-map': string;
19
23
  '@atlaskit/design-system/no-margin': string;
20
24
  '@atlaskit/design-system/no-nested-styles': string;
21
25
  '@atlaskit/design-system/no-physical-properties': 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::839224bfab98c1ddf6018dec5320968e>>
3
+ * @codegen <<SignedSource::577269c832952ce359cde6a50f26f4e0>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -14,6 +14,10 @@ declare const _default: {
14
14
  '@atlaskit/design-system/no-deprecated-apis': string;
15
15
  '@atlaskit/design-system/no-deprecated-design-token-usage': string;
16
16
  '@atlaskit/design-system/no-deprecated-imports': string;
17
+ '@atlaskit/design-system/no-empty-styled-expression': string;
18
+ '@atlaskit/design-system/no-exported-css': string;
19
+ '@atlaskit/design-system/no-exported-keyframes': string;
20
+ '@atlaskit/design-system/no-invalid-css-map': string;
17
21
  '@atlaskit/design-system/no-nested-styles': string;
18
22
  '@atlaskit/design-system/no-unsafe-design-token-usage': string;
19
23
  '@atlaskit/design-system/no-unsafe-style-overrides': string;
@@ -1,4 +1,9 @@
1
+ import type { ImportSource } from '../utils/is-supported-import';
1
2
  export type RuleConfig = {
2
- cssFunctions?: string[];
3
- stylesPlacement?: 'top' | 'bottom';
3
+ cssFunctions: string[];
4
+ stylesPlacement: 'top' | 'bottom';
5
+ cssImportSource: ImportSource;
6
+ xcssImportSource: ImportSource;
7
+ excludeReactComponents: boolean;
8
+ fixNamesOnly: boolean;
4
9
  };
@@ -13,6 +13,10 @@ declare const _default: {
13
13
  'no-deprecated-imports': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<string, [{
14
14
  deprecatedConfig: import("./utils/types").DeprecatedConfig;
15
15
  }], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
16
+ 'no-empty-styled-expression': import("eslint").Rule.RuleModule;
17
+ 'no-exported-css': import("eslint").Rule.RuleModule;
18
+ 'no-exported-keyframes': import("eslint").Rule.RuleModule;
19
+ 'no-invalid-css-map': import("eslint").Rule.RuleModule;
16
20
  'no-margin': import("eslint").Rule.RuleModule;
17
21
  'no-nested-styles': import("eslint").Rule.RuleModule;
18
22
  'no-physical-properties': import("eslint").Rule.RuleModule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const noEmptyStyledExpressionRule: Rule.RuleModule;
3
+ export default noEmptyStyledExpressionRule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const noExportedCssRule: Rule.RuleModule;
3
+ export default noExportedCssRule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const noExportedKeyframesRule: Rule.RuleModule;
3
+ export default noExportedKeyframesRule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const noInvalidCssMapRule: Rule.RuleModule;
3
+ export default noInvalidCssMapRule;
@@ -0,0 +1,14 @@
1
+ import type { Rule } from 'eslint';
2
+ import type { CallExpression, ObjectExpression } from 'estree';
3
+ export declare const getCssMapObject: (node: CallExpression) => ObjectExpression | undefined;
4
+ export declare class CssMapObjectChecker {
5
+ private readonly allowedFunctionCalls;
6
+ private readonly cssMapObject;
7
+ private readonly report;
8
+ private readonly references;
9
+ constructor(cssMapObject: ObjectExpression, context: Rule.RuleContext);
10
+ private isNotWhitelistedFunction;
11
+ private checkCssMapObjectValue;
12
+ private checkCssMapObject;
13
+ run(): void;
14
+ }
@@ -1,3 +1,3 @@
1
1
  import type { Rule } from 'eslint';
2
2
  import { JSXElement } from 'eslint-codemod-utils';
3
- export declare const updateJSXAttributeByName: (oldName: string, newName: string, node: JSXElement, fixer: Rule.RuleFixer) => never[] | Rule.Fix;
3
+ export declare const updateJSXAttributeByName: (oldName: string, newName: string, node: JSXElement, fixer: Rule.RuleFixer) => Rule.Fix | never[];
@@ -0,0 +1,15 @@
1
+ import type { Rule, Scope as ScopeNamespace } from 'eslint';
2
+ import { ImportSource } from '../is-supported-import';
3
+ type Node = Rule.Node;
4
+ type RuleContext = Rule.RuleContext;
5
+ type Scope = ScopeNamespace.Scope;
6
+ type Yes = {
7
+ isExport: true;
8
+ node: Node;
9
+ };
10
+ type No = {
11
+ isExport: false;
12
+ };
13
+ type IsSupportedExport = Yes | No;
14
+ export declare const checkIfSupportedExport: (context: RuleContext, node: Node, importSources: ImportSource[], scope?: Scope) => IsSupportedExport;
15
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { Rule } from 'eslint';
2
+ import type { ImportSource } from '../is-supported-import';
3
+ type Node = Rule.Node;
4
+ type RuleContext = Rule.RuleContext;
5
+ /**
6
+ * Returns whether the node is a usage of the `styled` API in the libraries we support.
7
+ *
8
+ * @param nodes Nodes to check.
9
+ * @param context Rule context.
10
+ * @param importSources A list of libraries we support.
11
+ * @returns Whether the node is a usage of the `styled` API.
12
+ */
13
+ export declare const isStyledComponent: (nodes: Node[], context: RuleContext, importSources: ImportSource[]) => boolean;
14
+ export {};
@@ -0,0 +1,19 @@
1
+ import type { Rule } from 'eslint';
2
+ import { type SupportedNameChecker } from '../is-supported-import';
3
+ type RuleModule = Rule.RuleModule;
4
+ /**
5
+ * Creates a new ESLint rule for banning exporting certain function calls, e.g.
6
+ * `css` and `keyframes`.
7
+ *
8
+ * Copied from the `utils/create-no-exported-rule/` folder in @compiled/eslint-plugin.
9
+ *
10
+ * Requires an importSources option defined on the rule, which is used to define additional
11
+ * packages which should be checked as part of this rule.
12
+ *
13
+ * @param isUsage A function that checks whether the current node matches the desired
14
+ * function call to check.
15
+ * @param messageId The ESLint error message to use for lint violations.
16
+ * @returns An eslint rule.
17
+ */
18
+ export declare const createNoExportedRule: (isUsage: SupportedNameChecker, messageId: string) => RuleModule['create'];
19
+ export {};
@@ -30,7 +30,7 @@ export interface LintRuleMeta extends Omit<Rule.RuleMetaData, 'docs'> {
30
30
  */
31
31
  description: string;
32
32
  /**
33
- * Specifies the URL at which the full documentation can be accessed
33
+ * Specifies the URL at which the full documentation can be accessed.
34
34
  */
35
35
  url?: string | undefined;
36
36
  /**
@@ -0,0 +1,17 @@
1
+ import type { Rule } from 'eslint';
2
+ import { ImportDeclaration } from 'eslint-codemod-utils';
3
+ import { ImportSource } from './is-supported-import';
4
+ type RuleContext = Rule.RuleContext;
5
+ /**
6
+ * Get the first import declaration in the file that matches any of the packages
7
+ * in `importSources`.
8
+ *
9
+ * @param context Rule context.
10
+ * @param importSources The packages to check import statements for. If importSources
11
+ * contains more than one package, the first import statement
12
+ * detected in the file that matches any of the packages will be
13
+ * returned.
14
+ * @returns The first import declaration found in the file.
15
+ */
16
+ export declare const getFirstSupportedImport: (context: RuleContext, importSources: ImportSource[]) => ImportDeclaration | undefined;
17
+ export {};
@@ -1,16 +1,34 @@
1
- import type { Scope } from 'eslint';
1
+ import type { Rule, Scope } from 'eslint';
2
2
  import type { CallExpression } from 'estree';
3
3
  type Callee = CallExpression['callee'];
4
4
  type Reference = Scope.Reference;
5
5
  export declare const CSS_IN_JS_IMPORTS: {
6
- compiled: string;
7
- emotionReact: string;
8
- emotionCore: string;
9
- styledComponents: string;
10
- atlaskitCss: string;
6
+ readonly compiled: "@compiled/react";
7
+ readonly emotionReact: "@emotion/react";
8
+ readonly emotionCore: "@emotion/core";
9
+ readonly styledComponents: "styled-components";
10
+ readonly atlaskitCss: "@atlaskit/css";
11
+ readonly atlaskitPrimitives: "@atlaskit/primitives";
11
12
  };
12
- type ValidImportSources = string[];
13
- export type SupportedNameChecker = (nodeToCheck: Callee, referencesInScope: Reference[], importSources: ValidImportSources) => boolean;
13
+ export type ImportSource = string;
14
+ export type SupportedNameChecker = (nodeToCheck: Callee, referencesInScope: Reference[], importSources: ImportSource[]) => boolean;
15
+ export declare const DEFAULT_IMPORT_SOURCES: ImportSource[];
16
+ /**
17
+ * Given the ESLint rule context, extract and parse the value of the importSources rule option.
18
+ * The importSources option is used to define additional libraries for which an ESLint rule
19
+ * should apply to.
20
+ *
21
+ * Note that `@compiled/react` and `@atlaskit/css` are always included in importSources, regardless
22
+ * of what importSources is configured to by the user.
23
+ *
24
+ * @param context The rule context.
25
+ * @returns An array of strings representing what CSS-in-JS packages that should be checked, based
26
+ * on the rule options configuration.
27
+ */
28
+ export declare const getImportSources: (context: Rule.RuleContext) => ImportSource[];
14
29
  export declare const isCss: SupportedNameChecker;
15
30
  export declare const isCxFunction: SupportedNameChecker;
31
+ export declare const isCssMap: SupportedNameChecker;
32
+ export declare const isKeyframes: SupportedNameChecker;
33
+ export declare const isStyled: SupportedNameChecker;
16
34
  export {};
@@ -13,6 +13,10 @@ export declare const configs: {
13
13
  '@atlaskit/design-system/no-deprecated-apis': string;
14
14
  '@atlaskit/design-system/no-deprecated-design-token-usage': string;
15
15
  '@atlaskit/design-system/no-deprecated-imports': string;
16
+ '@atlaskit/design-system/no-empty-styled-expression': string;
17
+ '@atlaskit/design-system/no-exported-css': string;
18
+ '@atlaskit/design-system/no-exported-keyframes': string;
19
+ '@atlaskit/design-system/no-invalid-css-map': string;
16
20
  '@atlaskit/design-system/no-margin': string;
17
21
  '@atlaskit/design-system/no-nested-styles': string;
18
22
  '@atlaskit/design-system/no-physical-properties': string;
@@ -39,6 +43,10 @@ export declare const configs: {
39
43
  '@atlaskit/design-system/no-deprecated-apis': string;
40
44
  '@atlaskit/design-system/no-deprecated-design-token-usage': string;
41
45
  '@atlaskit/design-system/no-deprecated-imports': string;
46
+ '@atlaskit/design-system/no-empty-styled-expression': string;
47
+ '@atlaskit/design-system/no-exported-css': string;
48
+ '@atlaskit/design-system/no-exported-keyframes': string;
49
+ '@atlaskit/design-system/no-invalid-css-map': string;
42
50
  '@atlaskit/design-system/no-nested-styles': string;
43
51
  '@atlaskit/design-system/no-unsafe-design-token-usage': string;
44
52
  '@atlaskit/design-system/no-unsafe-style-overrides': 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::5026ba2cb55b3c1bcacbfe7fb7728a6c>>
3
+ * @codegen <<SignedSource::914085544778f4543f43e3e30d0982e0>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -16,6 +16,10 @@ declare const _default: {
16
16
  '@atlaskit/design-system/no-deprecated-apis': string;
17
17
  '@atlaskit/design-system/no-deprecated-design-token-usage': string;
18
18
  '@atlaskit/design-system/no-deprecated-imports': string;
19
+ '@atlaskit/design-system/no-empty-styled-expression': string;
20
+ '@atlaskit/design-system/no-exported-css': string;
21
+ '@atlaskit/design-system/no-exported-keyframes': string;
22
+ '@atlaskit/design-system/no-invalid-css-map': string;
19
23
  '@atlaskit/design-system/no-margin': string;
20
24
  '@atlaskit/design-system/no-nested-styles': string;
21
25
  '@atlaskit/design-system/no-physical-properties': 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::839224bfab98c1ddf6018dec5320968e>>
3
+ * @codegen <<SignedSource::577269c832952ce359cde6a50f26f4e0>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -14,6 +14,10 @@ declare const _default: {
14
14
  '@atlaskit/design-system/no-deprecated-apis': string;
15
15
  '@atlaskit/design-system/no-deprecated-design-token-usage': string;
16
16
  '@atlaskit/design-system/no-deprecated-imports': string;
17
+ '@atlaskit/design-system/no-empty-styled-expression': string;
18
+ '@atlaskit/design-system/no-exported-css': string;
19
+ '@atlaskit/design-system/no-exported-keyframes': string;
20
+ '@atlaskit/design-system/no-invalid-css-map': string;
17
21
  '@atlaskit/design-system/no-nested-styles': string;
18
22
  '@atlaskit/design-system/no-unsafe-design-token-usage': string;
19
23
  '@atlaskit/design-system/no-unsafe-style-overrides': string;
@@ -1,4 +1,9 @@
1
+ import type { ImportSource } from '../utils/is-supported-import';
1
2
  export type RuleConfig = {
2
- cssFunctions?: string[];
3
- stylesPlacement?: 'top' | 'bottom';
3
+ cssFunctions: string[];
4
+ stylesPlacement: 'top' | 'bottom';
5
+ cssImportSource: ImportSource;
6
+ xcssImportSource: ImportSource;
7
+ excludeReactComponents: boolean;
8
+ fixNamesOnly: boolean;
4
9
  };
@@ -17,6 +17,10 @@ declare const _default: {
17
17
  deprecatedConfig: import("./utils/types").DeprecatedConfig;
18
18
  }
19
19
  ], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
20
+ 'no-empty-styled-expression': import("eslint").Rule.RuleModule;
21
+ 'no-exported-css': import("eslint").Rule.RuleModule;
22
+ 'no-exported-keyframes': import("eslint").Rule.RuleModule;
23
+ 'no-invalid-css-map': import("eslint").Rule.RuleModule;
20
24
  'no-margin': import("eslint").Rule.RuleModule;
21
25
  'no-nested-styles': import("eslint").Rule.RuleModule;
22
26
  'no-physical-properties': import("eslint").Rule.RuleModule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const noEmptyStyledExpressionRule: Rule.RuleModule;
3
+ export default noEmptyStyledExpressionRule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const noExportedCssRule: Rule.RuleModule;
3
+ export default noExportedCssRule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const noExportedKeyframesRule: Rule.RuleModule;
3
+ export default noExportedKeyframesRule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const noInvalidCssMapRule: Rule.RuleModule;
3
+ export default noInvalidCssMapRule;
@@ -0,0 +1,14 @@
1
+ import type { Rule } from 'eslint';
2
+ import type { CallExpression, ObjectExpression } from 'estree';
3
+ export declare const getCssMapObject: (node: CallExpression) => ObjectExpression | undefined;
4
+ export declare class CssMapObjectChecker {
5
+ private readonly allowedFunctionCalls;
6
+ private readonly cssMapObject;
7
+ private readonly report;
8
+ private readonly references;
9
+ constructor(cssMapObject: ObjectExpression, context: Rule.RuleContext);
10
+ private isNotWhitelistedFunction;
11
+ private checkCssMapObjectValue;
12
+ private checkCssMapObject;
13
+ run(): void;
14
+ }
@@ -1,3 +1,3 @@
1
1
  import type { Rule } from 'eslint';
2
2
  import { JSXElement } from 'eslint-codemod-utils';
3
- export declare const updateJSXAttributeByName: (oldName: string, newName: string, node: JSXElement, fixer: Rule.RuleFixer) => never[] | Rule.Fix;
3
+ export declare const updateJSXAttributeByName: (oldName: string, newName: string, node: JSXElement, fixer: Rule.RuleFixer) => Rule.Fix | never[];
@@ -0,0 +1,15 @@
1
+ import type { Rule, Scope as ScopeNamespace } from 'eslint';
2
+ import { ImportSource } from '../is-supported-import';
3
+ type Node = Rule.Node;
4
+ type RuleContext = Rule.RuleContext;
5
+ type Scope = ScopeNamespace.Scope;
6
+ type Yes = {
7
+ isExport: true;
8
+ node: Node;
9
+ };
10
+ type No = {
11
+ isExport: false;
12
+ };
13
+ type IsSupportedExport = Yes | No;
14
+ export declare const checkIfSupportedExport: (context: RuleContext, node: Node, importSources: ImportSource[], scope?: Scope) => IsSupportedExport;
15
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { Rule } from 'eslint';
2
+ import type { ImportSource } from '../is-supported-import';
3
+ type Node = Rule.Node;
4
+ type RuleContext = Rule.RuleContext;
5
+ /**
6
+ * Returns whether the node is a usage of the `styled` API in the libraries we support.
7
+ *
8
+ * @param nodes Nodes to check.
9
+ * @param context Rule context.
10
+ * @param importSources A list of libraries we support.
11
+ * @returns Whether the node is a usage of the `styled` API.
12
+ */
13
+ export declare const isStyledComponent: (nodes: Node[], context: RuleContext, importSources: ImportSource[]) => boolean;
14
+ export {};
@@ -0,0 +1,19 @@
1
+ import type { Rule } from 'eslint';
2
+ import { type SupportedNameChecker } from '../is-supported-import';
3
+ type RuleModule = Rule.RuleModule;
4
+ /**
5
+ * Creates a new ESLint rule for banning exporting certain function calls, e.g.
6
+ * `css` and `keyframes`.
7
+ *
8
+ * Copied from the `utils/create-no-exported-rule/` folder in @compiled/eslint-plugin.
9
+ *
10
+ * Requires an importSources option defined on the rule, which is used to define additional
11
+ * packages which should be checked as part of this rule.
12
+ *
13
+ * @param isUsage A function that checks whether the current node matches the desired
14
+ * function call to check.
15
+ * @param messageId The ESLint error message to use for lint violations.
16
+ * @returns An eslint rule.
17
+ */
18
+ export declare const createNoExportedRule: (isUsage: SupportedNameChecker, messageId: string) => RuleModule['create'];
19
+ export {};
@@ -30,7 +30,7 @@ export interface LintRuleMeta extends Omit<Rule.RuleMetaData, 'docs'> {
30
30
  */
31
31
  description: string;
32
32
  /**
33
- * Specifies the URL at which the full documentation can be accessed
33
+ * Specifies the URL at which the full documentation can be accessed.
34
34
  */
35
35
  url?: string | undefined;
36
36
  /**
@@ -0,0 +1,17 @@
1
+ import type { Rule } from 'eslint';
2
+ import { ImportDeclaration } from 'eslint-codemod-utils';
3
+ import { ImportSource } from './is-supported-import';
4
+ type RuleContext = Rule.RuleContext;
5
+ /**
6
+ * Get the first import declaration in the file that matches any of the packages
7
+ * in `importSources`.
8
+ *
9
+ * @param context Rule context.
10
+ * @param importSources The packages to check import statements for. If importSources
11
+ * contains more than one package, the first import statement
12
+ * detected in the file that matches any of the packages will be
13
+ * returned.
14
+ * @returns The first import declaration found in the file.
15
+ */
16
+ export declare const getFirstSupportedImport: (context: RuleContext, importSources: ImportSource[]) => ImportDeclaration | undefined;
17
+ export {};
@@ -1,16 +1,34 @@
1
- import type { Scope } from 'eslint';
1
+ import type { Rule, Scope } from 'eslint';
2
2
  import type { CallExpression } from 'estree';
3
3
  type Callee = CallExpression['callee'];
4
4
  type Reference = Scope.Reference;
5
5
  export declare const CSS_IN_JS_IMPORTS: {
6
- compiled: string;
7
- emotionReact: string;
8
- emotionCore: string;
9
- styledComponents: string;
10
- atlaskitCss: string;
6
+ readonly compiled: "@compiled/react";
7
+ readonly emotionReact: "@emotion/react";
8
+ readonly emotionCore: "@emotion/core";
9
+ readonly styledComponents: "styled-components";
10
+ readonly atlaskitCss: "@atlaskit/css";
11
+ readonly atlaskitPrimitives: "@atlaskit/primitives";
11
12
  };
12
- type ValidImportSources = string[];
13
- export type SupportedNameChecker = (nodeToCheck: Callee, referencesInScope: Reference[], importSources: ValidImportSources) => boolean;
13
+ export type ImportSource = string;
14
+ export type SupportedNameChecker = (nodeToCheck: Callee, referencesInScope: Reference[], importSources: ImportSource[]) => boolean;
15
+ export declare const DEFAULT_IMPORT_SOURCES: ImportSource[];
16
+ /**
17
+ * Given the ESLint rule context, extract and parse the value of the importSources rule option.
18
+ * The importSources option is used to define additional libraries for which an ESLint rule
19
+ * should apply to.
20
+ *
21
+ * Note that `@compiled/react` and `@atlaskit/css` are always included in importSources, regardless
22
+ * of what importSources is configured to by the user.
23
+ *
24
+ * @param context The rule context.
25
+ * @returns An array of strings representing what CSS-in-JS packages that should be checked, based
26
+ * on the rule options configuration.
27
+ */
28
+ export declare const getImportSources: (context: Rule.RuleContext) => ImportSource[];
14
29
  export declare const isCss: SupportedNameChecker;
15
30
  export declare const isCxFunction: SupportedNameChecker;
31
+ export declare const isCssMap: SupportedNameChecker;
32
+ export declare const isKeyframes: SupportedNameChecker;
33
+ export declare const isStyled: SupportedNameChecker;
16
34
  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.25.2",
4
+ "version": "8.27.0",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "publishConfig": {
7
7
  "registry": "https://registry.npmjs.org/"
@@ -41,6 +41,7 @@
41
41
  "@typescript-eslint/utils": "^5.48.1",
42
42
  "ajv": "^6.12.6",
43
43
  "eslint-codemod-utils": "^1.8.6",
44
+ "estraverse": "^5.3.0",
44
45
  "lodash": "^4.17.21",
45
46
  "semver": "^7.5.2"
46
47
  },
@@ -53,6 +54,7 @@
53
54
  "@emotion/react": "^11.7.1",
54
55
  "@emotion/styled": "^11.0.0",
55
56
  "@types/eslint": "^8.4.5",
57
+ "@types/estraverse": "^5.1.7",
56
58
  "eslint": "^7.7.0",
57
59
  "jscodeshift": "^0.13.0",
58
60
  "outdent": "^0.5.0",