eslint-plugin-smarthr 2.4.0 → 3.0.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 +23 -0
- package/README.md +0 -1
- package/package.json +2 -2
- package/rules/a11y-anchor-has-href-attribute/index.js +1 -0
- package/rules/a11y-clickable-element-has-text/index.js +1 -0
- package/rules/a11y-delegate-element-has-role-presentation/index.js +2 -0
- package/rules/a11y-form-control-in-form/index.js +1 -0
- package/rules/a11y-heading-in-sectioning-content/README.md +16 -1
- package/rules/a11y-heading-in-sectioning-content/index.js +7 -2
- package/rules/a11y-help-link-with-support-href/index.js +2 -1
- package/rules/a11y-image-has-alt-attribute/index.js +2 -0
- package/rules/a11y-input-has-name-attribute/index.js +6 -3
- package/rules/a11y-input-in-form-control/index.js +11 -4
- package/rules/a11y-numbered-text-within-ol/index.js +5 -0
- package/rules/a11y-prohibit-checkbox-or-radio-in-table-cell/index.js +2 -1
- package/rules/a11y-prohibit-input-maxlength-attribute/index.js +5 -4
- package/rules/a11y-prohibit-input-placeholder/index.js +7 -3
- package/rules/a11y-prohibit-sectioning-content-in-form/index.js +2 -0
- package/rules/a11y-prohibit-useless-sectioning-fragment/index.js +2 -1
- package/rules/a11y-trigger-has-button/index.js +4 -2
- package/rules/best-practice-for-async-current-target/index.js +2 -2
- package/rules/best-practice-for-button-element/index.js +1 -0
- package/rules/best-practice-for-data-test-attribute/index.js +1 -0
- package/rules/best-practice-for-date/index.js +2 -0
- package/rules/best-practice-for-layouts/index.js +22 -10
- package/rules/best-practice-for-nested-attributes-array-index/index.js +1 -0
- package/rules/best-practice-for-remote-trigger-dialog/index.js +2 -1
- package/rules/best-practice-for-tailwind-prohibit-root-margin/index.js +2 -1
- package/rules/best-practice-for-tailwind-variants/index.js +6 -3
- package/rules/component-name/README.md +11 -3
- package/rules/component-name/index.js +7 -2
- package/rules/design-system-guideline-prohibit-double-icons/index.js +1 -0
- package/rules/format-import-path/index.js +2 -1
- package/rules/jsx-start-with-spread-attributes/index.js +2 -1
- package/rules/no-import-other-domain/index.js +2 -1
- package/rules/prohibit-export-array-type/index.js +1 -0
- package/rules/prohibit-file-name/index.js +2 -1
- package/rules/prohibit-import/index.js +4 -2
- package/rules/prohibit-path-within-template-literal/index.js +2 -1
- package/rules/require-barrel-import/index.js +2 -1
- package/rules/require-declaration/index.js +4 -2
- package/rules/require-export/index.js +2 -1
- package/rules/require-i18n-text/index.js +28 -20
- package/rules/require-import/index.js +2 -1
- package/rules/trim-props/index.js +2 -1
- package/test/a11y-anchor-has-href-attribute.js +1 -0
- package/test/a11y-clickable-element-has-text.js +1 -0
- package/test/a11y-delegate-element-has-role-presentation.js +2 -0
- package/test/a11y-form-control-in-form.js +1 -0
- package/test/a11y-heading-in-sectioning-content.js +7 -2
- package/test/a11y-help-link-with-support-href.js +2 -1
- package/test/a11y-image-has-alt-attribute.js +2 -0
- package/test/a11y-input-has-name-attribute.js +30 -15
- package/test/a11y-input-in-form-control.js +15 -1
- package/test/a11y-numbered-text-within-ol.js +29 -0
- package/test/a11y-prohhibit-input-placeholder.js +19 -9
- package/test/a11y-prohibit-checkbox-or-radio-in-table-cell.js +21 -11
- package/test/a11y-prohibit-input-maxlength-attribute.js +5 -4
- package/test/a11y-prohibit-useless-sectioning-fragment.js +2 -1
- package/test/a11y-trigger-has-button.js +12 -6
- package/test/best-practice-for-async-current-target.js +2 -2
- package/test/best-practice-for-button-element.js +2 -0
- package/test/best-practice-for-data-test-attribute.js +1 -0
- package/test/best-practice-for-date.js +2 -0
- package/test/best-practice-for-layouts.js +26 -12
- package/test/best-practice-for-nested-attributes-array-index.js +1 -0
- package/test/best-practice-for-remote-trigger-dialog.js +6 -3
- package/test/best-practice-for-tailwind-prohibit-root-margin.js +2 -2
- package/test/best-practice-for-tailwind-variants.js +8 -4
- package/test/component-name.js +7 -2
- package/test/design-system-guideline-prohibit-double-icons.js +1 -0
- package/test/prohibit-file-name.js +4 -2
- package/test/prohibit-import.js +14 -7
- package/test/prohibit-path-within-template-literal.js +4 -2
- package/test/require-declaration.js +11 -5
- package/test/require-export.js +6 -3
- package/test/require-i18n-text.js +20 -3
- package/test/require-import.js +13 -7
- package/test/trim-props.js +18 -15
- package/rules/a11y-required-layout-as-attribute/README.md +0 -54
- package/rules/a11y-required-layout-as-attribute/index.js +0 -65
- package/test/a11y-required-layout-as-attribute.js +0 -34
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# smarthr/a11y-required-layout-as-attribute
|
|
2
|
-
|
|
3
|
-
- smarthr-ui/Layoutに属するコンポーネントはデフォルトではdiv要素を出力します
|
|
4
|
-
- そのため他の一部コンポーネントとの組み合わせによってはinvalidなマークアップになる場合が起こり得ます
|
|
5
|
-
- 例: FormControlのtitle属性内でClusterを使うと `label > div` の構造になるためinvalid
|
|
6
|
-
- 対象コンポーネントの使用方法をチェックし、適切なマークアップになるよう、as・forwardedAs属性の利用を促します
|
|
7
|
-
|
|
8
|
-
## rules
|
|
9
|
-
|
|
10
|
-
```js
|
|
11
|
-
{
|
|
12
|
-
rules: {
|
|
13
|
-
'smarthr/a11y-required-layout-as-attribute': [
|
|
14
|
-
'error', // 'warn', 'off'
|
|
15
|
-
]
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## ❌ Incorrect
|
|
21
|
-
|
|
22
|
-
```jsx
|
|
23
|
-
<Heading>
|
|
24
|
-
<Cluster>any</Cluster>
|
|
25
|
-
</Heading>
|
|
26
|
-
|
|
27
|
-
<HogeFormControl title={
|
|
28
|
-
<FugaCluster>any</FugaCluster>
|
|
29
|
-
} />
|
|
30
|
-
|
|
31
|
-
<StyledFieldset title={
|
|
32
|
-
<Cluster>any</Cluster>
|
|
33
|
-
}>
|
|
34
|
-
// any
|
|
35
|
-
</StyledFieldset>
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## ✅ Correct
|
|
39
|
-
|
|
40
|
-
```jsx
|
|
41
|
-
<Heading>
|
|
42
|
-
<Cluster as="span">any</Cluster>
|
|
43
|
-
</Heading>
|
|
44
|
-
|
|
45
|
-
<HogeFormControl title={
|
|
46
|
-
<FugaCluster forwardedAs="span">any</FugaCluster>
|
|
47
|
-
} />
|
|
48
|
-
|
|
49
|
-
<StyledFieldset title={
|
|
50
|
-
<Cluster as="strong">any</Cluster>
|
|
51
|
-
}>
|
|
52
|
-
// any
|
|
53
|
-
</StyledFieldset>
|
|
54
|
-
```
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
const layoutRegex = /((C(ent|lust)er)|Reel|Sidebar|Stack|Base(Column)?)$/
|
|
2
|
-
const headingRegex = /((^h(1|2|3|4|5|6))|Heading)$/
|
|
3
|
-
const asRegex = /^(as|forwardedAs)$/
|
|
4
|
-
const formControlRegex = /(FormControl|Fieldset)$/
|
|
5
|
-
|
|
6
|
-
const findAsAttr = (a) => a.name?.name.match(asRegex)
|
|
7
|
-
|
|
8
|
-
const searchBubbleUp = (node) => {
|
|
9
|
-
switch (node.type) {
|
|
10
|
-
case 'Program':
|
|
11
|
-
// rootまで検索した場合は確定でエラーにする
|
|
12
|
-
return null
|
|
13
|
-
case 'JSXElement': {
|
|
14
|
-
const name = node.openingElement.name.name || ''
|
|
15
|
-
|
|
16
|
-
if (headingRegex.test(name)) {
|
|
17
|
-
return name
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
break
|
|
21
|
-
}
|
|
22
|
-
case 'JSXAttribute': {
|
|
23
|
-
const name = node.name.name || ''
|
|
24
|
-
|
|
25
|
-
if (name === 'title' && formControlRegex.test(node.parent.name.name)) {
|
|
26
|
-
return `${node.parent.name.name}のtitle属性`
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return searchBubbleUp(node.parent)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @type {import('@typescript-eslint/utils').TSESLint.RuleModule<''>}
|
|
36
|
-
*/
|
|
37
|
-
module.exports = {
|
|
38
|
-
meta: {
|
|
39
|
-
type: 'problem',
|
|
40
|
-
schema: [],
|
|
41
|
-
},
|
|
42
|
-
create(context) {
|
|
43
|
-
return {
|
|
44
|
-
JSXOpeningElement: (node) => {
|
|
45
|
-
const name = node.name.name || ''
|
|
46
|
-
|
|
47
|
-
if (layoutRegex.test(name) && !node.attributes.some(findAsAttr)) {
|
|
48
|
-
const parentName = searchBubbleUp(node.parent.parent)
|
|
49
|
-
|
|
50
|
-
if (parentName) {
|
|
51
|
-
context.report({
|
|
52
|
-
node,
|
|
53
|
-
message: `${name}は${parentName}内に存在するため、as、もしくはforwardedAs属性を指定し、div以外の要素にする必要があります
|
|
54
|
-
- smarthr-ui/Layoutに属するコンポーネントはデフォルトでdiv要素を出力するため${parentName}内で利用すると、マークアップの仕様に違反します
|
|
55
|
-
- ほぼすべての場合、spanを指定することで適切なマークアップに変更出来ます
|
|
56
|
-
- span以外を指定したい場合、記述コンテンツに属する要素かどうかを確認してください (https://developer.mozilla.org/ja/docs/Web/HTML/Content_categories#%E8%A8%98%E8%BF%B0%E3%82%B3%E3%83%B3%E3%83%86%E3%83%B3%E3%83%84)`,
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
module.exports.schema = []
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
const rule = require('../rules/a11y-required-layout-as-attribute')
|
|
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 generateErrorText = (parentName, name) => `${name}は${parentName}内に存在するため、as、もしくはforwardedAs属性を指定し、div以外の要素にする必要があります
|
|
15
|
-
- smarthr-ui/Layoutに属するコンポーネントはデフォルトでdiv要素を出力するため${parentName}内で利用すると、マークアップの仕様に違反します
|
|
16
|
-
- ほぼすべての場合、spanを指定することで適切なマークアップに変更出来ます
|
|
17
|
-
- span以外を指定したい場合、記述コンテンツに属する要素かどうかを確認してください (https://developer.mozilla.org/ja/docs/Web/HTML/Content_categories#%E8%A8%98%E8%BF%B0%E3%82%B3%E3%83%B3%E3%83%86%E3%83%B3%E3%83%84)`
|
|
18
|
-
|
|
19
|
-
ruleTester.run('a11y-anchor-has-href-attribute', rule, {
|
|
20
|
-
valid: [
|
|
21
|
-
{ code: `<h1><Cluster as="span">ほげ</Cluster></h1>` },
|
|
22
|
-
{ code: `<Heading><Cluster as="strong" /></Heading>` },
|
|
23
|
-
{ code: `<StyledHeading><AnyCluster forwardedAs="span" /></StyledHeading>` },
|
|
24
|
-
{ code: `<FormControl title={<Cluster as="span" />} />` },
|
|
25
|
-
{ code: `<StyledFieldset title={<AnyCluster forwardedAs="strong" />} />` },
|
|
26
|
-
],
|
|
27
|
-
invalid: [
|
|
28
|
-
{ code: `<h1><Cluster>ほげ</Cluster></h1>`, errors: [{ message: generateErrorText('h1', 'Cluster') }] },
|
|
29
|
-
{ code: `<Heading><Cluster /></Heading>`, errors: [{ message: generateErrorText('Heading', 'Cluster') }] },
|
|
30
|
-
{ code: `<StyledHeading><AnyCluster /></StyledHeading>`, errors: [{ message: generateErrorText('StyledHeading', 'AnyCluster') }] },
|
|
31
|
-
{ code: `<FormControl title={<Cluster />} />`, errors: [{ message: generateErrorText('FormControlのtitle属性', 'Cluster') }] },
|
|
32
|
-
{ code: `<StyledFieldset title={<AnyCluster />} />`, errors: [{ message: generateErrorText('StyledFieldsetのtitle属性', 'AnyCluster') }] },
|
|
33
|
-
]
|
|
34
|
-
})
|