eslint-plugin-smarthr 3.1.0 → 3.2.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 +7 -0
- package/README.md +1 -0
- package/package.json +3 -3
- package/rules/best-practice-for-prohibit-import-smarthr-ui-local/README.md +46 -0
- package/rules/best-practice-for-prohibit-import-smarthr-ui-local/index.js +25 -0
- package/test/best-practice-for-prohibit-import-smarthr-ui-local.js +27 -0
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.2.0](https://github.com/kufu/tamatebako/compare/eslint-plugin-smarthr-v3.1.0...eslint-plugin-smarthr-v3.2.0) (2025-12-15)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* best-practice-for-prohibit-import-smarthr-ui-local を追加 ([#946](https://github.com/kufu/tamatebako/issues/946)) ([1be8bf8](https://github.com/kufu/tamatebako/commit/1be8bf82aa97ccca9dba60277f50c5247ad2b664))
|
|
11
|
+
|
|
5
12
|
## [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
13
|
|
|
7
14
|
|
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
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)
|
|
25
26
|
- [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
27
|
- [best-practice-for-tailwind-variants](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-tailwind-variants)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-smarthr",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.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.
|
|
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": "
|
|
40
|
+
"gitHead": "c6e4fb54bb2ff5d8421c656213dc29f3bc7237ac"
|
|
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,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
|
+
})
|