eslint-plugin-smarthr 4.0.0 → 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,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
+ ## [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
+
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)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * **best-practice-for-spread-syntax:** 関数に対してspread syntaxで引数を渡すパターンが誤検知される問題を修正 ([#999](https://github.com/kufu/tamatebako/issues/999)) ([3f4a163](https://github.com/kufu/tamatebako/commit/3f4a163b183305922651612d7945434dcb5fa991))
18
+
5
19
  ## [4.0.0](https://github.com/kufu/tamatebako/compare/eslint-plugin-smarthr-v3.5.1...eslint-plugin-smarthr-v4.0.0) (2026-01-04)
6
20
 
7
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-smarthr",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "author": "SmartHR",
5
5
  "license": "MIT",
6
6
  "description": "A sharable ESLint plugin for SmartHR",
@@ -26,7 +26,7 @@
26
26
  "json5": "^2.2.3"
27
27
  },
28
28
  "devDependencies": {
29
- "typescript-eslint": "^8.50.1"
29
+ "typescript-eslint": "^8.51.0"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "eslint": "^9"
@@ -37,5 +37,5 @@
37
37
  "eslintplugin",
38
38
  "smarthr"
39
39
  ],
40
- "gitHead": "f08245ba8257aa3587aa30b0024cb617638df74c"
40
+ "gitHead": "902835f740df61f2f9ce2c9bfeeff84788e0ed27"
41
41
  }
@@ -9,20 +9,25 @@ const SCHEMA = [
9
9
  }
10
10
  ]
11
11
 
12
- const CHECK_JSX_REGEX = /^(always|only-jsx)$/
13
- const CHECK_OBJ_REGEX = /^(always|only-object)$/
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) => {
17
19
  const attributes = node.parent[attributesKey]
18
20
 
19
- for (let i = 0; i < attributes.length; i++) {
20
- const a = attributes[i]
21
+ // HINT: 関数のspread elementの場合などは除外したいので属性がない場合に対応
22
+ if (attributes) {
23
+ for (let i = 0; i < attributes.length; i++) {
24
+ const a = attributes[i]
21
25
 
22
- if (a === node) {
23
- return -1
24
- } else if (a.type !== type) {
25
- return i
26
+ if (a === node) {
27
+ return -1
28
+ } else if (a.type !== type) {
29
+ return i
30
+ }
26
31
  }
27
32
  }
28
33
 
@@ -42,55 +47,50 @@ module.exports = {
42
47
  const option = context.options[0] || {}
43
48
  const fix = option.fix
44
49
  const checkType = option.checkType || 'always'
50
+ const result = {}
45
51
 
46
52
  const generateAction = (type, attributesKey, fixAction) => {
47
- return ((node) => {
48
- const insertIndex = getInsertIndex(node, type, attributesKey)
53
+ if (CHECK_REGEX[type].test(checkType)) {
54
+ result[type] = (node) => {
55
+ const insertIndex = getInsertIndex(node, type, attributesKey)
49
56
 
50
- if (insertIndex !== -1) {
51
- const code = context.sourceCode.getText(node)
57
+ if (insertIndex !== -1) {
58
+ const code = context.sourceCode.getText(node)
52
59
 
53
- context.report({
54
- node,
55
- message: `"${code}" は意図しない上書きを防ぐため、spread syntaxでない属性より先に記述してください
60
+ context.report({
61
+ node,
62
+ message: `"${code}" は意図しない上書きを防ぐため、spread syntaxでない属性より先に記述してください
56
63
  - 詳細: https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-spread-syntax`,
57
- fix: fixAction ? (fixer) => {
58
- const elementNode = node.parent
59
- const normals = []
60
- const spreads = []
64
+ fix: fixAction ? (fixer) => {
65
+ const elementNode = node.parent
66
+ const normals = []
67
+ const spreads = []
61
68
 
62
- elementNode[attributesKey].forEach((a, i) => {
63
- if (a !== node) {
64
- if (insertIndex === i) {
65
- spreads.push(code)
66
- }
69
+ elementNode[attributesKey].forEach((a, i) => {
70
+ if (a !== node) {
71
+ if (insertIndex === i) {
72
+ spreads.push(code)
73
+ }
67
74
 
68
- (a.type === type ? spreads : normals).push(context.sourceCode.getText(a))
69
- }
70
- })
75
+ (a.type === type ? spreads : normals).push(context.sourceCode.getText(a))
76
+ }
77
+ })
71
78
 
72
- return fixer.replaceText(
73
- elementNode,
74
- fixAction(spreads.concat(normals), elementNode),
75
- )
76
- } : null
77
- });
79
+ return fixer.replaceText(
80
+ elementNode,
81
+ fixAction(spreads.concat(normals), elementNode),
82
+ )
83
+ } : null
84
+ });
85
+ }
78
86
  }
79
- })
87
+ }
80
88
  }
81
89
 
82
- return {
83
- JSXSpreadAttribute: (
84
- CHECK_JSX_REGEX.test(checkType)
85
- ? generateAction('JSXSpreadAttribute', 'attributes', (option.fix) && ((attributes, e) => `<${e.name.name} ${attributes.join(' ')}${e.selfClosing ? ' /' : ''}>`))
86
- : undefined
87
- ),
88
- SpreadElement: (
89
- CHECK_OBJ_REGEX.test(checkType)
90
- ? generateAction('SpreadElement', 'properties', (option.fix) && ((attributes) => `{ ${attributes.join(', ')} }`))
91
- : undefined
92
- ),
93
- }
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
94
94
  },
95
95
  }
96
96
  module.exports.schema = SCHEMA
@@ -20,6 +20,9 @@ ruleTester.run('best-practice-for-spread-syntax', rule, {
20
20
  { code: `<Fuga {...props1} {...props2} id="ABC" />` },
21
21
  { code: `const hoge = { ...props, id: props.id || 'ABC' }` },
22
22
  { code: `const hoge = { ...props1, ...props2, id: 'ABC' }` },
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' } ], },
23
26
  ],
24
27
  invalid: [
25
28
  {