eslint-plugin-smarthr 0.2.12 → 0.2.14
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 +12 -0
- package/README.md +1 -0
- package/package.json +1 -1
- package/rules/redundant-name/index.js +1 -1
- package/rules/trim-props/README.md +30 -0
- package/rules/trim-props/index.js +37 -0
- package/test/trim-props.js +78 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
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.14](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.13...v0.2.14) (2022-12-13)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
* trim-propsルールを追加 ([#44](https://github.com/kufu/eslint-plugin-smarthr/pull/44))
|
|
9
|
+
|
|
10
|
+
### [0.2.13](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.12...v0.2.13) (2022-12-07)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* redundant-nameのarrowedNameなどで利用するファイルパスが削られすぎていたため、指定が行いにくい問題を修正する ([#43](https://github.com/kufu/eslint-plugin-smarthr/issues/43)) ([6de9618](https://github.com/kufu/eslint-plugin-smarthr/commit/6de961831a9f9e0e93eeeebb80e56ecb60d9a2ff))
|
|
16
|
+
|
|
5
17
|
### [0.2.12](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.11...v0.2.12) (2022-12-07)
|
|
6
18
|
|
|
7
19
|
|
package/README.md
CHANGED
|
@@ -17,3 +17,4 @@
|
|
|
17
17
|
- [require-declaration](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/require-declaration)
|
|
18
18
|
- [require-export](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/require-export)
|
|
19
19
|
- [require-import](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/require-import)
|
|
20
|
+
- [trim-props](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/trim-props)
|
package/package.json
CHANGED
|
@@ -421,7 +421,7 @@ module.exports = {
|
|
|
421
421
|
const keywords = keywordMatcher[1].split('/')
|
|
422
422
|
keywords[keywords.length - 1] = keywords[keywords.length - 1].split('.')[0]
|
|
423
423
|
|
|
424
|
-
filename = keywords.join('/')
|
|
424
|
+
filename = `${rootPath}/${keywords.join('/')}`
|
|
425
425
|
|
|
426
426
|
if (keywords[keywords.length - 1] === 'index') {
|
|
427
427
|
keywords.pop()
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# smarthr/trim-props
|
|
2
|
+
|
|
3
|
+
- このルールはCLIオプションの`--fix`で自動的に修正可能です
|
|
4
|
+
- 文字列型のpropsについて、先頭末尾に空白文字を含む文字列の設定を禁止させたい場合に利用します
|
|
5
|
+
|
|
6
|
+
## rules
|
|
7
|
+
|
|
8
|
+
```js
|
|
9
|
+
{
|
|
10
|
+
rules: {
|
|
11
|
+
'smarthr/trim-props': 'error', // 'warn', 'off',
|
|
12
|
+
},
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## ❌ Incorrect
|
|
17
|
+
|
|
18
|
+
```jsx
|
|
19
|
+
<a href=" https://www.google.com">google</a>
|
|
20
|
+
<img src={"/sample.jpg "} alt={" sample "} />
|
|
21
|
+
<div data-spec=" info-area ">....</div>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## ✅ Correct
|
|
25
|
+
|
|
26
|
+
```jsx
|
|
27
|
+
<a href="https://www.google.com">google</a>
|
|
28
|
+
<img src={"/sample.jpg"} alt={"sample"} />
|
|
29
|
+
<div data-spec="info-area">....</div>
|
|
30
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: 'suggestion',
|
|
4
|
+
messages: {
|
|
5
|
+
'trim-props': '{{ message }}',
|
|
6
|
+
},
|
|
7
|
+
schema: [],
|
|
8
|
+
fixable: 'whitespace',
|
|
9
|
+
},
|
|
10
|
+
create(context) {
|
|
11
|
+
return {
|
|
12
|
+
JSXOpeningElement: (node) =>
|
|
13
|
+
node.attributes.reduce((prev, current) => {
|
|
14
|
+
const attribute = current.value?.type === 'JSXExpressionContainer' ? current.value.expression : current.value
|
|
15
|
+
const props = attribute?.value
|
|
16
|
+
|
|
17
|
+
if (typeof props !== 'string') return prev
|
|
18
|
+
|
|
19
|
+
if (props.match(/(^\s+|\s+$)/)) {
|
|
20
|
+
return context.report({
|
|
21
|
+
node,
|
|
22
|
+
loc: current.loc,
|
|
23
|
+
messageId: 'trim-props',
|
|
24
|
+
data: {
|
|
25
|
+
message: '属性に設定している文字列から先頭、末尾の空白文字を削除してください',
|
|
26
|
+
},
|
|
27
|
+
fix(fixer) {
|
|
28
|
+
return fixer.replaceTextRange([attribute.range[0] + 1, attribute.range[1] - 1], props.trim())
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
return prev
|
|
33
|
+
}, []),
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
module.exports.schema = []
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const rule = require('../rules/trim-props')
|
|
2
|
+
const RuleTester = require('eslint').RuleTester
|
|
3
|
+
|
|
4
|
+
const ruleTester = new RuleTester({
|
|
5
|
+
parserOptions: {
|
|
6
|
+
ecmaFeatures: {
|
|
7
|
+
jsx: true,
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
ruleTester.run('trim-props', rule, {
|
|
13
|
+
valid: [
|
|
14
|
+
{ code: '<a href="https://www.google.com">google</a>' },
|
|
15
|
+
{ code: '<a href={"https://www.google.com"}>google</a>' },
|
|
16
|
+
{ code: '<img src="/sample.jpg" alt="sample" />' },
|
|
17
|
+
{ code: '<img src={"/sample.jpg"} alt={"sample"} />' },
|
|
18
|
+
{ code: '<div data-spec="info-area">....</div>' },
|
|
19
|
+
],
|
|
20
|
+
invalid: [
|
|
21
|
+
{
|
|
22
|
+
code: '<a href=" https://www.google.com">google</a>',
|
|
23
|
+
output: '<a href="https://www.google.com">google</a>',
|
|
24
|
+
errors: [{ message: '属性に設定している文字列から先頭、末尾の空白文字を削除してください' }],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
code: '<a href="https://www.google.com ">google</a>',
|
|
28
|
+
output: '<a href="https://www.google.com">google</a>',
|
|
29
|
+
errors: [{ message: '属性に設定している文字列から先頭、末尾の空白文字を削除してください' }],
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
code: '<a href=" https://www.google.com ">google</a>',
|
|
33
|
+
output: '<a href="https://www.google.com">google</a>',
|
|
34
|
+
errors: [{ message: '属性に設定している文字列から先頭、末尾の空白文字を削除してください' }],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
code: '<a href={" https://www.google.com"}>google</a>',
|
|
38
|
+
output: '<a href={"https://www.google.com"}>google</a>',
|
|
39
|
+
errors: [{ message: '属性に設定している文字列から先頭、末尾の空白文字を削除してください' }],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
code: '<a href={"https://www.google.com "}>google</a>',
|
|
43
|
+
output: '<a href={"https://www.google.com"}>google</a>',
|
|
44
|
+
errors: [{ message: '属性に設定している文字列から先頭、末尾の空白文字を削除してください' }],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
code: '<a href={" https://www.google.com "}>google</a>',
|
|
48
|
+
output: '<a href={"https://www.google.com"}>google</a>',
|
|
49
|
+
errors: [{ message: '属性に設定している文字列から先頭、末尾の空白文字を削除してください' }],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
code: '<img src=" /sample.jpg" alt="sample " />',
|
|
53
|
+
output: '<img src="/sample.jpg" alt="sample" />',
|
|
54
|
+
errors: [
|
|
55
|
+
{ message: '属性に設定している文字列から先頭、末尾の空白文字を削除してください' },
|
|
56
|
+
{ message: '属性に設定している文字列から先頭、末尾の空白文字を削除してください' },
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
code: '<img src={" /sample.jpg"} alt={"sample "} />',
|
|
61
|
+
output: '<img src={"/sample.jpg"} alt={"sample"} />',
|
|
62
|
+
errors: [
|
|
63
|
+
{ message: '属性に設定している文字列から先頭、末尾の空白文字を削除してください' },
|
|
64
|
+
{ message: '属性に設定している文字列から先頭、末尾の空白文字を削除してください' },
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
code: '<div data-spec=" info-area ">....</div>',
|
|
69
|
+
output: '<div data-spec="info-area">....</div>',
|
|
70
|
+
errors: [{ message: '属性に設定している文字列から先頭、末尾の空白文字を削除してください' }],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
code: '<div data-spec={" info-area "}>....</div>',
|
|
74
|
+
output: '<div data-spec={"info-area"}>....</div>',
|
|
75
|
+
errors: [{ message: '属性に設定している文字列から先頭、末尾の空白文字を削除してください' }],
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
})
|