@atlaskit/eslint-plugin-design-system 10.5.0 → 10.6.1

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 (39) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +1 -0
  3. package/configs/deprecated.json +263 -273
  4. package/constellation/index/usage.mdx +1 -0
  5. package/constellation/use-menu-section-title/usage.mdx +55 -0
  6. package/dist/cjs/common/token-maps.partial.js +1 -1
  7. package/dist/cjs/presets/all.codegen.js +2 -1
  8. package/dist/cjs/presets/recommended.codegen.js +2 -1
  9. package/dist/cjs/rules/index.codegen.js +3 -1
  10. package/dist/cjs/rules/use-latest-xcss-syntax/transformers/style-property/index.js +10 -1
  11. package/dist/cjs/rules/use-menu-section-title/index.js +85 -0
  12. package/dist/configs/deprecated.json +263 -273
  13. package/dist/es2019/common/token-maps.partial.js +1 -1
  14. package/dist/es2019/presets/all.codegen.js +2 -1
  15. package/dist/es2019/presets/recommended.codegen.js +2 -1
  16. package/dist/es2019/rules/index.codegen.js +3 -1
  17. package/dist/es2019/rules/use-latest-xcss-syntax/transformers/style-property/index.js +10 -1
  18. package/dist/es2019/rules/use-menu-section-title/index.js +79 -0
  19. package/dist/esm/common/token-maps.partial.js +1 -1
  20. package/dist/esm/presets/all.codegen.js +2 -1
  21. package/dist/esm/presets/recommended.codegen.js +2 -1
  22. package/dist/esm/rules/index.codegen.js +3 -1
  23. package/dist/esm/rules/use-latest-xcss-syntax/transformers/style-property/index.js +10 -1
  24. package/dist/esm/rules/use-menu-section-title/index.js +79 -0
  25. package/dist/types/common/token-maps.partial.d.ts +1 -1
  26. package/dist/types/index.codegen.d.ts +2 -0
  27. package/dist/types/presets/all.codegen.d.ts +2 -1
  28. package/dist/types/presets/recommended.codegen.d.ts +2 -1
  29. package/dist/types/rules/index.codegen.d.ts +1 -0
  30. package/dist/types/rules/use-menu-section-title/index.d.ts +3 -0
  31. package/dist/types/rules/use-primitives/transformers/index.d.ts +1 -1
  32. package/dist/types-ts4.5/common/token-maps.partial.d.ts +1 -1
  33. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  34. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  35. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
  36. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  37. package/dist/types-ts4.5/rules/use-menu-section-title/index.d.ts +3 -0
  38. package/dist/types-ts4.5/rules/use-primitives/transformers/index.d.ts +1 -1
  39. package/package.json +2 -2
@@ -0,0 +1,55 @@
1
+ # use-menu-section-title
2
+
3
+ Section should have an accessible title or a reference to it, so that users of assistive
4
+ technologies could have contextual information of interaction with current element.
5
+
6
+ ## Examples
7
+
8
+ This rule will indicate user with warning to strongly recommend usage of either `title` or `titleId`
9
+ prop.
10
+
11
+ ### Incorrect
12
+
13
+ ```tsx
14
+ <Section>
15
+ ^^^^^^ Missing either `title` or `titleId` prop.
16
+ Section content
17
+ </Section>
18
+
19
+ <Section title>
20
+ ^^^^^ `title` prop is missing value.
21
+ Section content
22
+ </Section>
23
+
24
+ <Section title="">
25
+ ^^^^^ `title` prop is missing accessible name value.
26
+ Section content
27
+ </Section>
28
+
29
+ <Section titleId>
30
+ ^^^^^^^ `titleId` prop is missing reference value.
31
+ <h1 id="section-title">Section content title</hi>
32
+ </Section>
33
+
34
+ <Section titleId="">
35
+ ^^^^^^^ `titleId` prop is missing reference value.
36
+ <h1 id="section-title">Section content title</hi>
37
+ </Section>
38
+
39
+ <Section titleId="section-title" title="Accessible title">
40
+ ^^^^^^^ ^^^^^ Do not include both `titleId` and `title` properties. Use `titleId` if the label text is available in the DOM to reference it, otherwise use `title` to provide accessible name explicitly.
41
+ <h1 id="section-title">Section content title</hi>
42
+ </Section>
43
+ ```
44
+
45
+ ### Correct
46
+
47
+ ```tsx
48
+ <Section title="Section content title">
49
+ Section content
50
+ </Section>
51
+
52
+ <Section titleId="section-title">
53
+ <h1 id="section-title">Section content title</hi>
54
+ </Section>
55
+ ```
@@ -10,7 +10,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
10
10
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
11
  /**
12
12
  * THIS SECTION WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
13
- * @codegen <<SignedSource::30c84f908843af1f250860b6f3deeea0>>
13
+ * @codegen <<SignedSource::a9fbd091c8b53fd9515afc7cdd793c6b>>
14
14
  * @codegenId spacing
15
15
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen-token-maps
16
16
  * @codegenDependency ../../../tokens/src/artifacts/tokens-raw/atlassian-spacing.tsx <<SignedSource::55622b91aca9b3afac4bce440f222b71>>
@@ -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::45da5525f92249d3a5b5049a95fc2fc5>>
9
+ * @codegen <<SignedSource::837556032f39113ae86785a120bb9ccb>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -44,6 +44,7 @@ var _default = exports.default = {
44
44
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
45
45
  '@atlaskit/design-system/use-href-in-link-item': 'warn',
46
46
  '@atlaskit/design-system/use-latest-xcss-syntax': 'error',
47
+ '@atlaskit/design-system/use-menu-section-title': 'warn',
47
48
  '@atlaskit/design-system/use-popup-label': 'warn',
48
49
  '@atlaskit/design-system/use-primitives': 'warn',
49
50
  '@atlaskit/design-system/use-primitives-text': '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::f5a2e39689cb7db642a65999cdc6f03a>>
9
+ * @codegen <<SignedSource::b7ed527a03208f0bc68f9d34e4ef2260>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -34,6 +34,7 @@ var _default = exports.default = {
34
34
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
35
35
  '@atlaskit/design-system/use-href-in-link-item': 'warn',
36
36
  '@atlaskit/design-system/use-latest-xcss-syntax': 'error',
37
+ '@atlaskit/design-system/use-menu-section-title': 'warn',
37
38
  '@atlaskit/design-system/use-popup-label': 'warn',
38
39
  '@atlaskit/design-system/use-visually-hidden': 'error'
39
40
  }
@@ -37,6 +37,7 @@ var _useHeading = _interopRequireDefault(require("./use-heading"));
37
37
  var _useHeadingLevelInSpotlightCard = _interopRequireDefault(require("./use-heading-level-in-spotlight-card"));
38
38
  var _useHrefInLinkItem = _interopRequireDefault(require("./use-href-in-link-item"));
39
39
  var _useLatestXcssSyntax = _interopRequireDefault(require("./use-latest-xcss-syntax"));
40
+ var _useMenuSectionTitle = _interopRequireDefault(require("./use-menu-section-title"));
40
41
  var _usePopupLabel = _interopRequireDefault(require("./use-popup-label"));
41
42
  var _usePrimitives = _interopRequireDefault(require("./use-primitives"));
42
43
  var _usePrimitivesText = _interopRequireDefault(require("./use-primitives-text"));
@@ -45,7 +46,7 @@ var _useTokensTypography = _interopRequireDefault(require("./use-tokens-typograp
45
46
  var _useVisuallyHidden = _interopRequireDefault(require("./use-visually-hidden"));
46
47
  /**
47
48
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
48
- * @codegen <<SignedSource::37cb0f5dfe6f5b8391203fdb1cf7cabe>>
49
+ * @codegen <<SignedSource::287628b11d396c2bcbcf6f4a175a3d3a>>
49
50
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
50
51
  */
51
52
  var _default = exports.default = {
@@ -81,6 +82,7 @@ var _default = exports.default = {
81
82
  'use-heading-level-in-spotlight-card': _useHeadingLevelInSpotlightCard.default,
82
83
  'use-href-in-link-item': _useHrefInLinkItem.default,
83
84
  'use-latest-xcss-syntax': _useLatestXcssSyntax.default,
85
+ 'use-menu-section-title': _useMenuSectionTitle.default,
84
86
  'use-popup-label': _usePopupLabel.default,
85
87
  'use-primitives': _usePrimitives.default,
86
88
  'use-primitives-text': _usePrimitivesText.default,
@@ -39,7 +39,16 @@ var StyleProperty = exports.StyleProperty = {
39
39
  ref: undefined
40
40
  };
41
41
  }
42
- var importDeclarations = ast.Root.findImportsByModule(context.sourceCode.ast.body, '@atlaskit/primitives');
42
+ var importDeclarations = ast.Root.findImportsByModule(
43
+ /**
44
+ * `context.getSourceCode()` is deprecated in favour of `context.sourceCode`.
45
+ * However, `context.sourceCode` returns undefined for some usages. This may be a bug
46
+ * in the `eslint` package. So, use `getSourceCode()` instead.
47
+ *
48
+ * Note: `context.sourceCode` works in testing environments. So, it is hard to validate whether it
49
+ * will work in the wild. Even if the tests pass, don't assume it will work in production.
50
+ */
51
+ context.getSourceCode().ast.body, '@atlaskit/primitives');
43
52
  var isXcssImported = importDeclarations.some(function (importDeclaration) {
44
53
  return ast.Import.containsNamedSpecifier(importDeclaration, 'xcss');
45
54
  });
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
8
+ var _createRule = require("../utils/create-rule");
9
+ // eslint-disable-next-line import/no-extraneous-dependencies
10
+
11
+ var elementsAccessibleNameProps = ['title', 'titleId'];
12
+ var rule = (0, _createRule.createLintRule)({
13
+ meta: {
14
+ name: 'use-menu-section-title',
15
+ type: 'suggestion',
16
+ docs: {
17
+ description: 'Encourages makers to provide accessible title for Atlassian Design System Menu Section component.',
18
+ recommended: true,
19
+ severity: 'warn'
20
+ },
21
+ messages: {
22
+ missingTitleProp: 'Missing accessible title. If there is no visible content to associate use `title` prop, otherwise pass id of element to `titleId` prop to be associated as label.',
23
+ titlePropShouldHaveContents: 'Define the string that labels the interactive element.',
24
+ titleIdShouldHaveValue: '`titleId` should reference the id of the element that defines the accessible name.',
25
+ noBothPropsUsage: 'Do not include both `titleId` and `title` properties. Use `titleId` if the label text is available in the DOM to reference it, otherwise use `title` to provide accessible name explicitly.'
26
+ },
27
+ hasSuggestions: true
28
+ },
29
+ create: function create(context) {
30
+ var contextLocalIdentifier = [];
31
+ return {
32
+ ImportDeclaration: function ImportDeclaration(node) {
33
+ var _node$specifiers;
34
+ var menuSectionIdentifier = (_node$specifiers = node.specifiers) === null || _node$specifiers === void 0 ? void 0 : _node$specifiers.filter(function (spec) {
35
+ if (node.source.value === '@atlaskit/menu') {
36
+ var _spec$imported;
37
+ return spec.type === 'ImportSpecifier' && ((_spec$imported = spec.imported) === null || _spec$imported === void 0 ? void 0 : _spec$imported.name) === 'Section';
38
+ } else if (node.source.value === '@atlaskit/menu/section') {
39
+ return spec.type === 'ImportDefaultSpecifier';
40
+ }
41
+ });
42
+ if (menuSectionIdentifier !== null && menuSectionIdentifier !== void 0 && menuSectionIdentifier.length) {
43
+ var local = menuSectionIdentifier[0].local;
44
+ contextLocalIdentifier.push(local.name);
45
+ }
46
+ },
47
+ JSXElement: function JSXElement(node) {
48
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXElement')) {
49
+ return;
50
+ }
51
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node.openingElement.name, 'JSXIdentifier')) {
52
+ return;
53
+ }
54
+ var name = node.openingElement.name.name;
55
+ if (contextLocalIdentifier.includes(name)) {
56
+ var componentLabelProps = node.openingElement.attributes.filter(function (attr) {
57
+ return (0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXAttribute') && (0, _eslintCodemodUtils.isNodeOfType)(attr.name, 'JSXIdentifier') && elementsAccessibleNameProps.includes(attr.name.name);
58
+ });
59
+ if (componentLabelProps.length === 1) {
60
+ var prop = componentLabelProps[0];
61
+ if ('value' in prop && prop.value) {
62
+ if ((0, _eslintCodemodUtils.isNodeOfType)(prop.value, 'Literal') && !prop.value.value || (0, _eslintCodemodUtils.isNodeOfType)(prop.value, 'JSXExpressionContainer') && !prop.value.expression) {
63
+ context.report({
64
+ node: prop,
65
+ messageId: prop.name.name === 'title' ? 'titlePropShouldHaveContents' : 'titleIdShouldHaveValue'
66
+ });
67
+ }
68
+ }
69
+ } else if (componentLabelProps.length > 1) {
70
+ context.report({
71
+ node: node.openingElement,
72
+ messageId: 'noBothPropsUsage'
73
+ });
74
+ } else {
75
+ context.report({
76
+ node: node.openingElement,
77
+ messageId: 'missingTitleProp'
78
+ });
79
+ }
80
+ }
81
+ }
82
+ };
83
+ }
84
+ });
85
+ var _default = exports.default = rule;