eslint-plugin-smarthr 6.0.0 → 6.0.2
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
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [6.0.2](https://github.com/kufu/tamatebako/compare/eslint-plugin-smarthr-v6.0.1...eslint-plugin-smarthr-v6.0.2) (2026-01-29)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **best-practice-for-interactive-element:** 属性にインタラクティブなコンポーネントを設定している場合、onXxxが誤検知されてしまうバグを修正 ([#1023](https://github.com/kufu/tamatebako/issues/1023)) ([81563cd](https://github.com/kufu/tamatebako/commit/81563cd2fa13ae9f53306d592b2f86e17e1f790c))
|
|
11
|
+
|
|
12
|
+
## [6.0.1](https://github.com/kufu/tamatebako/compare/eslint-plugin-smarthr-v6.0.0...eslint-plugin-smarthr-v6.0.1) (2026-01-28)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* **best-practice-for-interactive-element:** as属性でインタラクティブなコンポーネントに変更した場合、onXxxのチェックが誤検知する問題を修正 ([#1019](https://github.com/kufu/tamatebako/issues/1019)) ([8ba4343](https://github.com/kufu/tamatebako/commit/8ba4343b87b8acb8fee374946dd18c848839e6a9))
|
|
18
|
+
|
|
5
19
|
## [6.0.0](https://github.com/kufu/tamatebako/compare/eslint-plugin-smarthr-v5.0.0...eslint-plugin-smarthr-v6.0.0) (2026-01-28)
|
|
6
20
|
|
|
7
21
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-smarthr",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.2",
|
|
4
4
|
"author": "SmartHR",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "A sharable ESLint plugin for SmartHR",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"eslintplugin",
|
|
38
38
|
"smarthr"
|
|
39
39
|
],
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "347e704bdd63fa55699762f85752ad791e4f6b3d"
|
|
41
41
|
}
|
|
@@ -30,6 +30,9 @@ const INTERACTIVE_COMPONENT_NAMES = `(${[
|
|
|
30
30
|
].join('|')})$`
|
|
31
31
|
const INTERACTIVE_ON_REGEX = /^on(Change|Input|Focus|Blur|(Double)?Click|Key(Down|Up|Press)|Mouse(Enter|Over|Down|Up|Leave)|Select|Submit)$/
|
|
32
32
|
|
|
33
|
+
const ELEMENT_HAS_ROLE_ATTRIBUTE = 'JSXOpeningElement:has(JSXAttribute[name.name="role"])'
|
|
34
|
+
const AS_FORM_PART_ATTRIBUTE = 'JSXAttribute[name.name=/^(as|forwardedAs)$/][value.value=/^f(orm|ieldset)$/]'
|
|
35
|
+
|
|
33
36
|
const SCHEMA = [
|
|
34
37
|
{
|
|
35
38
|
type: 'object',
|
|
@@ -51,22 +54,27 @@ module.exports = {
|
|
|
51
54
|
create(context) {
|
|
52
55
|
const options = context.options[0]
|
|
53
56
|
const interactiveComponentRegex = new RegExp(`(${INTERACTIVE_COMPONENT_NAMES}${options?.additionalInteractiveComponentRegex ? `|${options.additionalInteractiveComponentRegex.join('|')}` : ''})`)
|
|
54
|
-
|
|
55
|
-
const interactiveAction = (node) => {
|
|
56
|
-
context.report({
|
|
57
|
-
node,
|
|
58
|
-
message: `${node.name.name}にrole属性は指定しないでください。
|
|
59
|
-
- 詳細: https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-interactive-element`,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
57
|
+
const targetNameProp = `[name.name=${interactiveComponentRegex}]`
|
|
62
58
|
|
|
63
59
|
return {
|
|
64
|
-
[
|
|
65
|
-
'JSXOpeningElement:has(JSXAttribute[name.name=/^(as|forwardedAs)$/][value.value=/^f(orm|ieldset)$/]):has(JSXAttribute[name.name="role"])': interactiveAction,
|
|
66
|
-
[`JSXOpeningElement:not([name.name=${interactiveComponentRegex}]):has(JSXAttribute[name.name=${INTERACTIVE_ON_REGEX}])`]: (node) => {
|
|
60
|
+
[`${ELEMENT_HAS_ROLE_ATTRIBUTE}${targetNameProp}`]: (node) => {
|
|
67
61
|
context.report({
|
|
68
62
|
node,
|
|
69
|
-
message: `${node.name.name}
|
|
63
|
+
message: `${node.name.name}にrole属性は指定しないでください。
|
|
64
|
+
- 詳細: https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-interactive-element`,
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
[`${ELEMENT_HAS_ROLE_ATTRIBUTE} ${AS_FORM_PART_ATTRIBUTE}`]: (node) => {
|
|
68
|
+
context.report({
|
|
69
|
+
node: node.parent,
|
|
70
|
+
message: `<${node.parent.name.name} ${context.sourceCode.getText(node)}>にrole属性は指定しないでください。
|
|
71
|
+
- 詳細: https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-interactive-element`,
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
[`JSXOpeningElement:not(${targetNameProp}):not(:has(${AS_FORM_PART_ATTRIBUTE}))>JSXAttribute[name.name=${INTERACTIVE_ON_REGEX}]`]: (node) => {
|
|
75
|
+
context.report({
|
|
76
|
+
node: node.parent,
|
|
77
|
+
message: `${node.parent.name.name}にデフォルトで用意されているonXxx形式の属性は設定しないでください
|
|
70
78
|
- 詳細: https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-interactive-element
|
|
71
79
|
- 対応方法1: 対象の属性がコンポーネント内の特定のインタラクティブな要素に設定される場合、名称を具体的なものに変更してください
|
|
72
80
|
- 属性名を"${INTERACTIVE_ON_REGEX}"に一致しないものに変更してください
|
|
@@ -59,13 +59,17 @@ ruleTester.run('best-practice-for-interactive-element', rule, {
|
|
|
59
59
|
{ code: `<button>...</button>` },
|
|
60
60
|
{ code: `<InteractiveComponent>...</InteractiveComponent>`, options: [{ additionalInteractiveComponentRegex: ['^InteractiveComponent%'] }] },
|
|
61
61
|
{ code: `<CrewDetail onChangeName={onChange} />` },
|
|
62
|
+
{ code: `<Stack as="form" onSubmit={onSubmit} />` },
|
|
63
|
+
{ code: `<Stack any={<Button onClick={onClick} />} />` },
|
|
62
64
|
],
|
|
63
65
|
invalid: [
|
|
64
66
|
{ code: `<button role="presentation">...</button>`, errors: [{ message: interactiveError('button') }] },
|
|
65
|
-
{ code: `<Hoge as="form" role="menu" />`, errors: [{ message:
|
|
67
|
+
{ code: `<Hoge as="form" role="menu" />`, errors: [{ message: `<Hoge as="form">にrole属性は指定しないでください。
|
|
68
|
+
- 詳細: https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-interactive-element` }] },
|
|
66
69
|
{ code: `<FormControl role="menu" />`, errors: [{ message: interactiveError('FormControl') }] },
|
|
67
70
|
{ code: `<InteractiveComponent role="group">...</InteractiveComponent>`, options: [{ additionalInteractiveComponentRegex: ['^Interactive'] }], errors: [{ message: interactiveError('InteractiveComponent') }] },
|
|
68
71
|
{ code: `<CrewDetail onChange={onChange} />`, errors: [{ message: uninteractiveError('CrewDetail') }] },
|
|
72
|
+
{ code: `<Stack onSubmit={onSubmit} />`, errors: [{ message: uninteractiveError('Stack') }] },
|
|
69
73
|
]
|
|
70
74
|
})
|
|
71
75
|
|