@atlaskit/eslint-plugin-design-system 13.9.0 → 13.10.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 (55) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -0
  3. package/dist/cjs/presets/all-flat.codegen.js +2 -1
  4. package/dist/cjs/presets/all.codegen.js +2 -1
  5. package/dist/cjs/presets/recommended-flat.codegen.js +2 -1
  6. package/dist/cjs/presets/recommended.codegen.js +2 -1
  7. package/dist/cjs/rules/index.codegen.js +3 -1
  8. package/dist/cjs/rules/no-html-heading/index.js +40 -0
  9. package/dist/cjs/rules/no-html-heading/node-types/index.js +19 -0
  10. package/dist/cjs/rules/no-html-heading/node-types/jsx-element/index.js +136 -0
  11. package/dist/cjs/rules/no-html-heading/node-types/styled-component/index.js +42 -0
  12. package/dist/cjs/rules/no-html-heading/node-types/supported.js +82 -0
  13. package/dist/es2019/presets/all-flat.codegen.js +2 -1
  14. package/dist/es2019/presets/all.codegen.js +2 -1
  15. package/dist/es2019/presets/recommended-flat.codegen.js +2 -1
  16. package/dist/es2019/presets/recommended.codegen.js +2 -1
  17. package/dist/es2019/rules/index.codegen.js +3 -1
  18. package/dist/es2019/rules/no-html-heading/index.js +34 -0
  19. package/dist/es2019/rules/no-html-heading/node-types/index.js +2 -0
  20. package/dist/es2019/rules/no-html-heading/node-types/jsx-element/index.js +99 -0
  21. package/dist/es2019/rules/no-html-heading/node-types/styled-component/index.js +37 -0
  22. package/dist/es2019/rules/no-html-heading/node-types/supported.js +72 -0
  23. package/dist/esm/presets/all-flat.codegen.js +2 -1
  24. package/dist/esm/presets/all.codegen.js +2 -1
  25. package/dist/esm/presets/recommended-flat.codegen.js +2 -1
  26. package/dist/esm/presets/recommended.codegen.js +2 -1
  27. package/dist/esm/rules/index.codegen.js +3 -1
  28. package/dist/esm/rules/no-html-heading/index.js +34 -0
  29. package/dist/esm/rules/no-html-heading/node-types/index.js +2 -0
  30. package/dist/esm/rules/no-html-heading/node-types/jsx-element/index.js +127 -0
  31. package/dist/esm/rules/no-html-heading/node-types/styled-component/index.js +36 -0
  32. package/dist/esm/rules/no-html-heading/node-types/supported.js +73 -0
  33. package/dist/types/index.codegen.d.ts +9 -0
  34. package/dist/types/presets/all-flat.codegen.d.ts +1 -0
  35. package/dist/types/presets/all.codegen.d.ts +1 -0
  36. package/dist/types/presets/recommended-flat.codegen.d.ts +1 -0
  37. package/dist/types/presets/recommended.codegen.d.ts +1 -0
  38. package/dist/types/rules/index.codegen.d.ts +1 -0
  39. package/dist/types/rules/no-html-heading/index.d.ts +3 -0
  40. package/dist/types/rules/no-html-heading/node-types/index.d.ts +2 -0
  41. package/dist/types/rules/no-html-heading/node-types/jsx-element/index.d.ts +8 -0
  42. package/dist/types/rules/no-html-heading/node-types/styled-component/index.d.ts +8 -0
  43. package/dist/types/rules/no-html-heading/node-types/supported.d.ts +7 -0
  44. package/dist/types-ts4.5/index.codegen.d.ts +9 -0
  45. package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +1 -0
  46. package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -0
  47. package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +1 -0
  48. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -0
  49. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  50. package/dist/types-ts4.5/rules/no-html-heading/index.d.ts +3 -0
  51. package/dist/types-ts4.5/rules/no-html-heading/node-types/index.d.ts +2 -0
  52. package/dist/types-ts4.5/rules/no-html-heading/node-types/jsx-element/index.d.ts +8 -0
  53. package/dist/types-ts4.5/rules/no-html-heading/node-types/styled-component/index.d.ts +8 -0
  54. package/dist/types-ts4.5/rules/no-html-heading/node-types/supported.d.ts +7 -0
  55. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 13.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#145568](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/145568)
8
+ [`43180d95604d6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/43180d95604d6) -
9
+ Add rule to encourage use of the DS heading component over native HTML headings.
10
+
3
11
  ## 13.9.0
4
12
 
5
13
  ### Minor Changes
package/README.md CHANGED
@@ -69,6 +69,7 @@ module.exports = {
69
69
  | <a href="./src/rules/no-html-anchor/README.md">no-html-anchor</a> | Discourage direct usage of HTML anchor elements in favor of Atlassian Design System link components. | Yes | | Yes |
70
70
  | <a href="./src/rules/no-html-button/README.md">no-html-button</a> | Discourage direct usage of HTML button elements in favor of Atlassian Design System button components. | Yes | | |
71
71
  | <a href="./src/rules/no-html-checkbox/README.md">no-html-checkbox</a> | Discourage direct usage of HTML checkbox elements in favor of the Atlassian Design System checkbox component. | Yes | | Yes |
72
+ | <a href="./src/rules/no-html-heading/README.md">no-html-heading</a> | Discourage direct usage of HTML heading elements in favor of Atlassian Design System heading components. | Yes | | Yes |
72
73
  | <a href="./src/rules/no-html-image/README.md">no-html-image</a> | Discourage direct usage of HTML image elements in favor of the Atlassian Design System image component. | Yes | | Yes |
73
74
  | <a href="./src/rules/no-html-range/README.md">no-html-range</a> | Discourage direct usage of HTML range elements in favor of the Atlassian Design System range component. | Yes | | Yes |
74
75
  | <a href="./src/rules/no-html-select/README.md">no-html-select</a> | Discourage direct usage of HTML select elements in favor of the Atlassian Design System select component. | Yes | | Yes |
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::f202c585a3745f4765e0515889577a22>>
9
+ * @codegen <<SignedSource::aa1526cdf8f7bbdd8e89e584da433397>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -30,6 +30,7 @@ var _default = exports.default = {
30
30
  '@atlaskit/design-system/no-html-anchor': 'warn',
31
31
  '@atlaskit/design-system/no-html-button': 'warn',
32
32
  '@atlaskit/design-system/no-html-checkbox': 'warn',
33
+ '@atlaskit/design-system/no-html-heading': 'warn',
33
34
  '@atlaskit/design-system/no-html-image': 'warn',
34
35
  '@atlaskit/design-system/no-html-range': 'warn',
35
36
  '@atlaskit/design-system/no-html-select': 'warn',
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::6b4a8032ac1f59781b9675b9cc053a55>>
9
+ * @codegen <<SignedSource::ec47b97e20d77ba1f43c2211aeeed2f6>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -29,6 +29,7 @@ var _default = exports.default = {
29
29
  '@atlaskit/design-system/no-html-anchor': 'warn',
30
30
  '@atlaskit/design-system/no-html-button': 'warn',
31
31
  '@atlaskit/design-system/no-html-checkbox': 'warn',
32
+ '@atlaskit/design-system/no-html-heading': 'warn',
32
33
  '@atlaskit/design-system/no-html-image': 'warn',
33
34
  '@atlaskit/design-system/no-html-range': 'warn',
34
35
  '@atlaskit/design-system/no-html-select': 'warn',
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::88336f6c2f8c5d33f84730619006b49e>>
9
+ * @codegen <<SignedSource::4ad986601bfd6f0081e3bc6909694979>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -25,6 +25,7 @@ var _default = exports.default = {
25
25
  '@atlaskit/design-system/no-html-anchor': 'warn',
26
26
  '@atlaskit/design-system/no-html-button': 'warn',
27
27
  '@atlaskit/design-system/no-html-checkbox': 'warn',
28
+ '@atlaskit/design-system/no-html-heading': 'warn',
28
29
  '@atlaskit/design-system/no-html-image': 'warn',
29
30
  '@atlaskit/design-system/no-html-range': 'warn',
30
31
  '@atlaskit/design-system/no-html-select': 'warn',
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::829b781e15e90c3a142273e2b153459f>>
9
+ * @codegen <<SignedSource::18dcf6fce30892e43fb5fb76339c261e>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -24,6 +24,7 @@ var _default = exports.default = {
24
24
  '@atlaskit/design-system/no-html-anchor': 'warn',
25
25
  '@atlaskit/design-system/no-html-button': 'warn',
26
26
  '@atlaskit/design-system/no-html-checkbox': 'warn',
27
+ '@atlaskit/design-system/no-html-heading': 'warn',
27
28
  '@atlaskit/design-system/no-html-image': 'warn',
28
29
  '@atlaskit/design-system/no-html-range': 'warn',
29
30
  '@atlaskit/design-system/no-html-select': 'warn',
@@ -25,6 +25,7 @@ var _noExportedKeyframes = _interopRequireDefault(require("./no-exported-keyfram
25
25
  var _noHtmlAnchor = _interopRequireDefault(require("./no-html-anchor"));
26
26
  var _noHtmlButton = _interopRequireDefault(require("./no-html-button"));
27
27
  var _noHtmlCheckbox = _interopRequireDefault(require("./no-html-checkbox"));
28
+ var _noHtmlHeading = _interopRequireDefault(require("./no-html-heading"));
28
29
  var _noHtmlImage = _interopRequireDefault(require("./no-html-image"));
29
30
  var _noHtmlRange = _interopRequireDefault(require("./no-html-range"));
30
31
  var _noHtmlSelect = _interopRequireDefault(require("./no-html-select"));
@@ -62,7 +63,7 @@ var _useTokensTypography = _interopRequireDefault(require("./use-tokens-typograp
62
63
  var _useVisuallyHidden = _interopRequireDefault(require("./use-visually-hidden"));
63
64
  /**
64
65
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
65
- * @codegen <<SignedSource::60d053061448c69290fba282ee307366>>
66
+ * @codegen <<SignedSource::19fc297469c40b1fa9fd64c9f9313ba7>>
66
67
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
67
68
  */
68
69
 
@@ -87,6 +88,7 @@ var rules = exports.rules = {
87
88
  'no-html-anchor': _noHtmlAnchor.default,
88
89
  'no-html-button': _noHtmlButton.default,
89
90
  'no-html-checkbox': _noHtmlCheckbox.default,
91
+ 'no-html-heading': _noHtmlHeading.default,
90
92
  'no-html-image': _noHtmlImage.default,
91
93
  'no-html-range': _noHtmlRange.default,
92
94
  'no-html-select': _noHtmlSelect.default,
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _createRule = require("../utils/create-rule");
8
+ var _nodeTypes = require("./node-types");
9
+ var rule = (0, _createRule.createLintRule)({
10
+ meta: {
11
+ name: 'no-html-heading',
12
+ type: 'suggestion',
13
+ hasSuggestions: true,
14
+ docs: {
15
+ description: 'Discourage direct usage of HTML heading elements in favor of Atlassian Design System heading components.',
16
+ recommended: true,
17
+ severity: 'warn'
18
+ },
19
+ messages: {
20
+ noHtmlHeading: "This <{{ name }}> should be replaced with a heading component from the Atlassian Design System. ADS headings include ensure accessible implementations and provide access to ADS styling features like design tokens."
21
+ }
22
+ },
23
+ create: function create(context) {
24
+ return {
25
+ // transforms styled.<heading>(...) usages
26
+ CallExpression: function CallExpression(node) {
27
+ _nodeTypes.StyledComponent.lint(node, {
28
+ context: context
29
+ });
30
+ },
31
+ // transforms <heading css={...}> usages
32
+ JSXElement: function JSXElement(node) {
33
+ _nodeTypes.JSXElement.lint(node, {
34
+ context: context
35
+ });
36
+ }
37
+ };
38
+ }
39
+ });
40
+ var _default = exports.default = rule;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "JSXElement", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _jsxElement.JSXElement;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "StyledComponent", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _styledComponent.StyledComponent;
16
+ }
17
+ });
18
+ var _styledComponent = require("./styled-component");
19
+ var _jsxElement = require("./jsx-element");
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.JSXElement = void 0;
8
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
9
+ var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
10
+ var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
11
+ var _supported = require("../supported");
12
+ 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); }
13
+ 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 && {}.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; }
14
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
15
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
16
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
17
+ function isImportDeclaration(node) {
18
+ return node.type === 'ImportDeclaration';
19
+ }
20
+ var JSXElement = exports.JSXElement = {
21
+ lint: function lint(node, _ref) {
22
+ var context = _ref.context;
23
+ if (!(0, _supported.isSupportedForLint)(node)) {
24
+ return;
25
+ }
26
+ var nodeName = ast.JSXElement.getName(node);
27
+ var sourceCode = (0, _contextCompat.getSourceCode)(context);
28
+ var importDeclarations = sourceCode.ast.body.filter(isImportDeclaration);
29
+ var existingHeadingName = null;
30
+ var usedNames = new Set();
31
+
32
+ // Check for existing imports
33
+ var _iterator = _createForOfIteratorHelper(importDeclarations),
34
+ _step;
35
+ try {
36
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
37
+ var declaration = _step.value;
38
+ var _iterator2 = _createForOfIteratorHelper(declaration.specifiers),
39
+ _step2;
40
+ try {
41
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
42
+ var specifier = _step2.value;
43
+ usedNames.add(specifier.local.name);
44
+ }
45
+ } catch (err) {
46
+ _iterator2.e(err);
47
+ } finally {
48
+ _iterator2.f();
49
+ }
50
+ if (declaration.source.value === '@atlaskit/heading') {
51
+ var defaultSpecifier = declaration.specifiers.find(function (specifier) {
52
+ return specifier.type === 'ImportDefaultSpecifier';
53
+ });
54
+ if (defaultSpecifier) {
55
+ existingHeadingName = defaultSpecifier.local.name;
56
+ }
57
+ }
58
+ }
59
+ } catch (err) {
60
+ _iterator.e(err);
61
+ } finally {
62
+ _iterator.f();
63
+ }
64
+ var generateUniqueName = function generateUniqueName(baseName) {
65
+ var index = 1;
66
+ var newName = baseName;
67
+ while (usedNames.has(newName)) {
68
+ newName = "".concat(baseName).concat(index);
69
+ index++;
70
+ }
71
+ return newName;
72
+ };
73
+ var headingName = existingHeadingName || generateUniqueName('Heading');
74
+ context.report({
75
+ node: node.openingElement,
76
+ messageId: 'noHtmlHeading',
77
+ data: {
78
+ name: nodeName
79
+ },
80
+ suggest: [{
81
+ desc: 'Replace with Heading component from @atlaskit/heading',
82
+ fix: function fix(fixer) {
83
+ var _node$closingElement;
84
+ var openingTagRange = node.openingElement.range;
85
+ var closingTagRange = (_node$closingElement = node.closingElement) === null || _node$closingElement === void 0 ? void 0 : _node$closingElement.range;
86
+ var elementName = (0, _eslintCodemodUtils.isNodeOfType)(node.openingElement.name, 'JSXIdentifier') ? node.openingElement.name.name : '';
87
+ var attributesText = node.openingElement.attributes
88
+ // Don't bring in the "role" or the "aria-level" because it's not needed
89
+ .filter(function (attr) {
90
+ return !(0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXAttribute') || typeof attr.name.name === 'string' && !['role', 'aria-level'].includes(attr.name.name);
91
+ }).map(function (attr) {
92
+ return sourceCode.getText(attr);
93
+ }).join(' ');
94
+
95
+ // Get the heading level
96
+ var headingLevel = '';
97
+ var ariaLevel = node.openingElement.attributes.find(function (attr) {
98
+ return (0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXAttribute') && attr.name.name === 'aria-level';
99
+ });
100
+ if (ariaLevel && (0, _eslintCodemodUtils.isNodeOfType)(ariaLevel, 'JSXAttribute')) {
101
+ var _ariaLevel$value, _ariaLevel$value2;
102
+ // If it's a string
103
+ if (((_ariaLevel$value = ariaLevel.value) === null || _ariaLevel$value === void 0 ? void 0 : _ariaLevel$value.type) === 'Literal' && ariaLevel.value.value) {
104
+ headingLevel = "h".concat(ariaLevel.value.value);
105
+ // If it's a number or some other literal in an expression container
106
+ } else if (((_ariaLevel$value2 = ariaLevel.value) === null || _ariaLevel$value2 === void 0 ? void 0 : _ariaLevel$value2.type) === 'JSXExpressionContainer' && ariaLevel.value.expression.type === 'Literal' && ariaLevel.value.expression.value) {
107
+ headingLevel = "h".concat(ariaLevel.value.expression.value);
108
+ }
109
+ } else if (elementName.match(/h[1-6]/)) {
110
+ headingLevel = elementName;
111
+ }
112
+ var fixers = [];
113
+
114
+ // Replace <a> with <Heading> and retain attributes
115
+ if (openingTagRange) {
116
+ if (node.openingElement.selfClosing) {
117
+ fixers.push(fixer.replaceTextRange([openingTagRange[0] + 1, openingTagRange[1] - 1], "".concat(headingName).concat(headingLevel ? " as=\"".concat(headingLevel, "\"") : '').concat(attributesText ? " ".concat(attributesText) : '', " /")));
118
+ } else {
119
+ fixers.push(fixer.replaceTextRange([openingTagRange[0] + 1, openingTagRange[1] - 1], "".concat(headingName).concat(headingLevel ? " as=\"".concat(headingLevel, "\"") : '').concat(attributesText ? " ".concat(attributesText) : '')));
120
+ }
121
+ }
122
+ if (closingTagRange && !node.openingElement.selfClosing) {
123
+ fixers.push(fixer.replaceTextRange([closingTagRange[0] + 2, closingTagRange[1] - 1], headingName));
124
+ }
125
+
126
+ // Add import if not present
127
+ if (!existingHeadingName) {
128
+ var importStatement = "import ".concat(headingName, " from '@atlaskit/heading';\n");
129
+ fixers.push(fixer.insertTextBefore(sourceCode.ast, importStatement));
130
+ }
131
+ return fixers;
132
+ }
133
+ }]
134
+ });
135
+ }
136
+ };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StyledComponent = void 0;
7
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
8
+ var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
9
+ var _getJsxElementByName2 = require("../../../utils/get-jsx-element-by-name");
10
+ var _getStyledComponentCall = require("../../../utils/get-styled-component-call");
11
+ var _supported = require("../supported");
12
+ /* eslint-disable @repo/internal/react/require-jsdoc */
13
+
14
+ var StyledComponent = exports.StyledComponent = {
15
+ lint: function lint(node, _ref) {
16
+ var _getJsxElementByName;
17
+ var context = _ref.context;
18
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression') || !(0, _eslintCodemodUtils.isNodeOfType)(node.callee, 'MemberExpression') || !(0, _eslintCodemodUtils.isNodeOfType)(node.callee.object, 'Identifier') || !(0, _eslintCodemodUtils.isNodeOfType)(node.callee.property, 'Identifier')) {
19
+ return;
20
+ }
21
+ var styles = (0, _getStyledComponentCall.getStyledComponentCall)(node);
22
+ var elementName = node.callee.property.name;
23
+ if (!styles || !(0, _eslintCodemodUtils.isNodeOfType)(styles.id, 'Identifier')) {
24
+ return;
25
+ }
26
+ var jsxElement = (_getJsxElementByName = (0, _getJsxElementByName2.getJsxElementByName)(styles.id.name, (0, _contextCompat.getScope)(context, node))) === null || _getJsxElementByName === void 0 ? void 0 : _getJsxElementByName.parent;
27
+ if (!jsxElement) {
28
+ // If there's no JSX element, we can't determine if it's being used as an heading or not
29
+ return;
30
+ }
31
+ if (jsxElement && !(0, _supported.isSupportedForLint)(jsxElement, elementName)) {
32
+ return;
33
+ }
34
+ context.report({
35
+ node: styles,
36
+ messageId: 'noHtmlHeading',
37
+ data: {
38
+ name: node.callee.property.name
39
+ }
40
+ });
41
+ }
42
+ };
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.isSupportedForLint = isSupportedForLint;
8
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
9
+ var ast = _interopRequireWildcard(require("../../../ast-nodes"));
10
+ 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); }
11
+ 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 && {}.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; }
12
+ var supportedElements = [{
13
+ name: 'h1'
14
+ }, {
15
+ name: 'h2'
16
+ }, {
17
+ name: 'h3'
18
+ }, {
19
+ name: 'h4'
20
+ }, {
21
+ name: 'h5'
22
+ }, {
23
+ name: 'h6'
24
+ }, {
25
+ name: '*',
26
+ attributes: [{
27
+ name: 'role',
28
+ values: ['heading']
29
+ }]
30
+ }];
31
+
32
+ /**
33
+ * Determines if the given JSX element is a supported element to lint with this rule.
34
+ */
35
+ function isSupportedForLint(jsxNode, elementName) {
36
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(jsxNode, 'JSXElement')) {
37
+ return false;
38
+ }
39
+
40
+ // Allow passing in the element name because the jsxNode doesn't
41
+ // represent the element name with styled components
42
+ var elName = elementName || ast.JSXElement.getName(jsxNode);
43
+ if (!elName) {
44
+ return false;
45
+ }
46
+
47
+ // Only check native HTML elements, not components
48
+ if (elName[0] !== elName[0].toLowerCase()) {
49
+ return false;
50
+ }
51
+ var supportedElement = supportedElements.find(function (_ref) {
52
+ var name = _ref.name;
53
+ return name === elName;
54
+ });
55
+ if (!supportedElement) {
56
+ supportedElement = supportedElements.find(function (_ref2) {
57
+ var name = _ref2.name;
58
+ return name === '*';
59
+ });
60
+ }
61
+ if (!supportedElement) {
62
+ return false;
63
+ }
64
+
65
+ // Check if the element has any attributes that are not supported
66
+ var attributes = ast.JSXElement.getAttributes(jsxNode);
67
+ if (supportedElement.attributes && !supportedElement.attributes.every(function (_ref3) {
68
+ var name = _ref3.name,
69
+ values = _ref3.values;
70
+ return attributes.some(function (attribute) {
71
+ if (attribute.type === 'JSXSpreadAttribute') {
72
+ return false;
73
+ }
74
+ var isMatchingName = attribute.name.name === name;
75
+ var isMatchingValues = values && attribute.value && attribute.value.type === 'Literal' && typeof attribute.value.value === 'string' && (values === null || values === void 0 ? void 0 : values.includes(attribute.value.value));
76
+ return isMatchingName && isMatchingValues;
77
+ });
78
+ })) {
79
+ return false;
80
+ }
81
+ return true;
82
+ }
@@ -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::f202c585a3745f4765e0515889577a22>>
3
+ * @codegen <<SignedSource::aa1526cdf8f7bbdd8e89e584da433397>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -25,6 +25,7 @@ export default {
25
25
  '@atlaskit/design-system/no-html-anchor': 'warn',
26
26
  '@atlaskit/design-system/no-html-button': 'warn',
27
27
  '@atlaskit/design-system/no-html-checkbox': 'warn',
28
+ '@atlaskit/design-system/no-html-heading': 'warn',
28
29
  '@atlaskit/design-system/no-html-image': 'warn',
29
30
  '@atlaskit/design-system/no-html-range': 'warn',
30
31
  '@atlaskit/design-system/no-html-select': 'warn',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::6b4a8032ac1f59781b9675b9cc053a55>>
3
+ * @codegen <<SignedSource::ec47b97e20d77ba1f43c2211aeeed2f6>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -24,6 +24,7 @@ export default {
24
24
  '@atlaskit/design-system/no-html-anchor': 'warn',
25
25
  '@atlaskit/design-system/no-html-button': 'warn',
26
26
  '@atlaskit/design-system/no-html-checkbox': 'warn',
27
+ '@atlaskit/design-system/no-html-heading': 'warn',
27
28
  '@atlaskit/design-system/no-html-image': 'warn',
28
29
  '@atlaskit/design-system/no-html-range': 'warn',
29
30
  '@atlaskit/design-system/no-html-select': 'warn',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::88336f6c2f8c5d33f84730619006b49e>>
3
+ * @codegen <<SignedSource::4ad986601bfd6f0081e3bc6909694979>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -20,6 +20,7 @@ export default {
20
20
  '@atlaskit/design-system/no-html-anchor': 'warn',
21
21
  '@atlaskit/design-system/no-html-button': 'warn',
22
22
  '@atlaskit/design-system/no-html-checkbox': 'warn',
23
+ '@atlaskit/design-system/no-html-heading': 'warn',
23
24
  '@atlaskit/design-system/no-html-image': 'warn',
24
25
  '@atlaskit/design-system/no-html-range': 'warn',
25
26
  '@atlaskit/design-system/no-html-select': 'warn',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::829b781e15e90c3a142273e2b153459f>>
3
+ * @codegen <<SignedSource::18dcf6fce30892e43fb5fb76339c261e>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -19,6 +19,7 @@ export default {
19
19
  '@atlaskit/design-system/no-html-anchor': 'warn',
20
20
  '@atlaskit/design-system/no-html-button': 'warn',
21
21
  '@atlaskit/design-system/no-html-checkbox': 'warn',
22
+ '@atlaskit/design-system/no-html-heading': 'warn',
22
23
  '@atlaskit/design-system/no-html-image': 'warn',
23
24
  '@atlaskit/design-system/no-html-range': 'warn',
24
25
  '@atlaskit/design-system/no-html-select': 'warn',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::60d053061448c69290fba282ee307366>>
3
+ * @codegen <<SignedSource::19fc297469c40b1fa9fd64c9f9313ba7>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import consistentCssPropUsage from './consistent-css-prop-usage';
@@ -23,6 +23,7 @@ import noExportedKeyframes from './no-exported-keyframes';
23
23
  import noHtmlAnchor from './no-html-anchor';
24
24
  import noHtmlButton from './no-html-button';
25
25
  import noHtmlCheckbox from './no-html-checkbox';
26
+ import noHtmlHeading from './no-html-heading';
26
27
  import noHtmlImage from './no-html-image';
27
28
  import noHtmlRange from './no-html-range';
28
29
  import noHtmlSelect from './no-html-select';
@@ -79,6 +80,7 @@ export const rules = {
79
80
  'no-html-anchor': noHtmlAnchor,
80
81
  'no-html-button': noHtmlButton,
81
82
  'no-html-checkbox': noHtmlCheckbox,
83
+ 'no-html-heading': noHtmlHeading,
82
84
  'no-html-image': noHtmlImage,
83
85
  'no-html-range': noHtmlRange,
84
86
  'no-html-select': noHtmlSelect,
@@ -0,0 +1,34 @@
1
+ import { createLintRule } from '../utils/create-rule';
2
+ import { JSXElement, StyledComponent } from './node-types';
3
+ const rule = createLintRule({
4
+ meta: {
5
+ name: 'no-html-heading',
6
+ type: 'suggestion',
7
+ hasSuggestions: true,
8
+ docs: {
9
+ description: 'Discourage direct usage of HTML heading elements in favor of Atlassian Design System heading components.',
10
+ recommended: true,
11
+ severity: 'warn'
12
+ },
13
+ messages: {
14
+ noHtmlHeading: `This <{{ name }}> should be replaced with a heading component from the Atlassian Design System. ADS headings include ensure accessible implementations and provide access to ADS styling features like design tokens.`
15
+ }
16
+ },
17
+ create(context) {
18
+ return {
19
+ // transforms styled.<heading>(...) usages
20
+ CallExpression(node) {
21
+ StyledComponent.lint(node, {
22
+ context
23
+ });
24
+ },
25
+ // transforms <heading css={...}> usages
26
+ JSXElement(node) {
27
+ JSXElement.lint(node, {
28
+ context
29
+ });
30
+ }
31
+ };
32
+ }
33
+ });
34
+ export default rule;
@@ -0,0 +1,2 @@
1
+ export { StyledComponent } from './styled-component';
2
+ export { JSXElement } from './jsx-element';