eslint-plugin-smarthr 0.2.5 → 0.2.7

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
+ ### [0.2.7](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.5...v0.2.7) (2022-10-03)
6
+
7
+
8
+ ### Features
9
+
10
+ * 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))
11
+ * 修正しなければ問題が起きる可能性があるruleのmeta.typeをproblemに修正 ([#31](https://github.com/kufu/eslint-plugin-smarthr/issues/31)) ([e3980e5](https://github.com/kufu/eslint-plugin-smarthr/commit/e3980e5dd226f229aa21c57b81dd2460b9b0d8c9))
12
+
13
+ ### [0.2.6](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.5...v0.2.6) (2022-09-08)
14
+
15
+ ### Features
16
+
17
+ * 修正しなければ問題が起きる可能性があるruleのmeta.typeをproblemに修正 ([#31](https://github.com/kufu/eslint-plugin-smarthr/pull/31))
18
+
5
19
  ### [0.2.5](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.4...v0.2.5) (2022-09-08)
6
20
 
7
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-smarthr",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "author": "SmartHR",
5
5
  "license": "MIT",
6
6
  "description": "A sharable ESLint plugin for SmartHR",
@@ -14,7 +14,7 @@ const filterFalsyJSXText = (cs) => cs.filter((c) => (
14
14
 
15
15
  module.exports = {
16
16
  meta: {
17
- type: 'suggestion',
17
+ type: 'problem',
18
18
  messages: {
19
19
  'format-styled-components': '{{ message }}',
20
20
  'a11y-clickable-element-has-text': '{{ message }}',
@@ -9,7 +9,7 @@ const EXPECTED_NAMES = {
9
9
 
10
10
  module.exports = {
11
11
  meta: {
12
- type: 'suggestion',
12
+ type: 'problem',
13
13
  messages: {
14
14
  'format-styled-components': '{{ message }}',
15
15
  'a11y-image-has-alt-attribute': '{{ message }}',
@@ -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 = []
@@ -17,7 +17,7 @@ const filterFalsyJSXText = (cs) => cs.filter((c) => (
17
17
 
18
18
  module.exports = {
19
19
  meta: {
20
- type: 'suggestion',
20
+ type: 'problem',
21
21
  messages: {
22
22
  'format-styled-components': '{{ message }}',
23
23
  'a11y-trigger-has-button': '{{ message }}',
@@ -1,6 +1,6 @@
1
1
  module.exports = {
2
2
  meta: {
3
- type: 'suggestion',
3
+ type: 'problem',
4
4
  messages: {
5
5
  'best-practice-for-date': '{{ message }}',
6
6
  },
@@ -10,7 +10,7 @@ const SCHEMA = [
10
10
 
11
11
  module.exports = {
12
12
  meta: {
13
- type: 'suggestion',
13
+ type: 'problem',
14
14
  messages: {
15
15
  'jsx-start-with-spread-attributes': '{{ message }}',
16
16
  },
@@ -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
+ })