eslint-plugin-primer-react 5.2.1 → 5.3.0-rc.e240e9d

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-primer-react",
3
- "version": "5.2.1",
3
+ "version": "5.3.0-rc.e240e9d",
4
4
  "description": "ESLint rules for Primer React",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -16,6 +16,7 @@ module.exports = {
16
16
  'primer-react/new-color-css-vars': 'error',
17
17
  'primer-react/a11y-explicit-heading': 'error',
18
18
  'primer-react/no-deprecated-props': 'warn',
19
+ 'primer-react/a11y-remove-disable-tooltip': 'error',
19
20
  },
20
21
  settings: {
21
22
  github: {
package/src/index.js CHANGED
@@ -8,6 +8,7 @@ module.exports = {
8
8
  'a11y-explicit-heading': require('./rules/a11y-explicit-heading'),
9
9
  'no-deprecated-props': require('./rules/no-deprecated-props'),
10
10
  'a11y-link-in-text-block': require('./rules/a11y-link-in-text-block'),
11
+ 'a11y-remove-disable-tooltip': require('./rules/a11y-remove-disable-tooltip'),
11
12
  },
12
13
  configs: {
13
14
  recommended: require('./configs/recommended'),
@@ -0,0 +1,50 @@
1
+ 'use strict'
2
+
3
+ const {RuleTester} = require('eslint')
4
+ const rule = require('../a11y-remove-disable-tooltip')
5
+
6
+ const ruleTester = new RuleTester({
7
+ parserOptions: {
8
+ ecmaVersion: 'latest',
9
+ sourceType: 'module',
10
+ ecmaFeatures: {
11
+ jsx: true,
12
+ },
13
+ },
14
+ })
15
+
16
+ ruleTester.run('a11y-remove-disable-tooltip', rule, {
17
+ valid: [
18
+ `import {IconButton} from '@primer/react';
19
+ <IconButton icon={SearchIcon} aria-label="Search" />`,
20
+ ],
21
+ invalid: [
22
+ {
23
+ code: `<IconButton icon={SearchIcon} aria-label="Search" unsafeDisableTooltip />`,
24
+ output: `<IconButton icon={SearchIcon} aria-label="Search" />`,
25
+ errors: [
26
+ {
27
+ messageId: 'removeDisableTooltipProp',
28
+ },
29
+ ],
30
+ },
31
+ {
32
+ code: `<IconButton icon={SearchIcon} aria-label="Search" unsafeDisableTooltip={true} />`,
33
+ output: `<IconButton icon={SearchIcon} aria-label="Search" />`,
34
+ errors: [
35
+ {
36
+ messageId: 'removeDisableTooltipProp',
37
+ },
38
+ ],
39
+ },
40
+ {
41
+ code: `<IconButton icon={SearchIcon} aria-label="Search" unsafeDisableTooltip={false} />`,
42
+ output: `<IconButton icon={SearchIcon} aria-label="Search" />`,
43
+ errors: [
44
+ {
45
+ messageId: 'removeDisableTooltipProp',
46
+ },
47
+ ],
48
+ },
49
+ ],
50
+ })
@@ -0,0 +1,47 @@
1
+ 'use strict'
2
+ const {getJSXOpeningElementAttribute} = require('../utils/get-jsx-opening-element-attribute')
3
+ const {getJSXOpeningElementName} = require('../utils/get-jsx-opening-element-name')
4
+
5
+ /**
6
+ * @type {import('eslint').Rule.RuleModule}
7
+ */
8
+ module.exports = {
9
+ meta: {
10
+ type: 'error',
11
+ docs: {
12
+ description:
13
+ 'Icon buttons should have tooltip by default. Please remove `unsafeDisableTooltip` prop from `IconButton` component to enable the tooltip and help making icon button more accessible.',
14
+ recommended: true,
15
+ },
16
+ fixable: 'code',
17
+ schema: [],
18
+ messages: {
19
+ removeDisableTooltipProp:
20
+ 'Please remove `unsafeDisableTooltip` prop from `IconButton` component to enable the tooltip and help make icon button more accessible.',
21
+ },
22
+ },
23
+ create(context) {
24
+ return {
25
+ JSXOpeningElement(node) {
26
+ const openingElName = getJSXOpeningElementName(node)
27
+ if (openingElName !== 'IconButton') {
28
+ return
29
+ }
30
+ const unsafeDisableTooltip = getJSXOpeningElementAttribute(node, 'unsafeDisableTooltip')
31
+ if (unsafeDisableTooltip !== undefined) {
32
+ context.report({
33
+ node,
34
+ messageId: 'removeDisableTooltipProp',
35
+ fix(fixer) {
36
+ const start = unsafeDisableTooltip.range[0]
37
+ const end = unsafeDisableTooltip.range[1]
38
+ return [
39
+ fixer.removeRange([start - 1, end]), // remove the space before unsafeDisableTooltip as well
40
+ ]
41
+ },
42
+ })
43
+ }
44
+ },
45
+ }
46
+ },
47
+ }