eslint-plugin-primer-react 7.0.0-rc.0d4a60c → 7.0.0-rc.1eafbbd
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/.github/workflows/release_tracking.yml +1 -1
- package/CHANGELOG.md +4 -0
- package/README.md +1 -0
- package/docs/rules/a11y-no-title-usage.md +40 -0
- package/docs/rules/no-deprecated-experimental-components.md +29 -0
- package/package-lock.json +442 -321
- package/package.json +3 -3
- package/src/configs/recommended.js +2 -0
- package/src/index.js +2 -0
- package/src/rules/__tests__/a11y-no-title-usage.test.js +27 -0
- package/src/rules/__tests__/no-deprecated-experimental-components.test.js +44 -0
- package/src/rules/a11y-no-title-usage.js +37 -0
- package/src/rules/no-deprecated-experimental-components.js +67 -0
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.1eafbbd",
|
|
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": "8.
|
|
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",
|
|
@@ -12,9 +12,11 @@ module.exports = {
|
|
|
12
12
|
rules: {
|
|
13
13
|
'primer-react/direct-slot-children': 'error',
|
|
14
14
|
'primer-react/no-system-props': 'warn',
|
|
15
|
+
'primer-react/no-deprecated-experimental-components': 'warn',
|
|
15
16
|
'primer-react/a11y-tooltip-interactive-trigger': 'error',
|
|
16
17
|
'primer-react/new-color-css-vars': 'error',
|
|
17
18
|
'primer-react/a11y-explicit-heading': 'error',
|
|
19
|
+
'primer-react/a11y-no-title-usage': 'error',
|
|
18
20
|
'primer-react/no-deprecated-props': 'warn',
|
|
19
21
|
'primer-react/a11y-remove-disable-tooltip': 'error',
|
|
20
22
|
'primer-react/a11y-use-accessible-tooltip': 'error',
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,7 @@ module.exports = {
|
|
|
3
3
|
'direct-slot-children': require('./rules/direct-slot-children'),
|
|
4
4
|
'no-deprecated-entrypoints': require('./rules/no-deprecated-entrypoints'),
|
|
5
5
|
'no-system-props': require('./rules/no-system-props'),
|
|
6
|
+
'no-deprecated-experimental-components': require('./rules/no-deprecated-experimental-components'),
|
|
6
7
|
'a11y-tooltip-interactive-trigger': require('./rules/a11y-tooltip-interactive-trigger'),
|
|
7
8
|
'new-color-css-vars': require('./rules/new-color-css-vars'),
|
|
8
9
|
'a11y-explicit-heading': require('./rules/a11y-explicit-heading'),
|
|
@@ -10,6 +11,7 @@ module.exports = {
|
|
|
10
11
|
'a11y-link-in-text-block': require('./rules/a11y-link-in-text-block'),
|
|
11
12
|
'a11y-remove-disable-tooltip': require('./rules/a11y-remove-disable-tooltip'),
|
|
12
13
|
'a11y-use-accessible-tooltip': require('./rules/a11y-use-accessible-tooltip'),
|
|
14
|
+
'a11y-no-title-usage': require('./rules/a11y-no-title-usage'),
|
|
13
15
|
'use-deprecated-from-deprecated': require('./rules/use-deprecated-from-deprecated'),
|
|
14
16
|
'no-wildcard-imports': require('./rules/no-wildcard-imports'),
|
|
15
17
|
'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
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const {RuleTester} = require('eslint')
|
|
4
|
+
const rule = require('../no-deprecated-experimental-components')
|
|
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('no-deprecated-experimental-components', rule, {
|
|
17
|
+
valid: [
|
|
18
|
+
{
|
|
19
|
+
code: `import {SelectPanel} from '@primer/react'`,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
code: `import {DataTable} from '@primer/react/experimental'`,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
code: `import {DataTable, ActionBar} from '@primer/react/experimental'`,
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
invalid: [
|
|
29
|
+
// Single experimental import
|
|
30
|
+
{
|
|
31
|
+
code: `import {SelectPanel} from '@primer/react/experimental'`,
|
|
32
|
+
errors: [
|
|
33
|
+
'SelectPanel is deprecated. Please import from the stable entrypoint (@primer/react) if available, or check https://primer.style/product/components/ for alternative components.',
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
// Multiple experimental import
|
|
37
|
+
{
|
|
38
|
+
code: `import {SelectPanel, DataTable, ActionBar} from '@primer/react/experimental'`,
|
|
39
|
+
errors: [
|
|
40
|
+
'SelectPanel is deprecated. Please import from the stable entrypoint (@primer/react) if available, or check https://primer.style/product/components/ for alternative components.',
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
})
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const url = require('../url')
|
|
4
|
+
|
|
5
|
+
const components = [
|
|
6
|
+
{
|
|
7
|
+
identifier: 'SelectPanel',
|
|
8
|
+
entrypoint: '@primer/react/experimental',
|
|
9
|
+
},
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
const entrypoints = new Map()
|
|
13
|
+
|
|
14
|
+
for (const component of components) {
|
|
15
|
+
if (!entrypoints.has(component.entrypoint)) {
|
|
16
|
+
entrypoints.set(component.entrypoint, new Set())
|
|
17
|
+
}
|
|
18
|
+
entrypoints.get(component.entrypoint).add(component.identifier)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @type {import('eslint').Rule.RuleModule}
|
|
23
|
+
*/
|
|
24
|
+
module.exports = {
|
|
25
|
+
meta: {
|
|
26
|
+
type: 'problem',
|
|
27
|
+
docs: {
|
|
28
|
+
description: 'Use a stable component from the `@primer/react` entrypoint, or check the docs for alternatives',
|
|
29
|
+
recommended: true,
|
|
30
|
+
url: url(module),
|
|
31
|
+
},
|
|
32
|
+
fixable: true,
|
|
33
|
+
schema: [],
|
|
34
|
+
},
|
|
35
|
+
create(context) {
|
|
36
|
+
return {
|
|
37
|
+
ImportDeclaration(node) {
|
|
38
|
+
if (!entrypoints.has(node.source.value)) {
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const entrypoint = entrypoints.get(node.source.value)
|
|
43
|
+
|
|
44
|
+
const experimental = node.specifiers.filter(specifier => {
|
|
45
|
+
return entrypoint.has(specifier.imported.name)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const components = experimental.map(specifier => specifier.imported.name)
|
|
49
|
+
|
|
50
|
+
if (experimental.length === 0) {
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (experimental.length > 0) {
|
|
55
|
+
const message = `${components.join(', ')} ${
|
|
56
|
+
components.length > 1 ? 'are' : 'is'
|
|
57
|
+
} deprecated. Please import from the stable entrypoint (@primer/react) if available, or check https://primer.style/product/components/ for alternative components.`
|
|
58
|
+
|
|
59
|
+
context.report({
|
|
60
|
+
node,
|
|
61
|
+
message,
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
}
|