eslint-plugin-smarthr 3.2.0 → 3.3.0
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
|
+
## [3.3.0](https://github.com/kufu/tamatebako/compare/eslint-plugin-smarthr-v3.2.0...eslint-plugin-smarthr-v3.3.0) (2025-12-18)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* best-practice-for-rest-parametersを追加 ([#953](https://github.com/kufu/tamatebako/issues/953)) ([093f8f2](https://github.com/kufu/tamatebako/commit/093f8f258b65a746cc10ae90696827600ca45dfc))
|
|
11
|
+
|
|
5
12
|
## [3.2.0](https://github.com/kufu/tamatebako/compare/eslint-plugin-smarthr-v3.1.0...eslint-plugin-smarthr-v3.2.0) (2025-12-15)
|
|
6
13
|
|
|
7
14
|
|
package/README.md
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
- [best-practice-for-nested-attributes-array-index](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-nested-attributes-array-index)
|
|
24
24
|
- [best-practice-for-prohibit-import-smarthr-ui-local](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-prohibit-import-smarthr-ui-local)
|
|
25
25
|
- [best-practice-for-remote-trigger-dialog](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-remote-trigger-dialog)
|
|
26
|
+
- [best-practice-for-rest-parameters](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-rest-parameters)
|
|
26
27
|
- [best-practice-for-tailwind-prohibit-root-margin](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-tailwind-prohibit-root-margin)
|
|
27
28
|
- [best-practice-for-tailwind-variants](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-tailwind-variants)
|
|
28
29
|
- [design-system-guideline-prohibit-double-icons](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/design-system-guideline-prohibit-double-icons)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-smarthr",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
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": "61261c2334b39d607b47e1f5be64fdb74f4ac83f"
|
|
41
41
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# smarthr/best-practice-for-rest-parameters
|
|
2
|
+
|
|
3
|
+
- 残余引数(rest parameters)の命名規則を設定するルールです
|
|
4
|
+
- https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Functions/rest_parameters
|
|
5
|
+
- 残余引数にはrestという名称を設定することを推奨します
|
|
6
|
+
- よく利用される `props` という名称と完全一致する場合、エラーになります
|
|
7
|
+
- コンポーネントが受け取れる属性を定義する際、多用される "Props" 型と勘違いされる可能性を減らすためです
|
|
8
|
+
- 残余引数の時点でコンポーネントが受け取れる属性全てではないことが確定するためpropsの利用を禁止しています
|
|
9
|
+
- `xxxProps` のように他単語と組合されている場合はエラーになりません
|
|
10
|
+
- 残余引数以外でrestという名称と完全一致する設定することを禁止します
|
|
11
|
+
- restは rest parametersから命名されたjsのイディオムのため、残余引数以外の箇所で利用すると混乱を招くためです
|
|
12
|
+
- `xxxRest` のように他単語と組合されている場合はエラーになりません
|
|
13
|
+
|
|
14
|
+
## rules
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
{
|
|
18
|
+
rules: {
|
|
19
|
+
'smarthr/best-practice-for-rest-parameters': 'error', // 'warn', 'off'
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## ❌ Incorrect
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
// 残余引数にpropsという名称が設定されているためNG
|
|
28
|
+
const hoge = (a, b, ...props) => {
|
|
29
|
+
// any
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// オブジェクトの残余引数の場合も同様のチェックを行うためNG
|
|
33
|
+
const hoge = ({ a, b, ...props }) => {
|
|
34
|
+
// any
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 残余引数ではない箇所でrestという文字列と完全一致する場合NG
|
|
38
|
+
const hoge = (a, rest, b) => {
|
|
39
|
+
// any
|
|
40
|
+
}
|
|
41
|
+
// 引数以外の場合でも混乱するためNG
|
|
42
|
+
const rest = { /* any */ }
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## ✅ Correct
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
// 残余引数にrestという名称が設定されておりOK
|
|
50
|
+
const hoge = (a, b, ...rest) => {
|
|
51
|
+
// any
|
|
52
|
+
}
|
|
53
|
+
// 残余引数でもprops以外は許容
|
|
54
|
+
const hoge = ({ a, b, ...actionButtonProps }) => {
|
|
55
|
+
// any
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 残余引数以外の場合はpropsを許容
|
|
59
|
+
const hoge = (props) => {
|
|
60
|
+
// any
|
|
61
|
+
}
|
|
62
|
+
const props = { /* any */ }
|
|
63
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const SCHEMA = []
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @type {import('@typescript-eslint/utils').TSESLint.RuleModule<''>}
|
|
5
|
+
*/
|
|
6
|
+
module.exports = {
|
|
7
|
+
meta: {
|
|
8
|
+
type: 'suggestion',
|
|
9
|
+
schema: SCHEMA,
|
|
10
|
+
},
|
|
11
|
+
create(context) {
|
|
12
|
+
return {
|
|
13
|
+
[`RestElement[argument.name='props']`]: (node) => {
|
|
14
|
+
context.report({
|
|
15
|
+
node,
|
|
16
|
+
message: `残余引数には 'props' という名称を利用しないでください
|
|
17
|
+
- 詳細: https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-rest-parameters
|
|
18
|
+
- 'rest' という名称を推奨します`,
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
[`:not(RestElement)>Identifier[name='rest']`]: (node) => {
|
|
22
|
+
context.report({
|
|
23
|
+
node,
|
|
24
|
+
message: `残余引数以外に 'rest' という名称を利用しないでください
|
|
25
|
+
- 詳細: https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-rest-parameters
|
|
26
|
+
- 残余引数(rest parameters)と混同する可能性があるため別の名称に修正してください`,
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
module.exports.schema = SCHEMA
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const rule = require('../rules/best-practice-for-rest-parameters')
|
|
2
|
+
const RuleTester = require('eslint').RuleTester
|
|
3
|
+
|
|
4
|
+
const ruleTester = new RuleTester({
|
|
5
|
+
languageOptions: {
|
|
6
|
+
parserOptions: {
|
|
7
|
+
ecmaFeatures: {
|
|
8
|
+
jsx: true,
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const ERROR_PROPS = `残余引数には 'props' という名称を利用しないでください
|
|
15
|
+
- 詳細: https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-rest-parameters
|
|
16
|
+
- 'rest' という名称を推奨します`
|
|
17
|
+
const ERROR_REST = `残余引数以外に 'rest' という名称を利用しないでください
|
|
18
|
+
- 詳細: https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-rest-parameters
|
|
19
|
+
- 残余引数(rest parameters)と混同する可能性があるため別の名称に修正してください`
|
|
20
|
+
|
|
21
|
+
ruleTester.run('best-practice-for-rest-parameters', rule, {
|
|
22
|
+
valid: [
|
|
23
|
+
{ code: `const hoge = (a, b, ...rest) => {}` },
|
|
24
|
+
{ code: `const hoge = ({ a, b, ...rest }) => {}` },
|
|
25
|
+
{ code: `const hoge = (a, b, ...hoge) => {}` },
|
|
26
|
+
{ code: `const hoge = ({ a, b, ...xxxProps }) => {}` },
|
|
27
|
+
{ code: `const hoge = (props) => {}` },
|
|
28
|
+
{ code: `const props = {}` },
|
|
29
|
+
{ code: `const hogeRest = {}` },
|
|
30
|
+
],
|
|
31
|
+
invalid: [
|
|
32
|
+
{ code: `const hoge = (a, b, ...props) => {}`, errors: [ { message: ERROR_PROPS } ] },
|
|
33
|
+
{ code: `const hoge = ({ a, b, ...props }) => {}`, errors: [ { message: ERROR_PROPS } ] },
|
|
34
|
+
{ code: `const hoge = (rest) => {}`, errors: [ { message: ERROR_REST } ] },
|
|
35
|
+
{ code: `const hoge = (a, b, rest) => {}`, errors: [ { message: ERROR_REST } ] },
|
|
36
|
+
{ code: `const rest = {}`, errors: [ { message: ERROR_REST } ] },
|
|
37
|
+
]
|
|
38
|
+
})
|
|
39
|
+
|