eslint-plugin-smarthr 0.2.24 → 0.2.25
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 +1 -1
- package/rules/best-practice-for-remote-trigger-action-dialog/README.md +31 -0
- package/rules/best-practice-for-remote-trigger-action-dialog/index.js +41 -0
- package/test/best-practice-for-remote-trigger-action-dialog.js +46 -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
|
+
### [0.2.25](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.24...v0.2.25) (2023-04-04)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* best-practice-for-remote-trigger-action-dialog ルールを追加 ([#60](https://github.com/kufu/eslint-plugin-smarthr/issues/60)) ([d2bbeef](https://github.com/kufu/eslint-plugin-smarthr/commit/d2bbeeff4d2f48133b2b44f956985cf18aae9800))
|
|
11
|
+
|
|
5
12
|
### [0.2.24](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.23...v0.2.24) (2023-03-10)
|
|
6
13
|
|
|
7
14
|
|
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
- [a11y-prohibit-input-placeholder](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/a11y-prohibit-input-placeholder)
|
|
8
8
|
- [a11y-trigger-has-button](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/a11y-trigger-has-button)
|
|
9
9
|
- [best-practice-for-date](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/best-practice-for-date)
|
|
10
|
+
- [best-practice-for-remote-trigger-action-dialog](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/best-practice-for-remote-trigger-action-dialog)
|
|
10
11
|
- [format-import-path](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/format-import-path)
|
|
11
12
|
- [format-translate-component](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/format-translate-component)
|
|
12
13
|
- [jsx-start-with-spread-attributes](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/jsx-start-with-spread-attributes)
|
package/package.json
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# smarthr/best-practice-for-remote-trigger-action-dialog
|
|
2
|
+
|
|
3
|
+
- RemoteDialogTrigger, RemoteTriggerActionDialog のベストプラクティスをチェックするルールです
|
|
4
|
+
- `id` もしくは `targetId` にリテラルな文字列以外が設定できなくなります
|
|
5
|
+
- 変数なども使えません
|
|
6
|
+
- これは対応するTriggerとDialogをわかりやすくするためです(検索などが容易になります)
|
|
7
|
+
|
|
8
|
+
## rules
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
{
|
|
12
|
+
rules: {
|
|
13
|
+
'smarthr/best-practice-for-remote-trigger-action-dialog': 'error', // 'warn', 'off'
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## ❌ Incorrect
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
<RemoteDialogTrigger targetId={id}>open.</RemoteDialogTrigger>
|
|
22
|
+
<RemoteTriggerActionDialog {...args} id={'hoge'}>content.</RemoteTriggerActionDialog>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## ✅ Correct
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
<RemoteDialogTrigger targetId="help_dialog">open.</RemoteDialogTrigger>
|
|
30
|
+
<RemoteTriggerActionDialog {...args} id="help_dialog">content.</RemoteTriggerActionDialog>
|
|
31
|
+
```
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const { generateTagFormatter } = require('../../libs/format_styled_components');
|
|
2
|
+
|
|
3
|
+
const EXPECTED_NAMES = {
|
|
4
|
+
'RemoteDialogTrigger$': 'RemoteDialogTrigger$',
|
|
5
|
+
'RemoteTrigger(.+)Dialog$': 'RemoteTrigger(.+)Dialog$',
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const REGEX_REMOTE_TRIGGER_DIALOG = /RemoteTrigger(.+)Dialog$/
|
|
9
|
+
const REGEX_REMOTE_DIALOG_TRIGGER = /RemoteDialogTrigger$/
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
meta: {
|
|
13
|
+
type: 'suggestion',
|
|
14
|
+
schema: [],
|
|
15
|
+
},
|
|
16
|
+
create(context) {
|
|
17
|
+
return {
|
|
18
|
+
...generateTagFormatter({ context, EXPECTED_NAMES }),
|
|
19
|
+
JSXOpeningElement: (node) => {
|
|
20
|
+
const nodeName = node.name.name || '';
|
|
21
|
+
|
|
22
|
+
const regexRemoteTriggerDialog = nodeName.match(REGEX_REMOTE_TRIGGER_DIALOG)
|
|
23
|
+
|
|
24
|
+
if (regexRemoteTriggerDialog || nodeName.match(REGEX_REMOTE_DIALOG_TRIGGER)) {
|
|
25
|
+
const attrName = regexRemoteTriggerDialog ? 'id' : 'targetId'
|
|
26
|
+
const id = node.attributes.find((a) => a.name?.name === attrName)
|
|
27
|
+
|
|
28
|
+
if (id.value.type !== 'Literal') {
|
|
29
|
+
context.report({
|
|
30
|
+
node: id,
|
|
31
|
+
message: `${nodeName}の${attrName}属性には直接文字列を指定してください。
|
|
32
|
+
- 変数などは利用できません(これは関連するTriggerとDialogを検索しやすくするためです)
|
|
33
|
+
- RemoteTriggerActionDialogはループやDropdown内にTriggerが存在する場合に利用してください
|
|
34
|
+
- ループやDropdown以外にTriggerが設定されている場合、TriggerAndActionDialogを利用してください`,
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const rule = require('../rules/best-practice-for-remote-trigger-action-dialog')
|
|
2
|
+
const RuleTester = require('eslint').RuleTester
|
|
3
|
+
|
|
4
|
+
const ruleTester = new RuleTester({
|
|
5
|
+
parserOptions: {
|
|
6
|
+
ecmaVersion: 2018,
|
|
7
|
+
ecmaFeatures: {
|
|
8
|
+
experimentalObjectRestSpread: true,
|
|
9
|
+
jsx: true,
|
|
10
|
+
},
|
|
11
|
+
sourceType: 'module',
|
|
12
|
+
},
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
ruleTester.run('best-practice-for-remote-trigger-action-dialog', rule, {
|
|
16
|
+
valid: [
|
|
17
|
+
{ code: `import styled from 'styled-components'` },
|
|
18
|
+
{ code: 'const HogeRemoteDialogTrigger = styled(RemoteDialogTrigger)``' },
|
|
19
|
+
{ code: 'const RemoteTriggerHogeDialog = styled(RemoteTriggerActionDialog)``' },
|
|
20
|
+
{ code: '<RemoteDialogTrigger targetId="hoge">open.</RemoteDialogTrigger>' },
|
|
21
|
+
{ code: '<StyledRemoteDialogTrigger targetId="fuga">open.</StyledRemoteDialogTrigger>' },
|
|
22
|
+
{ code: '<RemoteTriggerActionDialog {...args} id="hoge">content.</RemoteTriggerActionDialog>' },
|
|
23
|
+
{ code: '<RemoteTriggerHogeDialog {...args} id="hoge">content.</RemoteTriggerHogeDialog>' },
|
|
24
|
+
],
|
|
25
|
+
invalid: [
|
|
26
|
+
{ code: `import hoge from 'styled-components'`, errors: [ { message: `styled-components をimportする際は、名称が"styled" となるようにしてください。例: "import styled from 'styled-components'"` } ] },
|
|
27
|
+
{ code: 'const Hoge = styled(RemoteDialogTrigger)``', errors: [ { message: 'Hogeを正規表現 "/RemoteDialogTrigger$/" がmatchする名称に変更してください' } ] },
|
|
28
|
+
{ code: 'const Fuga = styled(RemoteTriggerActionDialog)``', errors: [ { message: 'Fugaを正規表現 "/RemoteTrigger(.+)Dialog$/" がmatchする名称に変更してください' } ] },
|
|
29
|
+
{ code: '<RemoteDialogTrigger targetId={hoge}>open.</RemoteDialogTrigger>', errors: [ { message: `RemoteDialogTriggerのtargetId属性には直接文字列を指定してください。
|
|
30
|
+
- 変数などは利用できません(これは関連するTriggerとDialogを検索しやすくするためです)
|
|
31
|
+
- RemoteTriggerActionDialogはループやDropdown内にTriggerが存在する場合に利用してください
|
|
32
|
+
- ループやDropdown以外にTriggerが設定されている場合、TriggerAndActionDialogを利用してください` } ] },
|
|
33
|
+
{ code: '<StyledRemoteDialogTrigger targetId={"fuga"}>open.</StyledRemoteDialogTrigger>', errors: [ { message: `StyledRemoteDialogTriggerのtargetId属性には直接文字列を指定してください。
|
|
34
|
+
- 変数などは利用できません(これは関連するTriggerとDialogを検索しやすくするためです)
|
|
35
|
+
- RemoteTriggerActionDialogはループやDropdown内にTriggerが存在する場合に利用してください
|
|
36
|
+
- ループやDropdown以外にTriggerが設定されている場合、TriggerAndActionDialogを利用してください` } ] },
|
|
37
|
+
{ code: '<RemoteTriggerHogeDialog {...args} id={hoge}>content.</RemoteTriggerHogeDialog>', errors: [ { message: `RemoteTriggerHogeDialogのid属性には直接文字列を指定してください。
|
|
38
|
+
- 変数などは利用できません(これは関連するTriggerとDialogを検索しやすくするためです)
|
|
39
|
+
- RemoteTriggerActionDialogはループやDropdown内にTriggerが存在する場合に利用してください
|
|
40
|
+
- ループやDropdown以外にTriggerが設定されている場合、TriggerAndActionDialogを利用してください` } ] },
|
|
41
|
+
{ code: '<StyldRemoteTriggerActionDialog {...args} id={"fuga"}>content.</StyldRemoteTriggerActionDialog>', errors: [ { message: `StyldRemoteTriggerActionDialogのid属性には直接文字列を指定してください。
|
|
42
|
+
- 変数などは利用できません(これは関連するTriggerとDialogを検索しやすくするためです)
|
|
43
|
+
- RemoteTriggerActionDialogはループやDropdown内にTriggerが存在する場合に利用してください
|
|
44
|
+
- ループやDropdown以外にTriggerが設定されている場合、TriggerAndActionDialogを利用してください` } ] },
|
|
45
|
+
]
|
|
46
|
+
})
|