eslint-plugin-smarthr 0.2.6 → 0.2.8
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,8 +2,27 @@
|
|
|
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.8](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.7...v0.2.8) (2022-10-05)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* チェックするファイルのdirを取得するロジックから正規表現を取り除く ([#33](https://github.com/kufu/eslint-plugin-smarthr/issues/33)) ([c89548e](https://github.com/kufu/eslint-plugin-smarthr/commit/c89548e465e1f5aec49c6e1fc3b66c5bfefa6281))
|
|
11
|
+
|
|
12
|
+
### [0.2.7](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.5...v0.2.7) (2022-10-03)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* add a11y-prohibit-input-placeholder rule. ([#32](https://github.com/kufu/eslint-plugin-smarthr/issues/32)) ([a6033b9](https://github.com/kufu/eslint-plugin-smarthr/commit/a6033b94ba4f4c014caab0746ab151331e45daf0))
|
|
18
|
+
* 修正しなければ問題が起きる可能性があるruleのmeta.typeをproblemに修正 ([#31](https://github.com/kufu/eslint-plugin-smarthr/issues/31)) ([e3980e5](https://github.com/kufu/eslint-plugin-smarthr/commit/e3980e5dd226f229aa21c57b81dd2460b9b0d8c9))
|
|
19
|
+
|
|
5
20
|
### [0.2.6](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.5...v0.2.6) (2022-09-08)
|
|
6
21
|
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* 修正しなければ問題が起きる可能性があるruleのmeta.typeをproblemに修正 ([#31](https://github.com/kufu/eslint-plugin-smarthr/pull/31))
|
|
25
|
+
|
|
7
26
|
### [0.2.5](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.4...v0.2.5) (2022-09-08)
|
|
8
27
|
|
|
9
28
|
|
package/libs/common_domain.js
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# smarthr/a11y-prohibit-input-placeholder
|
|
2
|
+
|
|
3
|
+
- input や textarea などの入力要素に対して placeholder を設定することを禁止するルールです
|
|
4
|
+
- placeholder は入力要素に値を設定すると閲覧が不可能になるため、アクセシビリティの観点からは基本的に非推奨です
|
|
5
|
+
- Tooltip や 別途ヒント用の要素を作成し、そちらを表示することで基本的にユーザーが閲覧する必要のあるタイミングで常に見ることができるようにしてください
|
|
6
|
+
|
|
7
|
+
## rules
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
{
|
|
11
|
+
rules: {
|
|
12
|
+
'smarthr/a11y-prohibit-input-placeholder': 'error', // 'warn', 'off'
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## ❌ Incorrect
|
|
18
|
+
|
|
19
|
+
```jsx
|
|
20
|
+
<Input placeholder="hoge" />
|
|
21
|
+
```
|
|
22
|
+
```jsx
|
|
23
|
+
<CustomTextarea placeholder="hoge" />
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## ✅ Correct
|
|
27
|
+
|
|
28
|
+
```jsx
|
|
29
|
+
<CustomInput tooltip="hoge" />
|
|
30
|
+
```
|
|
31
|
+
```jsx
|
|
32
|
+
<Wrapper>
|
|
33
|
+
<Textarea />
|
|
34
|
+
<Hint>hoge</Hint>
|
|
35
|
+
</Wrapper>
|
|
36
|
+
```
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const { generateTagFormatter } = require('../../libs/format_styled_components')
|
|
2
|
+
|
|
3
|
+
const EXPECTED_NAMES = {
|
|
4
|
+
'(i|I)nput$': 'Input$',
|
|
5
|
+
'(t|T)extarea$': 'Textarea$',
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
meta: {
|
|
10
|
+
type: 'suggestion',
|
|
11
|
+
messages: {
|
|
12
|
+
'format-styled-components': '{{ message }}',
|
|
13
|
+
'a11y-prohibit-input-placeholder': '{{ message }}',
|
|
14
|
+
},
|
|
15
|
+
schema: [],
|
|
16
|
+
},
|
|
17
|
+
create(context) {
|
|
18
|
+
return {
|
|
19
|
+
...generateTagFormatter({ context, EXPECTED_NAMES }),
|
|
20
|
+
JSXOpeningElement: (node) => {
|
|
21
|
+
if (!node.name.name) {
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const match = node.name.name.match(/((i|I)nput|(t|T)extarea)$/)
|
|
26
|
+
|
|
27
|
+
if (!match) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const placeholder = node.attributes.find((a) => a.name?.name === 'placeholder')
|
|
32
|
+
|
|
33
|
+
if (placeholder) {
|
|
34
|
+
context.report({
|
|
35
|
+
node: placeholder,
|
|
36
|
+
messageId: 'a11y-prohibit-input-placeholder',
|
|
37
|
+
data: {
|
|
38
|
+
message: 'input, textarea要素のplaceholder属性は設定せず、smarthr-ui/Tooltip や別途ヒント用要素の利用を検討してください (例: `<><Input /><Hint>ヒント</Hint></>`, `<Tooltip message="ヒント"><Textarea/></Tooltip>`)',
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
module.exports.schema = []
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const rule = require('../rules/a11y-prohibit-input-placeholder')
|
|
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('a11y-prohibit-input-placeholder', rule, {
|
|
16
|
+
valid: [
|
|
17
|
+
{ code: `import styled from 'styled-components'` },
|
|
18
|
+
{ code: `import styled, { css } from 'styled-components'` },
|
|
19
|
+
{ code: `import { css } from 'styled-components'` },
|
|
20
|
+
{ code: 'const HogeInput = styled.input``' },
|
|
21
|
+
{ code: 'const HogeTextarea = styled.textarea``' },
|
|
22
|
+
{ code: 'const HogeInput = styled(Input)``' },
|
|
23
|
+
{ code: 'const HogeInput = styled(StyledInput)``' },
|
|
24
|
+
{ code: 'const HogeTextarea = styled(Textarea)``' },
|
|
25
|
+
{ code: `<input />` },
|
|
26
|
+
{ code: `<textarea />` },
|
|
27
|
+
{ code: `<StyledInput />` },
|
|
28
|
+
{ code: `<HogeTextarea />` },
|
|
29
|
+
],
|
|
30
|
+
invalid: [
|
|
31
|
+
{ code: `import hoge from 'styled-components'`, errors: [ { message: "styled-components をimportする際は、名称が`styled` となるようにしてください。例: `import styled from 'styled-components'`" } ] },
|
|
32
|
+
{ code: 'const Hoge = styled.input``', errors: [ { message: `Hogeを正規表現 "/Input$/" がmatchする名称に変更してください` } ] },
|
|
33
|
+
{ code: 'const Hoge = styled(StyledInput)``', errors: [ { message: `Hogeを正規表現 "/Input$/" がmatchする名称に変更してください` } ] },
|
|
34
|
+
{ code: 'const Hoge = styled.textarea``', errors: [ { message: `Hogeを正規表現 "/Textarea$/" がmatchする名称に変更してください` } ] },
|
|
35
|
+
{ code: 'const Hoge = styled(StyledTextarea)``', errors: [ { message: `Hogeを正規表現 "/Textarea$/" がmatchする名称に変更してください` } ] },
|
|
36
|
+
{ code: `<input placeholder />`, errors: [ { message: 'input, textarea要素のplaceholder属性は設定せず、smarthr-ui/Tooltip や別途ヒント用要素の利用を検討してください (例: `<><Input /><Hint>ヒント</Hint></>`, `<Tooltip message="ヒント"><Textarea/></Tooltip>`)' } ] },
|
|
37
|
+
{ code: `<textarea placeholder="hoge" />`, errors: [ { message: 'input, textarea要素のplaceholder属性は設定せず、smarthr-ui/Tooltip や別途ヒント用要素の利用を検討してください (例: `<><Input /><Hint>ヒント</Hint></>`, `<Tooltip message="ヒント"><Textarea/></Tooltip>`)' } ] },
|
|
38
|
+
{ code: `<StyledInput placeholder={any} />`, errors: [ { message: 'input, textarea要素のplaceholder属性は設定せず、smarthr-ui/Tooltip や別途ヒント用要素の利用を検討してください (例: `<><Input /><Hint>ヒント</Hint></>`, `<Tooltip message="ヒント"><Textarea/></Tooltip>`)' } ] },
|
|
39
|
+
{ code: `<HogeTextarea placeholder="any" />`, errors: [ { message: 'input, textarea要素のplaceholder属性は設定せず、smarthr-ui/Tooltip や別途ヒント用要素の利用を検討してください (例: `<><Input /><Hint>ヒント</Hint></>`, `<Tooltip message="ヒント"><Textarea/></Tooltip>`)' } ] },
|
|
40
|
+
]
|
|
41
|
+
})
|