eslint-plugin-primer-react 7.0.0-rc.55939f7 → 7.0.0-rc.5c89573
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/CHANGELOG.md +6 -0
- package/docs/rules/a11y-no-title-usage.md +40 -0
- package/package-lock.json +1456 -857
- package/package.json +4 -4
- package/src/configs/recommended.js +1 -0
- package/src/index.js +1 -0
- package/src/rules/__tests__/a11y-no-title-usage.test.js +27 -0
- package/src/rules/__tests__/a11y-tooltip-interactive-trigger.test.js +16 -0
- package/src/rules/a11y-no-title-usage.js +37 -0
- package/src/rules/a11y-tooltip-interactive-trigger.js +9 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-primer-react",
|
|
3
|
-
"version": "7.0.0-rc.
|
|
3
|
+
"version": "7.0.0-rc.5c89573",
|
|
4
4
|
"description": "ESLint rules for Primer React",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"eslint-traverse": "^1.0.0",
|
|
35
35
|
"lodash": "^4.17.21",
|
|
36
36
|
"styled-system": "^5.1.5",
|
|
37
|
-
"@typescript-eslint/utils": "
|
|
38
|
-
"typescript": "^5.
|
|
37
|
+
"@typescript-eslint/utils": "8.26.0",
|
|
38
|
+
"typescript": "^5.8.2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@changesets/changelog-github": "^0.5.0",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"eslint": "^8.42.0",
|
|
46
46
|
"eslint-plugin-prettier": "^5.2.1",
|
|
47
47
|
"jest": "^29.7.0",
|
|
48
|
-
"markdownlint-cli2": "^0.
|
|
48
|
+
"markdownlint-cli2": "^0.17.1",
|
|
49
49
|
"markdownlint-cli2-formatter-pretty": "^0.0.7",
|
|
50
50
|
"@typescript-eslint/rule-tester": "7.16.0",
|
|
51
51
|
"@types/jest": "^29.5.13"
|
|
@@ -15,6 +15,7 @@ module.exports = {
|
|
|
15
15
|
'primer-react/a11y-tooltip-interactive-trigger': 'error',
|
|
16
16
|
'primer-react/new-color-css-vars': 'error',
|
|
17
17
|
'primer-react/a11y-explicit-heading': 'error',
|
|
18
|
+
'primer-react/a11y-no-title-usage': 'error',
|
|
18
19
|
'primer-react/no-deprecated-props': 'warn',
|
|
19
20
|
'primer-react/a11y-remove-disable-tooltip': 'error',
|
|
20
21
|
'primer-react/a11y-use-accessible-tooltip': 'error',
|
package/src/index.js
CHANGED
|
@@ -10,6 +10,7 @@ module.exports = {
|
|
|
10
10
|
'a11y-link-in-text-block': require('./rules/a11y-link-in-text-block'),
|
|
11
11
|
'a11y-remove-disable-tooltip': require('./rules/a11y-remove-disable-tooltip'),
|
|
12
12
|
'a11y-use-accessible-tooltip': require('./rules/a11y-use-accessible-tooltip'),
|
|
13
|
+
'a11y-no-title-usage': require('./rules/a11y-no-title-usage'),
|
|
13
14
|
'use-deprecated-from-deprecated': require('./rules/use-deprecated-from-deprecated'),
|
|
14
15
|
'no-wildcard-imports': require('./rules/no-wildcard-imports'),
|
|
15
16
|
'no-unnecessary-components': require('./rules/no-unnecessary-components'),
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const rule = require('../a11y-no-title-usage')
|
|
2
|
+
const {RuleTester} = require('eslint')
|
|
3
|
+
|
|
4
|
+
const ruleTester = new RuleTester({
|
|
5
|
+
parserOptions: {
|
|
6
|
+
ecmaVersion: 'latest',
|
|
7
|
+
sourceType: 'module',
|
|
8
|
+
ecmaFeatures: {
|
|
9
|
+
jsx: true,
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
ruleTester.run('a11y-no-title-usage', rule, {
|
|
15
|
+
valid: [
|
|
16
|
+
`<RelativeTime date={new Date('2020-01-01T00:00:00Z')} noTitle={true} />`,
|
|
17
|
+
`<RelativeTime date={new Date('2020-01-01T00:00:00Z')} noTitle />`,
|
|
18
|
+
`<RelativeTime date={new Date('2020-01-01T00:00:00Z')} />`,
|
|
19
|
+
],
|
|
20
|
+
invalid: [
|
|
21
|
+
{
|
|
22
|
+
code: `<RelativeTime date={new Date('2020-01-01T00:00:00Z')} noTitle={false} />`,
|
|
23
|
+
output: `<RelativeTime date={new Date('2020-01-01T00:00:00Z')} />`,
|
|
24
|
+
errors: [{messageId: 'noTitleOnRelativeTime'}],
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
})
|
|
@@ -67,6 +67,22 @@ ruleTester.run('non-interactive-tooltip-trigger', rule, {
|
|
|
67
67
|
</Link>
|
|
68
68
|
</Tooltip>
|
|
69
69
|
`,
|
|
70
|
+
`
|
|
71
|
+
import {Tooltip, Link} from '@primer/react';
|
|
72
|
+
<Tooltip aria-label="product" direction="e">
|
|
73
|
+
<Link to={productLink}>
|
|
74
|
+
Product
|
|
75
|
+
</Link>
|
|
76
|
+
</Tooltip>
|
|
77
|
+
`,
|
|
78
|
+
`
|
|
79
|
+
import {Tooltip, Link} from '@primer/react';
|
|
80
|
+
<Tooltip aria-label="product" direction="e">
|
|
81
|
+
<Link to="https://github.com">
|
|
82
|
+
Product
|
|
83
|
+
</Link>
|
|
84
|
+
</Tooltip>
|
|
85
|
+
`,
|
|
70
86
|
],
|
|
71
87
|
invalid: [
|
|
72
88
|
{
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const url = require('../url')
|
|
2
|
+
const {getJSXOpeningElementAttribute} = require('../utils/get-jsx-opening-element-attribute')
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
meta: {
|
|
6
|
+
type: 'error',
|
|
7
|
+
docs: {
|
|
8
|
+
description: 'Disallow usage of title attribute on some components',
|
|
9
|
+
recommended: true,
|
|
10
|
+
url: url(module),
|
|
11
|
+
},
|
|
12
|
+
messages: {
|
|
13
|
+
noTitleOnRelativeTime: 'Avoid using the title attribute on RelativeTime.',
|
|
14
|
+
},
|
|
15
|
+
fixable: 'code',
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
create(context) {
|
|
19
|
+
return {
|
|
20
|
+
JSXOpeningElement(jsxNode) {
|
|
21
|
+
const title = getJSXOpeningElementAttribute(jsxNode, 'noTitle')
|
|
22
|
+
|
|
23
|
+
if (title && title.value && title.value.expression && title.value.expression.value !== true) {
|
|
24
|
+
context.report({
|
|
25
|
+
node: title,
|
|
26
|
+
messageId: 'noTitleOnRelativeTime',
|
|
27
|
+
fix(fixer) {
|
|
28
|
+
const start = title.range[0] - 1
|
|
29
|
+
const end = title.range[1]
|
|
30
|
+
return fixer.removeRange([start, end])
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
}
|
|
@@ -23,7 +23,7 @@ const isAnchorTag = el => {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const isJSXValue = attributes => {
|
|
26
|
-
const node = attributes.find(attribute => propName(attribute) === 'href')
|
|
26
|
+
const node = attributes.find(attribute => propName(attribute) === 'href' || propName(attribute))
|
|
27
27
|
const isJSXExpression = node.value.type === 'JSXExpressionContainer' && node && typeof getPropValue(node) === 'string'
|
|
28
28
|
|
|
29
29
|
return isJSXExpression
|
|
@@ -31,8 +31,14 @@ const isJSXValue = attributes => {
|
|
|
31
31
|
|
|
32
32
|
const isInteractiveAnchor = child => {
|
|
33
33
|
const hasHref = getJSXOpeningElementAttribute(child.openingElement, 'href')
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
const hasTo = getJSXOpeningElementAttribute(child.openingElement, 'to')
|
|
35
|
+
|
|
36
|
+
if (!hasHref && !hasTo) return false
|
|
37
|
+
|
|
38
|
+
const href = hasHref
|
|
39
|
+
? getJSXOpeningElementAttribute(child.openingElement, 'href').value.value
|
|
40
|
+
: getJSXOpeningElementAttribute(child.openingElement, 'to').value.value
|
|
41
|
+
|
|
36
42
|
const hasJSXValue = isJSXValue(child.openingElement.attributes)
|
|
37
43
|
const isAnchorInteractive = (typeof href === 'string' && href !== '') || hasJSXValue
|
|
38
44
|
|