@atlaskit/eslint-plugin-design-system 9.2.4 → 9.3.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 (95) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +1 -0
  3. package/constellation/index/usage.mdx +1 -0
  4. package/constellation/use-heading/usage.mdx +28 -0
  5. package/dist/cjs/ast-nodes/root.js +32 -0
  6. package/dist/cjs/presets/all.codegen.js +2 -1
  7. package/dist/cjs/rules/index.codegen.js +3 -1
  8. package/dist/cjs/rules/use-heading/config/index.js +15 -0
  9. package/dist/cjs/rules/use-heading/index.js +39 -0
  10. package/dist/cjs/rules/use-heading/transformers/common.js +19 -0
  11. package/dist/cjs/rules/use-heading/transformers/index.js +12 -0
  12. package/dist/cjs/rules/use-heading/transformers/native-elements.js +99 -0
  13. package/dist/cjs/rules/use-primitives/transformers/compiled-styled/index.js +1 -2
  14. package/dist/cjs/rules/use-primitives/transformers/emotion-css/index.js +1 -2
  15. package/dist/cjs/rules/use-primitives/utils/validate-styles.js +10 -3
  16. package/dist/cjs/rules/use-primitives-text/transformers/emphasis-elements.js +1 -2
  17. package/dist/cjs/rules/use-primitives-text/transformers/paragraph-elements.js +2 -3
  18. package/dist/cjs/rules/use-primitives-text/transformers/span-elements.js +1 -2
  19. package/dist/cjs/rules/use-primitives-text/transformers/strong-elements.js +1 -2
  20. package/dist/cjs/rules/use-tokens-space/transformers/style-property/index.js +1 -2
  21. package/dist/cjs/rules/utils/create-rule.js +4 -7
  22. package/dist/es2019/ast-nodes/root.js +34 -0
  23. package/dist/es2019/presets/all.codegen.js +2 -1
  24. package/dist/es2019/rules/index.codegen.js +3 -1
  25. package/dist/es2019/rules/use-heading/config/index.js +9 -0
  26. package/dist/es2019/rules/use-heading/index.js +33 -0
  27. package/dist/es2019/rules/use-heading/transformers/common.js +9 -0
  28. package/dist/es2019/rules/use-heading/transformers/index.js +1 -0
  29. package/dist/es2019/rules/use-heading/transformers/native-elements.js +89 -0
  30. package/dist/es2019/rules/use-primitives/transformers/compiled-styled/index.js +1 -2
  31. package/dist/es2019/rules/use-primitives/transformers/emotion-css/index.js +1 -2
  32. package/dist/es2019/rules/use-primitives/utils/validate-styles.js +10 -3
  33. package/dist/es2019/rules/use-primitives-text/transformers/emphasis-elements.js +1 -2
  34. package/dist/es2019/rules/use-primitives-text/transformers/paragraph-elements.js +2 -3
  35. package/dist/es2019/rules/use-primitives-text/transformers/span-elements.js +1 -2
  36. package/dist/es2019/rules/use-primitives-text/transformers/strong-elements.js +1 -2
  37. package/dist/es2019/rules/use-tokens-space/transformers/style-property/index.js +1 -2
  38. package/dist/es2019/rules/utils/create-rule.js +4 -6
  39. package/dist/esm/ast-nodes/root.js +32 -0
  40. package/dist/esm/presets/all.codegen.js +2 -1
  41. package/dist/esm/rules/index.codegen.js +3 -1
  42. package/dist/esm/rules/use-heading/config/index.js +9 -0
  43. package/dist/esm/rules/use-heading/index.js +33 -0
  44. package/dist/esm/rules/use-heading/transformers/common.js +9 -0
  45. package/dist/esm/rules/use-heading/transformers/index.js +1 -0
  46. package/dist/esm/rules/use-heading/transformers/native-elements.js +89 -0
  47. package/dist/esm/rules/use-primitives/transformers/compiled-styled/index.js +1 -2
  48. package/dist/esm/rules/use-primitives/transformers/emotion-css/index.js +1 -2
  49. package/dist/esm/rules/use-primitives/utils/validate-styles.js +10 -3
  50. package/dist/esm/rules/use-primitives-text/transformers/emphasis-elements.js +1 -2
  51. package/dist/esm/rules/use-primitives-text/transformers/paragraph-elements.js +2 -3
  52. package/dist/esm/rules/use-primitives-text/transformers/span-elements.js +1 -2
  53. package/dist/esm/rules/use-primitives-text/transformers/strong-elements.js +1 -2
  54. package/dist/esm/rules/use-tokens-space/transformers/style-property/index.js +1 -2
  55. package/dist/esm/rules/utils/create-rule.js +4 -6
  56. package/dist/types/ast-nodes/jsx-element.d.ts +2 -2
  57. package/dist/types/ast-nodes/root.d.ts +8 -0
  58. package/dist/types/index.codegen.d.ts +1 -0
  59. package/dist/types/presets/all.codegen.d.ts +2 -1
  60. package/dist/types/rules/ensure-design-token-usage/rule-meta.d.ts +1 -1
  61. package/dist/types/rules/index.codegen.d.ts +1 -0
  62. package/dist/types/rules/use-heading/config/index.d.ts +6 -0
  63. package/dist/types/rules/use-heading/index.d.ts +3 -0
  64. package/dist/types/rules/use-heading/transformers/common.d.ts +9 -0
  65. package/dist/types/rules/use-heading/transformers/index.d.ts +1 -0
  66. package/dist/types/rules/use-heading/transformers/native-elements.d.ts +18 -0
  67. package/dist/types/rules/utils/create-rule.d.ts +1 -37
  68. package/dist/types-ts4.5/ast-nodes/jsx-element.d.ts +2 -2
  69. package/dist/types-ts4.5/ast-nodes/root.d.ts +8 -0
  70. package/dist/types-ts4.5/index.codegen.d.ts +1 -0
  71. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  72. package/dist/types-ts4.5/rules/ensure-design-token-usage/rule-meta.d.ts +1 -1
  73. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  74. package/dist/types-ts4.5/rules/use-heading/config/index.d.ts +6 -0
  75. package/dist/types-ts4.5/rules/use-heading/index.d.ts +3 -0
  76. package/dist/types-ts4.5/rules/use-heading/transformers/common.d.ts +9 -0
  77. package/dist/types-ts4.5/rules/use-heading/transformers/index.d.ts +1 -0
  78. package/dist/types-ts4.5/rules/use-heading/transformers/native-elements.d.ts +18 -0
  79. package/dist/types-ts4.5/rules/utils/create-rule.d.ts +1 -37
  80. package/package.json +2 -2
  81. package/dist/cjs/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +0 -37
  82. package/dist/cjs/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +0 -37
  83. package/dist/cjs/rules/use-tokens-space/transformers/style-property/upsert-import-declaration.js +0 -37
  84. package/dist/es2019/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +0 -30
  85. package/dist/es2019/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +0 -30
  86. package/dist/es2019/rules/use-tokens-space/transformers/style-property/upsert-import-declaration.js +0 -30
  87. package/dist/esm/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +0 -29
  88. package/dist/esm/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +0 -29
  89. package/dist/esm/rules/use-tokens-space/transformers/style-property/upsert-import-declaration.js +0 -29
  90. package/dist/types/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.d.ts +0 -14
  91. package/dist/types/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.d.ts +0 -14
  92. package/dist/types/rules/use-tokens-space/transformers/style-property/upsert-import-declaration.d.ts +0 -14
  93. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.d.ts +0 -14
  94. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.d.ts +0 -14
  95. package/dist/types-ts4.5/rules/use-tokens-space/transformers/style-property/upsert-import-declaration.d.ts +0 -14
@@ -37,6 +37,7 @@ export var validateStyles = function validateStyles(node, config) {
37
37
  if (!property) {
38
38
  return false;
39
39
  }
40
+ var isDimensionProperty = !!supportedDimensionAttributesMap[property];
40
41
 
41
42
  // Currently, we handle values like `'8px'` (a 'Literal') or `token('space.100')` (a 'CallExpression')
42
43
  if (isNodeOfType(value, 'Literal')) {
@@ -51,8 +52,15 @@ export var validateStyles = function validateStyles(node, config) {
51
52
  // If it's a function call, then make sure it's the `token` function (and we have `css-property-with-tokens` enabled)
52
53
 
53
54
  // Short-circuit when token calls are found but pattern is not enabled in config
54
- if (isTokenCall(value) && !config.patterns.includes('css-property-with-tokens')) {
55
- return false;
55
+ if (isTokenCall(value)) {
56
+ if (!config.patterns.includes('css-property-with-tokens')) {
57
+ return false;
58
+ }
59
+
60
+ // Don't attempt to convert `width: token('space.100') -> width: 'size.100'`
61
+ if (isDimensionProperty) {
62
+ return false;
63
+ }
56
64
  }
57
65
 
58
66
  // Bail if it's a function, but that function call is not `tokens('<token>')`
@@ -66,7 +74,6 @@ export var validateStyles = function validateStyles(node, config) {
66
74
  // Bail if dimension property is found but pattern is not enabled in config
67
75
  // Note: We don't need to exhaustively re-check the key/value pair here. That's already been done above.
68
76
  // This is just to check wether 'dimension-properties' pattern is enabled and can be removed when the pattern is completely rolled out
69
- var isDimensionProperty = !!supportedDimensionAttributesMap[property];
70
77
  if (isDimensionProperty && !config.patterns.includes('dimension-properties')) {
71
78
  return false;
72
79
  }
@@ -3,7 +3,6 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
3
 
4
4
  import { isNodeOfType } from 'eslint-codemod-utils';
5
5
  import * as ast from '../../../ast-nodes';
6
- import { upsertImportDeclaration } from '../../use-primitives/transformers/emotion-css/upsert-import-declaration';
7
6
  import { addColorInheritAttributeFix, allowedAttrs, updateTestIdAttributeFix } from './common';
8
7
  export var EmphasisElements = {
9
8
  lint: function lint(node, _ref) {
@@ -59,7 +58,7 @@ export var EmphasisElements = {
59
58
  var context = _ref3.context,
60
59
  config = _ref3.config;
61
60
  return function (fixer) {
62
- var importFix = upsertImportDeclaration({
61
+ var importFix = ast.Root.upsertNamedImportDeclaration({
63
62
  module: '@atlaskit/primitives',
64
63
  specifiers: ['Text']
65
64
  }, context, fixer);
@@ -3,7 +3,6 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
3
 
4
4
  import { isNodeOfType } from 'eslint-codemod-utils';
5
5
  import * as ast from '../../../ast-nodes';
6
- import { upsertImportDeclaration } from '../../use-primitives/transformers/emotion-css/upsert-import-declaration';
7
6
  import { addColorInheritAttributeFix, allowedAttrs, updateTestIdAttributeFix } from './common';
8
7
  export var ParagraphElements = {
9
8
  lint: function lint(node, _ref) {
@@ -152,7 +151,7 @@ export var ParagraphElements = {
152
151
  var context = _ref3.context,
153
152
  config = _ref3.config;
154
153
  return function (fixer) {
155
- var importFix = upsertImportDeclaration({
154
+ var importFix = ast.Root.upsertNamedImportDeclaration({
156
155
  module: '@atlaskit/primitives',
157
156
  specifiers: ['Text']
158
157
  }, context, fixer);
@@ -173,7 +172,7 @@ export var ParagraphElements = {
173
172
  if (!isNodeOfType(node.parent, 'JSXElement') || !node.parent.closingElement) {
174
173
  return [];
175
174
  }
176
- var importFix = upsertImportDeclaration({
175
+ var importFix = ast.Root.upsertNamedImportDeclaration({
177
176
  module: '@atlaskit/primitives',
178
177
  specifiers: ['Text', 'Stack']
179
178
  }, context, fixer);
@@ -3,7 +3,6 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
3
 
4
4
  import { isNodeOfType } from 'eslint-codemod-utils';
5
5
  import * as ast from '../../../ast-nodes';
6
- import { upsertImportDeclaration } from '../../use-primitives/transformers/emotion-css/upsert-import-declaration';
7
6
  import { addColorInheritAttributeFix, allowedAttrs, hasTextChildrenOnly, updateTestIdAttributeFix } from './common';
8
7
  export var SpanElements = {
9
8
  lint: function lint(node, _ref) {
@@ -64,7 +63,7 @@ export var SpanElements = {
64
63
  var context = _ref3.context,
65
64
  config = _ref3.config;
66
65
  return function (fixer) {
67
- var importFix = upsertImportDeclaration({
66
+ var importFix = ast.Root.upsertNamedImportDeclaration({
68
67
  module: '@atlaskit/primitives',
69
68
  specifiers: ['Text']
70
69
  }, context, fixer);
@@ -3,7 +3,6 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
3
 
4
4
  import { isNodeOfType } from 'eslint-codemod-utils';
5
5
  import * as ast from '../../../ast-nodes';
6
- import { upsertImportDeclaration } from '../../use-primitives/transformers/emotion-css/upsert-import-declaration';
7
6
  import { addColorInheritAttributeFix, allowedAttrs, updateTestIdAttributeFix } from './common';
8
7
  export var StrongElements = {
9
8
  lint: function lint(node, _ref) {
@@ -59,7 +58,7 @@ export var StrongElements = {
59
58
  var context = _ref3.context,
60
59
  config = _ref3.config;
61
60
  return function (fixer) {
62
- var importFix = upsertImportDeclaration({
61
+ var importFix = ast.Root.upsertNamedImportDeclaration({
63
62
  module: '@atlaskit/primitives',
64
63
  specifiers: ['Text']
65
64
  }, context, fixer);
@@ -5,7 +5,6 @@ import * as ast from '../../../../ast-nodes';
5
5
  import { isStringOrNumber } from '../../utils';
6
6
  import { styleMap } from './style-map';
7
7
  import supported from './supported';
8
- import { upsertImportDeclaration } from './upsert-import-declaration';
9
8
  var messageId = 'noRawSpacingValues';
10
9
  export var StyleProperty = {
11
10
  lint: function lint(node, _ref) {
@@ -106,7 +105,7 @@ export var StyleProperty = {
106
105
  */
107
106
  _fix: function _fix(ref, context) {
108
107
  return function (fixer) {
109
- var importFix = upsertImportDeclaration({
108
+ var importFix = ast.Root.upsertNamedImportDeclaration({
110
109
  module: '@atlaskit/tokens',
111
110
  specifiers: ['token']
112
111
  }, context, fixer);
@@ -1,5 +1,5 @@
1
1
  import { ESLintUtils } from '@typescript-eslint/utils';
2
- // eslint-disable-next-line import/no-extraneous-dependencies
2
+ import { getCreateLintRule, getPathSafeName } from '@atlaskit/eslint-utils/create-rule';
3
3
 
4
4
  /**
5
5
  * We are moving to our own small abstraction to create a lint rule that we have the power
@@ -13,16 +13,14 @@ import { ESLintUtils } from '@typescript-eslint/utils';
13
13
  export var createRule = ESLintUtils.RuleCreator(function (name) {
14
14
  return getRuleUrl(name);
15
15
  });
16
+
16
17
  /**
17
18
  * Tiny wrapped over the ESLint rule module type that ensures
18
19
  * there is a docs link to our ESLint plugin documentation page,
19
20
  * as well as improving type support.
20
21
  */
21
- export var createLintRule = function createLintRule(rule) {
22
- rule.meta.docs.url = getRuleUrl(rule.meta.name);
23
- return rule;
24
- };
22
+ export var createLintRule = getCreateLintRule(getRuleUrl);
25
23
  function getRuleUrl(ruleName) {
26
- var name = ruleName.replace('/', '-'); // If it's a nested rule, ensure the url is clean and matches codegen/gatsby
24
+ var name = getPathSafeName(ruleName);
27
25
  return "https://atlassian.design/components/eslint-plugin-design-system/".concat(name, "/usage");
28
26
  }
@@ -1,5 +1,5 @@
1
1
  import type { Rule } from 'eslint';
2
- import { JSXAttribute, JSXElement, JSXSpreadAttribute } from 'eslint-codemod-utils';
2
+ import { JSXAttribute, JSXElement, JSXFragment, JSXSpreadAttribute } from 'eslint-codemod-utils';
3
3
  export declare const JSXElementHelper: {
4
4
  /**
5
5
  * Names of JSXElements can be any of:
@@ -18,7 +18,7 @@ export declare const JSXElementHelper: {
18
18
  getAttributeByName(node: JSXElement, name: string): JSXAttribute | undefined;
19
19
  containsSpreadAttributes(node: JSXElement): boolean;
20
20
  addAttribute(node: JSXElement, name: string, value: string, fixer: Rule.RuleFixer): Rule.Fix;
21
- getChildren(node: JSXElement): JSXElement['children'];
21
+ getChildren(node: JSXElement | JSXFragment): JSXElement['children'];
22
22
  hasAllowedAttrsOnly(node: JSXElement, allowedProps: string[]): boolean;
23
23
  };
24
24
  export { JSXElementHelper as JSXElement };
@@ -15,5 +15,13 @@ export declare const Root: {
15
15
  module: string;
16
16
  specifiers: ImportData;
17
17
  }, fixer: Rule.RuleFixer): Rule.Fix;
18
+ upsertNamedImportDeclaration({ module, specifiers, }: {
19
+ module: string;
20
+ specifiers: string[];
21
+ }, context: Rule.RuleContext, fixer: Rule.RuleFixer): Rule.Fix | undefined;
22
+ upsertDefaultImportDeclaration({ module, localName, }: {
23
+ module: string;
24
+ localName: string;
25
+ }, context: Rule.RuleContext, fixer: Rule.RuleFixer): Rule.Fix | undefined;
18
26
  };
19
27
  export {};
@@ -28,6 +28,7 @@ export declare const configs: {
28
28
  '@atlaskit/design-system/prefer-primitives': string;
29
29
  '@atlaskit/design-system/use-button-group-label': string;
30
30
  '@atlaskit/design-system/use-drawer-label': string;
31
+ '@atlaskit/design-system/use-heading': string;
31
32
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
32
33
  '@atlaskit/design-system/use-href-in-link-item': string;
33
34
  '@atlaskit/design-system/use-primitives': 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::d95217b658f807294de3c81123068bf1>>
3
+ * @codegen <<SignedSource::2e2cf6c0ecfe1b01f3eb24caa223f09e>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -31,6 +31,7 @@ declare const _default: {
31
31
  '@atlaskit/design-system/prefer-primitives': string;
32
32
  '@atlaskit/design-system/use-button-group-label': string;
33
33
  '@atlaskit/design-system/use-drawer-label': string;
34
+ '@atlaskit/design-system/use-heading': string;
34
35
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
35
36
  '@atlaskit/design-system/use-href-in-link-item': string;
36
37
  '@atlaskit/design-system/use-primitives': string;
@@ -1,3 +1,3 @@
1
- import { LintRuleMeta } from '../utils/create-rule';
1
+ import type { LintRuleMeta } from '@atlaskit/eslint-utils/create-rule';
2
2
  declare const ruleMeta: LintRuleMeta;
3
3
  export default ruleMeta;
@@ -28,6 +28,7 @@ declare const _default: {
28
28
  'prefer-primitives': import("eslint").Rule.RuleModule;
29
29
  'use-button-group-label': import("eslint").Rule.RuleModule;
30
30
  'use-drawer-label': import("eslint").Rule.RuleModule;
31
+ 'use-heading': import("eslint").Rule.RuleModule;
31
32
  'use-heading-level-in-spotlight-card': import("eslint").Rule.RuleModule;
32
33
  'use-href-in-link-item': import("eslint").Rule.RuleModule;
33
34
  'use-primitives': import("eslint").Rule.RuleModule;
@@ -0,0 +1,6 @@
1
+ type Pattern = 'native-elements';
2
+ export interface RuleConfig {
3
+ patterns: Pattern[];
4
+ }
5
+ export declare const getConfig: (overrides: Partial<RuleConfig>) => Required<RuleConfig>;
6
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,9 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ import { RuleConfig } from '../config';
4
+ export type MetaData = {
5
+ context: Rule.RuleContext;
6
+ config: RuleConfig;
7
+ };
8
+ export declare function updateTestIdAttributeFix(node: JSXElement, fixer: Rule.RuleFixer): Rule.Fix | undefined;
9
+ export declare const allowedAttrs: string[];
@@ -0,0 +1 @@
1
+ export { NativeElements } from './native-elements';
@@ -0,0 +1,18 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement, JSXIdentifier, JSXOpeningElement } from 'eslint-codemod-utils';
3
+ import { type MetaData } from './common';
4
+ type ValidTags = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
5
+ interface ValidHeadingElement extends JSXElement {
6
+ parent: Rule.Node;
7
+ openingElement: {
8
+ name: JSXIdentifier & {
9
+ name: ValidTags;
10
+ };
11
+ } & JSXOpeningElement;
12
+ }
13
+ export declare const NativeElements: {
14
+ lint(node: Rule.Node, { context, config }: MetaData): void;
15
+ _check(node: Rule.Node, { config }: MetaData): node is ValidHeadingElement;
16
+ _fix(node: ValidHeadingElement, { context }: MetaData): Rule.ReportFixer;
17
+ };
18
+ export {};
@@ -1,5 +1,4 @@
1
1
  import { ESLintUtils } from '@typescript-eslint/utils';
2
- import type { Rule } from 'eslint';
3
2
  /**
4
3
  * We are moving to our own small abstraction to create a lint rule that we have the power
5
4
  * to change and mold to our own needs.
@@ -10,44 +9,9 @@ import type { Rule } from 'eslint';
10
9
  * @deprecated
11
10
  */
12
11
  export declare const createRule: <TOptions extends readonly unknown[], TMessageIds extends string, TRuleListener extends import("@typescript-eslint/utils/dist/ts-eslint").RuleListener = import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>({ name, meta, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<TOptions, TMessageIds, TRuleListener>>) => import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<TMessageIds, TOptions, TRuleListener>;
13
- export interface LintRule extends Omit<Rule.RuleModule, 'meta'> {
14
- /**
15
- * Including this for backwards compat moving from the typescript-eslint util.
16
- */
17
- name?: never;
18
- meta: LintRuleMeta;
19
- }
20
- export interface LintRuleMeta extends Omit<Rule.RuleMetaData, 'docs'> {
21
- /**
22
- * Name of the rule.
23
- * Must match the folder it is in exactly else build will throw.
24
- * Add an exception in codegen.tsx for nested rules.
25
- */
26
- name: string;
27
- docs: {
28
- /**
29
- * Short description of what this rule does.
30
- */
31
- description: string;
32
- /**
33
- * Specifies the URL at which the full documentation can be accessed.
34
- */
35
- url?: string | undefined;
36
- /**
37
- * If this rule should be in the recommended preset or not.
38
- * Set to `false` to exclude it from the recommended preset.
39
- */
40
- recommended: boolean;
41
- /**
42
- * The severity level to be applied to this rule.
43
- * When setting to `"error"` it will mean releasing a breaking change.
44
- */
45
- severity: 'error' | 'warn';
46
- };
47
- }
48
12
  /**
49
13
  * Tiny wrapped over the ESLint rule module type that ensures
50
14
  * there is a docs link to our ESLint plugin documentation page,
51
15
  * as well as improving type support.
52
16
  */
53
- export declare const createLintRule: (rule: LintRule) => Rule.RuleModule;
17
+ export declare const createLintRule: (rule: import("@atlaskit/eslint-utils/create-rule").LintRule) => import("eslint").Rule.RuleModule;
@@ -1,5 +1,5 @@
1
1
  import type { Rule } from 'eslint';
2
- import { JSXAttribute, JSXElement, JSXSpreadAttribute } from 'eslint-codemod-utils';
2
+ import { JSXAttribute, JSXElement, JSXFragment, JSXSpreadAttribute } from 'eslint-codemod-utils';
3
3
  export declare const JSXElementHelper: {
4
4
  /**
5
5
  * Names of JSXElements can be any of:
@@ -18,7 +18,7 @@ export declare const JSXElementHelper: {
18
18
  getAttributeByName(node: JSXElement, name: string): JSXAttribute | undefined;
19
19
  containsSpreadAttributes(node: JSXElement): boolean;
20
20
  addAttribute(node: JSXElement, name: string, value: string, fixer: Rule.RuleFixer): Rule.Fix;
21
- getChildren(node: JSXElement): JSXElement['children'];
21
+ getChildren(node: JSXElement | JSXFragment): JSXElement['children'];
22
22
  hasAllowedAttrsOnly(node: JSXElement, allowedProps: string[]): boolean;
23
23
  };
24
24
  export { JSXElementHelper as JSXElement };
@@ -15,5 +15,13 @@ export declare const Root: {
15
15
  module: string;
16
16
  specifiers: ImportData;
17
17
  }, fixer: Rule.RuleFixer): Rule.Fix;
18
+ upsertNamedImportDeclaration({ module, specifiers, }: {
19
+ module: string;
20
+ specifiers: string[];
21
+ }, context: Rule.RuleContext, fixer: Rule.RuleFixer): Rule.Fix | undefined;
22
+ upsertDefaultImportDeclaration({ module, localName, }: {
23
+ module: string;
24
+ localName: string;
25
+ }, context: Rule.RuleContext, fixer: Rule.RuleFixer): Rule.Fix | undefined;
18
26
  };
19
27
  export {};
@@ -28,6 +28,7 @@ export declare const configs: {
28
28
  '@atlaskit/design-system/prefer-primitives': string;
29
29
  '@atlaskit/design-system/use-button-group-label': string;
30
30
  '@atlaskit/design-system/use-drawer-label': string;
31
+ '@atlaskit/design-system/use-heading': string;
31
32
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
32
33
  '@atlaskit/design-system/use-href-in-link-item': string;
33
34
  '@atlaskit/design-system/use-primitives': 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::d95217b658f807294de3c81123068bf1>>
3
+ * @codegen <<SignedSource::2e2cf6c0ecfe1b01f3eb24caa223f09e>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  declare const _default: {
@@ -31,6 +31,7 @@ declare const _default: {
31
31
  '@atlaskit/design-system/prefer-primitives': string;
32
32
  '@atlaskit/design-system/use-button-group-label': string;
33
33
  '@atlaskit/design-system/use-drawer-label': string;
34
+ '@atlaskit/design-system/use-heading': string;
34
35
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': string;
35
36
  '@atlaskit/design-system/use-href-in-link-item': string;
36
37
  '@atlaskit/design-system/use-primitives': string;
@@ -1,3 +1,3 @@
1
- import { LintRuleMeta } from '../utils/create-rule';
1
+ import type { LintRuleMeta } from '@atlaskit/eslint-utils/create-rule';
2
2
  declare const ruleMeta: LintRuleMeta;
3
3
  export default ruleMeta;
@@ -32,6 +32,7 @@ declare const _default: {
32
32
  'prefer-primitives': import("eslint").Rule.RuleModule;
33
33
  'use-button-group-label': import("eslint").Rule.RuleModule;
34
34
  'use-drawer-label': import("eslint").Rule.RuleModule;
35
+ 'use-heading': import("eslint").Rule.RuleModule;
35
36
  'use-heading-level-in-spotlight-card': import("eslint").Rule.RuleModule;
36
37
  'use-href-in-link-item': import("eslint").Rule.RuleModule;
37
38
  'use-primitives': import("eslint").Rule.RuleModule;
@@ -0,0 +1,6 @@
1
+ type Pattern = 'native-elements';
2
+ export interface RuleConfig {
3
+ patterns: Pattern[];
4
+ }
5
+ export declare const getConfig: (overrides: Partial<RuleConfig>) => Required<RuleConfig>;
6
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,9 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ import { RuleConfig } from '../config';
4
+ export type MetaData = {
5
+ context: Rule.RuleContext;
6
+ config: RuleConfig;
7
+ };
8
+ export declare function updateTestIdAttributeFix(node: JSXElement, fixer: Rule.RuleFixer): Rule.Fix | undefined;
9
+ export declare const allowedAttrs: string[];
@@ -0,0 +1 @@
1
+ export { NativeElements } from './native-elements';
@@ -0,0 +1,18 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement, JSXIdentifier, JSXOpeningElement } from 'eslint-codemod-utils';
3
+ import { type MetaData } from './common';
4
+ type ValidTags = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
5
+ interface ValidHeadingElement extends JSXElement {
6
+ parent: Rule.Node;
7
+ openingElement: {
8
+ name: JSXIdentifier & {
9
+ name: ValidTags;
10
+ };
11
+ } & JSXOpeningElement;
12
+ }
13
+ export declare const NativeElements: {
14
+ lint(node: Rule.Node, { context, config }: MetaData): void;
15
+ _check(node: Rule.Node, { config }: MetaData): node is ValidHeadingElement;
16
+ _fix(node: ValidHeadingElement, { context }: MetaData): Rule.ReportFixer;
17
+ };
18
+ export {};
@@ -1,5 +1,4 @@
1
1
  import { ESLintUtils } from '@typescript-eslint/utils';
2
- import type { Rule } from 'eslint';
3
2
  /**
4
3
  * We are moving to our own small abstraction to create a lint rule that we have the power
5
4
  * to change and mold to our own needs.
@@ -10,44 +9,9 @@ import type { Rule } from 'eslint';
10
9
  * @deprecated
11
10
  */
12
11
  export declare const createRule: <TOptions extends readonly unknown[], TMessageIds extends string, TRuleListener extends import("@typescript-eslint/utils/dist/ts-eslint").RuleListener = import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>({ name, meta, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<TOptions, TMessageIds, TRuleListener>>) => import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<TMessageIds, TOptions, TRuleListener>;
13
- export interface LintRule extends Omit<Rule.RuleModule, 'meta'> {
14
- /**
15
- * Including this for backwards compat moving from the typescript-eslint util.
16
- */
17
- name?: never;
18
- meta: LintRuleMeta;
19
- }
20
- export interface LintRuleMeta extends Omit<Rule.RuleMetaData, 'docs'> {
21
- /**
22
- * Name of the rule.
23
- * Must match the folder it is in exactly else build will throw.
24
- * Add an exception in codegen.tsx for nested rules.
25
- */
26
- name: string;
27
- docs: {
28
- /**
29
- * Short description of what this rule does.
30
- */
31
- description: string;
32
- /**
33
- * Specifies the URL at which the full documentation can be accessed.
34
- */
35
- url?: string | undefined;
36
- /**
37
- * If this rule should be in the recommended preset or not.
38
- * Set to `false` to exclude it from the recommended preset.
39
- */
40
- recommended: boolean;
41
- /**
42
- * The severity level to be applied to this rule.
43
- * When setting to `"error"` it will mean releasing a breaking change.
44
- */
45
- severity: 'error' | 'warn';
46
- };
47
- }
48
12
  /**
49
13
  * Tiny wrapped over the ESLint rule module type that ensures
50
14
  * there is a docs link to our ESLint plugin documentation page,
51
15
  * as well as improving type support.
52
16
  */
53
- export declare const createLintRule: (rule: LintRule) => Rule.RuleModule;
17
+ export declare const createLintRule: (rule: import("@atlaskit/eslint-utils/create-rule").LintRule) => import("eslint").Rule.RuleModule;
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": "9.2.4",
4
+ "version": "9.3.0",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
7
7
  "publishConfig": {
@@ -37,7 +37,7 @@
37
37
  ".": "./src/index.tsx"
38
38
  },
39
39
  "dependencies": {
40
- "@atlaskit/eslint-utils": "^1.0.0",
40
+ "@atlaskit/eslint-utils": "^1.1.0",
41
41
  "@atlaskit/tokens": "*",
42
42
  "@babel/runtime": "^7.0.0",
43
43
  "@typescript-eslint/utils": "^5.48.1",
@@ -1,37 +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.upsertImportDeclaration = void 0;
8
- var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
9
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
10
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
- /**
12
- * Currently this is defined here because it's not very general purpose.
13
- * If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
14
- * and the other half would be in `Import`.
15
- *
16
- * TODO: Refactor and move to `ast-nodes`
17
- *
18
- * Note: It does not handle default imports, namespace imports, or aliased imports.
19
- */
20
- var upsertImportDeclaration = exports.upsertImportDeclaration = function upsertImportDeclaration(_ref, context, fixer) {
21
- var module = _ref.module,
22
- specifiers = _ref.specifiers;
23
- // Find any imports that match the packageName
24
- var root = context.getSourceCode().ast.body;
25
- var importDeclarations = ast.Root.findImportsByModule(root, module);
26
-
27
- // The import doesn't exist yet, we can just insert a whole new one
28
- if (importDeclarations.length === 0) {
29
- return ast.Root.insertImport(root, {
30
- module: module,
31
- specifiers: specifiers
32
- }, fixer);
33
- }
34
-
35
- // The import exists so, modify the existing one
36
- return ast.Import.insertNamedSpecifiers(importDeclarations[0], specifiers, fixer);
37
- };
@@ -1,37 +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.upsertImportDeclaration = void 0;
8
- var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
9
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
10
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
- /**
12
- * Currently this is defined here because it's not very general purpose.
13
- * If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
14
- * and the other half would be in `Import`.
15
- *
16
- * TODO: Refactor and move to `ast-nodes`
17
- *
18
- * Note: It does not handle default imports, namespace imports, or aliased imports.
19
- */
20
- var upsertImportDeclaration = exports.upsertImportDeclaration = function upsertImportDeclaration(_ref, context, fixer) {
21
- var module = _ref.module,
22
- specifiers = _ref.specifiers;
23
- // Find any imports that match the packageName
24
- var root = context.getSourceCode().ast.body;
25
- var importDeclarations = ast.Root.findImportsByModule(root, module);
26
-
27
- // The import doesn't exist yet, we can just insert a whole new one
28
- if (importDeclarations.length === 0) {
29
- return ast.Root.insertImport(root, {
30
- module: module,
31
- specifiers: specifiers
32
- }, fixer);
33
- }
34
-
35
- // The import exists so, modify the existing one
36
- return ast.Import.insertNamedSpecifiers(importDeclarations[0], specifiers, fixer);
37
- };
@@ -1,37 +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.upsertImportDeclaration = void 0;
8
- var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
9
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
10
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
- /**
12
- * Currently this is defined here because it's not very general purpose.
13
- * If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
14
- * and the other half would be in `Import`.
15
- *
16
- * TODO: Refactor and move to `ast-nodes`
17
- *
18
- * Note: It does not handle default imports, namespace imports, or aliased imports.
19
- */
20
- var upsertImportDeclaration = exports.upsertImportDeclaration = function upsertImportDeclaration(_ref, context, fixer) {
21
- var module = _ref.module,
22
- specifiers = _ref.specifiers;
23
- // Find any imports that match the packageName
24
- var root = context.getSourceCode().ast.body;
25
- var importDeclarations = ast.Root.findImportsByModule(root, module);
26
-
27
- // The import doesn't exist yet, we can just insert a whole new one
28
- if (importDeclarations.length === 0) {
29
- return ast.Root.insertImport(root, {
30
- module: module,
31
- specifiers: specifiers
32
- }, fixer);
33
- }
34
-
35
- // The import exists so, modify the existing one
36
- return ast.Import.insertNamedSpecifiers(importDeclarations[0], specifiers, fixer);
37
- };