eslint-plugin-smarthr 3.1.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,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
+ ## [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
+
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)
13
+
14
+
15
+ ### Features
16
+
17
+ * best-practice-for-prohibit-import-smarthr-ui-local を追加 ([#946](https://github.com/kufu/tamatebako/issues/946)) ([1be8bf8](https://github.com/kufu/tamatebako/commit/1be8bf82aa97ccca9dba60277f50c5247ad2b664))
18
+
5
19
  ## [3.1.0](https://github.com/kufu/tamatebako/compare/eslint-plugin-smarthr-v3.0.0...eslint-plugin-smarthr-v3.1.0) (2025-12-10)
6
20
 
7
21
 
package/README.md CHANGED
@@ -21,7 +21,9 @@
21
21
  - [best-practice-for-date](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-date)
22
22
  - [best-practice-for-layouts](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-layouts)
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
+ - [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)
24
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)
25
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)
26
28
  - [best-practice-for-tailwind-variants](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-tailwind-variants)
27
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.1.0",
3
+ "version": "3.3.0",
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.48.1"
29
+ "typescript-eslint": "^8.49.0"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "eslint": "^9"
@@ -37,5 +37,5 @@
37
37
  "eslintplugin",
38
38
  "smarthr"
39
39
  ],
40
- "gitHead": "beddf6927401452bb9ac84ab7de9bb3fe0d85461"
40
+ "gitHead": "61261c2334b39d607b47e1f5be64fdb74f4ac83f"
41
41
  }
@@ -0,0 +1,46 @@
1
+ # smarthr/best-practice-for-prohibit-import-smarthr-ui-local
2
+
3
+ - smarthr-uiの内部的に利用している型などのimportを禁止します
4
+ - 型は必要とするコンポーネントなどから生成することをおすすめします
5
+
6
+ ## rules
7
+
8
+ ```js
9
+ {
10
+ rules: {
11
+ 'smarthr/best-practice-for-prohibit-import-smarthr-ui-local': 'error', // 'warn', 'off'
12
+ },
13
+ }
14
+ ```
15
+
16
+ ## ❌ Incorrect
17
+
18
+ ```jsx
19
+ // smarthr-uiの内部構造に依存したpathからimportしているためNG
20
+ import { AnchorButton } from 'smarthr-ui/lib/components/Button/AnchorButton'
21
+ import { FaArrowRightIcon } from 'smarthr-ui/lib/components/Icon'
22
+
23
+ // 型情報は内部実装、storybookのためにexportしているもののため利用するとNG
24
+ import { HeadingTagTypes } from 'smarthr-ui/lib/components/Heading/Heading'
25
+ import type { Variant } from 'smarthr-ui/lib/components/Button/types'
26
+ import { type Navigation } from 'smarthr-ui/lib/components/AppHeader/types'
27
+ ```
28
+
29
+ ## ✅ Correct
30
+
31
+ ```jsx
32
+ // 'smarthr-ui' からimportしているのでOK
33
+ import { AnchorButton, FaArrowRightIcon } from 'smarthr-ui'
34
+
35
+ // 型情報をコンポーネントから生成しているのでOK
36
+ import { ComponentProps } from 'react'
37
+
38
+ import { Heading } from 'smarthr-ui'
39
+ type HeadingTagTypes = Required<ComponentProps<typeof Heading>>['tag']
40
+
41
+ import { Button } from 'smarthr-ui'
42
+ type Variant = Required<ComponentProps<typeof Button>>['variant']
43
+
44
+ import { AppHeader } from 'smarthr-ui'
45
+ type Navigation = Exclude<ComponentProps<typeof AppHeader>['navigations'], undefined | null>[number]
46
+ ```
@@ -0,0 +1,25 @@
1
+ const SCHEMA = []
2
+
3
+ /**
4
+ * @type {import('@typescript-eslint/utils').TSESLint.RuleModule<''>}
5
+ */
6
+ module.exports = {
7
+ meta: {
8
+ type: 'problem',
9
+ schema: SCHEMA,
10
+ },
11
+ create(context) {
12
+ return {
13
+ [`ImportDeclaration[source.value=/^smarthr-ui\\u002Flib\\u002Fcomponents\\u002F/]`]: (node) => {
14
+ context.report({
15
+ node,
16
+ message: `smarthr-uiからコンポーネントや型をimportする際は 'smarthr-ui' からimportしてください
17
+ - 詳細: https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-prohibit-import-smarthr-ui-local
18
+ - 'smarthr-ui/lib/components' 以下からのexportはsmarthr-uiの内部実装・もしくはstorybook用であり、プロダクトからの利用は非推奨です
19
+ - 型を使いたい場合、コンポーネントからreact/ComponentPropsを利用し生成するように修正してください`,
20
+ })
21
+ },
22
+ }
23
+ },
24
+ }
25
+ module.exports.schema = SCHEMA
@@ -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,27 @@
1
+ const rule = require('../rules/best-practice-for-prohibit-import-smarthr-ui-local')
2
+ const RuleTester = require('eslint').RuleTester
3
+
4
+ const ERROR_MESSAGE = `smarthr-uiからコンポーネントや型をimportする際は 'smarthr-ui' からimportしてください
5
+ - 詳細: https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-prohibit-import-smarthr-ui-local
6
+ - 'smarthr-ui/lib/components' 以下からのexportはsmarthr-uiの内部実装・もしくはstorybook用であり、プロダクトからの利用は非推奨です
7
+ - 型を使いたい場合、コンポーネントからreact/ComponentPropsを利用し生成するように修正してください`
8
+
9
+ const ruleTester = new RuleTester({
10
+ languageOptions: {
11
+ parserOptions: {
12
+ ecmaFeatures: {
13
+ jsx: true,
14
+ },
15
+ },
16
+ },
17
+ })
18
+ ruleTester.run('best-practice-for-prohibit-import-smarthr-ui-local', rule, {
19
+ valid: [
20
+ { code: `import { AnchorButton } from 'smarthr-ui'` },
21
+ ],
22
+ invalid: [
23
+ { code: `import { AnchorButton } from 'smarthr-ui/lib/components/Button/AnchorButton'`, errors: [ { message: ERROR_MESSAGE } ] },
24
+ { code: `import { FaArrowRightIcon } from 'smarthr-ui/lib/components/Icon'`, errors: [ { message: ERROR_MESSAGE } ] },
25
+ { code: `import { HeadingTagTypes } from 'smarthr-ui/lib/components/Heading/Heading'`, errors: [ { message: ERROR_MESSAGE } ] },
26
+ ]
27
+ })
@@ -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
+