eslint-plugin-smarthr 4.0.1 → 4.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,13 @@
|
|
|
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
|
+
## [4.0.2](https://github.com/kufu/tamatebako/compare/eslint-plugin-smarthr-v4.0.1...eslint-plugin-smarthr-v4.0.2) (2026-01-07)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* best-practice-for-spread-syntaxのcheckTypeをalways以外を指定した場合、チェック対象のコードによってエラーが発生する問題を修正 ([#1005](https://github.com/kufu/tamatebako/issues/1005)) ([ebd7b71](https://github.com/kufu/tamatebako/commit/ebd7b714a4e31f3875f5c3d9ad6a16bfb6e31634))
|
|
11
|
+
|
|
5
12
|
## [4.0.1](https://github.com/kufu/tamatebako/compare/eslint-plugin-smarthr-v4.0.0...eslint-plugin-smarthr-v4.0.1) (2026-01-04)
|
|
6
13
|
|
|
7
14
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-smarthr",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.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": "902835f740df61f2f9ce2c9bfeeff84788e0ed27"
|
|
41
41
|
}
|
|
@@ -9,8 +9,10 @@ const SCHEMA = [
|
|
|
9
9
|
}
|
|
10
10
|
]
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
|
|
12
|
+
const CHECK_REGEX = {
|
|
13
|
+
JSXSpreadAttribute: /^(always|only-jsx)$/,
|
|
14
|
+
SpreadElement: /^(always|only-object)$/,
|
|
15
|
+
}
|
|
14
16
|
|
|
15
17
|
// HINT: -1: 見つからなかった >= 0: 見つかった
|
|
16
18
|
const getInsertIndex = (node, type, attributesKey) => {
|
|
@@ -45,55 +47,50 @@ module.exports = {
|
|
|
45
47
|
const option = context.options[0] || {}
|
|
46
48
|
const fix = option.fix
|
|
47
49
|
const checkType = option.checkType || 'always'
|
|
50
|
+
const result = {}
|
|
48
51
|
|
|
49
52
|
const generateAction = (type, attributesKey, fixAction) => {
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
if (CHECK_REGEX[type].test(checkType)) {
|
|
54
|
+
result[type] = (node) => {
|
|
55
|
+
const insertIndex = getInsertIndex(node, type, attributesKey)
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
if (insertIndex !== -1) {
|
|
58
|
+
const code = context.sourceCode.getText(node)
|
|
55
59
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
context.report({
|
|
61
|
+
node,
|
|
62
|
+
message: `"${code}" は意図しない上書きを防ぐため、spread syntaxでない属性より先に記述してください
|
|
59
63
|
- 詳細: https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-spread-syntax`,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
fix: fixAction ? (fixer) => {
|
|
65
|
+
const elementNode = node.parent
|
|
66
|
+
const normals = []
|
|
67
|
+
const spreads = []
|
|
64
68
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
elementNode[attributesKey].forEach((a, i) => {
|
|
70
|
+
if (a !== node) {
|
|
71
|
+
if (insertIndex === i) {
|
|
72
|
+
spreads.push(code)
|
|
73
|
+
}
|
|
70
74
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
(a.type === type ? spreads : normals).push(context.sourceCode.getText(a))
|
|
76
|
+
}
|
|
77
|
+
})
|
|
74
78
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
return fixer.replaceText(
|
|
80
|
+
elementNode,
|
|
81
|
+
fixAction(spreads.concat(normals), elementNode),
|
|
82
|
+
)
|
|
83
|
+
} : null
|
|
84
|
+
});
|
|
85
|
+
}
|
|
81
86
|
}
|
|
82
|
-
}
|
|
87
|
+
}
|
|
83
88
|
}
|
|
84
89
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
: undefined
|
|
90
|
-
),
|
|
91
|
-
SpreadElement: (
|
|
92
|
-
CHECK_OBJ_REGEX.test(checkType)
|
|
93
|
-
? generateAction('SpreadElement', 'properties', (option.fix) && ((attributes) => `{ ${attributes.join(', ')} }`))
|
|
94
|
-
: undefined
|
|
95
|
-
),
|
|
96
|
-
}
|
|
90
|
+
generateAction('JSXSpreadAttribute', 'attributes', (option.fix) && ((attributes, e) => `<${e.name.name} ${attributes.join(' ')}${e.selfClosing ? ' /' : ''}>`))
|
|
91
|
+
generateAction('SpreadElement', 'properties', (option.fix) && ((attributes) => `{ ${attributes.join(', ')} }`))
|
|
92
|
+
|
|
93
|
+
return result
|
|
97
94
|
},
|
|
98
95
|
}
|
|
99
96
|
module.exports.schema = SCHEMA
|
|
@@ -21,6 +21,8 @@ ruleTester.run('best-practice-for-spread-syntax', rule, {
|
|
|
21
21
|
{ code: `const hoge = { ...props, id: props.id || 'ABC' }` },
|
|
22
22
|
{ code: `const hoge = { ...props1, ...props2, id: 'ABC' }` },
|
|
23
23
|
{ code: `dig(target, ...keys.slice(1))` },
|
|
24
|
+
{ code: `{[...Array(3)].map((_, i) => (i))}`, options: [ { checkType: 'only-jsx' } ], },
|
|
25
|
+
{ code: `<Fuga id={props.id || 'ABC'} {...props} />`, options: [ { checkType: 'only-object' } ], },
|
|
24
26
|
],
|
|
25
27
|
invalid: [
|
|
26
28
|
{
|