eslint-plugin-smarthr 0.1.2 → 0.2.1

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.
Files changed (45) hide show
  1. package/.github/CODEOWNERS +3 -0
  2. package/CHANGELOG.md +27 -0
  3. package/README.md +15 -489
  4. package/github/CODEOWNERS +3 -0
  5. package/index.js +3 -6
  6. package/libs/format_styled_components.js +57 -0
  7. package/package.json +1 -1
  8. package/rules/a11y-clickable-element-has-text/README.md +61 -0
  9. package/rules/a11y-clickable-element-has-text/index.js +71 -0
  10. package/rules/a11y-image-has-alt-attribute/README.md +55 -0
  11. package/rules/a11y-image-has-alt-attribute/index.js +48 -0
  12. package/rules/a11y-trigger-has-button/README.md +57 -0
  13. package/rules/a11y-trigger-has-button/index.js +74 -0
  14. package/rules/best-practice-for-date/README.md +40 -0
  15. package/rules/best-practice-for-date/index.js +42 -0
  16. package/rules/format-import-path/README.md +99 -0
  17. package/rules/{format-import-path.js → format-import-path/index.js} +2 -2
  18. package/rules/format-translate-component/README.md +58 -0
  19. package/rules/format-translate-component/index.js +97 -0
  20. package/rules/jsx-start-with-spread-attributes/README.md +31 -0
  21. package/rules/{jsx-start-with-spread-attributes.js → jsx-start-with-spread-attributes/index.js} +0 -0
  22. package/rules/no-import-other-domain/README.md +85 -0
  23. package/rules/{no-import-other-domain.js → no-import-other-domain/index.js} +2 -2
  24. package/rules/prohibit-export-array-type/README.md +28 -0
  25. package/rules/prohibit-export-array-type/index.js +28 -0
  26. package/rules/prohibit-file-name/README.md +35 -0
  27. package/rules/prohibit-file-name/index.js +61 -0
  28. package/rules/prohibit-import/README.md +44 -0
  29. package/rules/{prohibit-import.js → prohibit-import/index.js} +0 -0
  30. package/rules/redundant-name/README.md +94 -0
  31. package/rules/{redundant-name.js → redundant-name/index.js} +15 -5
  32. package/rules/require-barrel-import/README.md +39 -0
  33. package/rules/{require-barrel-import.js → require-barrel-import/index.js} +1 -1
  34. package/rules/require-export/README.md +43 -0
  35. package/rules/require-export/index.js +90 -0
  36. package/rules/require-import/README.md +51 -0
  37. package/rules/{require-import.js → require-import/index.js} +0 -0
  38. package/test/a11y-clickable-element-has-text.js +142 -0
  39. package/test/a11y-image-has-alt-attribute.js +44 -0
  40. package/test/a11y-trigger-has-button.js +50 -0
  41. package/test/best-practice-for-date.js +31 -0
  42. package/test/format-translate-component.js +37 -0
  43. package/test/prohibit-file-name.js +45 -0
  44. package/test/require-export.js +83 -0
  45. package/rules/a11y-icon-button-has-name.js +0 -56
@@ -0,0 +1,3 @@
1
+ # https://help.github.com/en/articles/about-code-owners
2
+
3
+ * @kufu/group-dev-front-linter-reviewers
package/CHANGELOG.md CHANGED
@@ -2,6 +2,33 @@
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.1](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.0...v0.2.1) (2022-08-15)
6
+
7
+
8
+ ### Features
9
+
10
+ * 新しいルールの追加 (require-export, prohibit-file-name, prohibit-export-array-type, best-practice-for-date ) ([#22](https://github.com/kufu/eslint-plugin-smarthr/issues/22)) ([ddb7433](https://github.com/kufu/eslint-plugin-smarthr/commit/ddb7433c0f26d64043cdcec353143240eceeccee))
11
+
12
+ ### [0.2.0](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.1.2...v0.2.0) (2022-07-05)
13
+
14
+ ### ⚠ BREAKING CHANGES
15
+
16
+ * BREAKING CHANGE: a11-xxxx-has-text を a11-clickable-element-has-text に統一する ([#16](https://github.com/kufu/eslint-plugin-smarthr/pull/16)
17
+
18
+
19
+ ### [0.1.3](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.1.2...v0.1.3) (2022-07-05)
20
+
21
+
22
+ ### Features
23
+
24
+ * add rules format-translate-component ([#19](https://github.com/kufu/eslint-plugin-smarthr/issues/19)) ([a429e9e](https://github.com/kufu/eslint-plugin-smarthr/commit/a429e9ef31779deb8f08499cfb8cbf00322c58b8))
25
+ * リンク要素内にテキストが設定されていない場合、エラーとなるルールを追加する ([#15](https://github.com/kufu/eslint-plugin-smarthr/issues/15)) ([4bbb9c1](https://github.com/kufu/eslint-plugin-smarthr/commit/4bbb9c1204a8edd068fabcdca497d94ecc1db4a4))
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * redundant-nameのバグを修正する ([#20](https://github.com/kufu/eslint-plugin-smarthr/issues/20)) ([b733f18](https://github.com/kufu/eslint-plugin-smarthr/commit/b733f1835293c3b478f6d9bb3ebe944041c67038))
31
+
5
32
  ### [0.1.2](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.1.1...v0.1.2) (2022-03-09)
6
33
 
7
34
 
package/README.md CHANGED
@@ -1,491 +1,17 @@
1
1
  # eslint-plugin-smarthr
2
2
 
3
- ## smarthr/a11y-icon-button-has-name
4
-
5
- - ボタンの中にIconのみが設置されている場合、アクセシビリティの問題が発生する可能性を防ぐルールです
6
-
7
- ### rules
8
-
9
- ```js
10
- {
11
- rules: {
12
- 'smarthr/a11y-icon-button-has-name': 'error', // 'warn', 'off'
13
- },
14
- }
15
- ```
16
-
17
- ### ❌ Incorrect
18
-
19
- ```jsx
20
- <XxxButton>
21
- <YyyIcon />
22
- </XxxButton>
23
- ```
24
-
25
- ### ✅ Correct
26
-
27
- ```jsx
28
- <XxxButton>
29
- <YyyIcon />
30
- Hoge
31
- </XxxButton>
32
- ```
33
- ```jsx
34
- <XxxButton>
35
- <YyyIcon />
36
- <AnyComponent />
37
- </XxxButton>
38
- ```
39
- ```jsx
40
- <XxxButton>
41
- <YyyIcon visuallyHiddenText="hoge" />
42
- </XxxButton>
43
- ```
44
-
45
- ## smarthr/format-import-path
46
-
47
- - importする際のpathをフォーマットするruleです
48
- - ディレクトリ構造からドメインを識別して相対パス、絶対パスいずれかにするかを判定することが出来ます
49
- - 例: crews/index 以下同士でのimportは相対パス、crews/index外のファイルimportする場合は絶対パスにする
50
- - eslint を `--fix` オプション付きで実行すると自動的にパスを置き換えます
51
-
52
- ### config
53
-
54
- - tsconfig.json の compilerOptions.pathsに '@/*' としてroot path を指定する必要があります
55
- - ドメインを識別するために以下の設定を記述する必要があります
56
- - globalModuleDir
57
- - 全体で利用するファイルを収めているディレクトリを相対パスで指定します
58
- - domainModuleDir:
59
- - ドメイン内で共通のファイルを収めているディレクトリ名を指定します
60
- - domainConstituteDir
61
- - ドメインを構築するディレクトリ名を指定します
62
-
63
- #### ディレクトリ例
64
- ```
65
- / constants
66
- / modules // 全体共通ディレクトリ
67
- / crews
68
- / modules // 共通ディレクトリ
69
- / views
70
- / parts
71
- / index
72
- / adapters
73
- / index.ts
74
- / hoge.ts
75
- / slices
76
- / index.ts
77
- / views
78
- / index.ts
79
- / parts
80
- / Abc.ts
81
- / show
82
- / views
83
- / parts
84
- ```
85
-
86
- #### 指定例
87
- ```
88
- const DOMAIN_RULE_ARGS = {
89
- globalModuleDir: [ './constants', './modules' ],
90
- domainModuleDir: [ 'modules' ],
91
- domainConstituteDir: [ 'adapters', 'slices', 'views', 'parts' ],
92
- }
93
- ```
94
-
95
- ### rules
96
-
97
- ```js
98
- {
99
- rules: {
100
- 'smarthr/format-import-path': [
101
- 'error', // 'warn', 'off'
102
- {
103
- ...DOMAIN_RULE_ARGS,
104
- format: {
105
- // 'relative', 'auto', 'none'
106
- // all: 'absolute',
107
- outside: 'auto',
108
- globalModule: 'absolute',
109
- module: 'relative',
110
- domain: 'relative',
111
- lower: 'relative',
112
- },
113
- },
114
- ],
115
- },
116
- }
117
- ```
118
-
119
- ### ❌ Incorrect
120
-
121
- ```js
122
- // crews/index/views/index.js
123
-
124
- import slice from '@/crews/index/slice'
125
- import hoge from '@/crews/index/adapter/hoge'
126
- import Abc from '@/crews/index/views/parts/Abc'
127
- import modulePart from '@/crews/modules/views/part'
128
- import showPart from '../../show/views/parts'
129
- import globalModulePart from '../../../module/views/part'
130
- ```
131
-
132
- ### ✅ Correct
133
-
134
- ```js
135
- // crews/index/views/index.js
136
-
137
- import slice from '../slice'
138
- import hoge from '../adapter/hoge'
139
- import Abc from './parts/Abc'
140
- import modulePart from '../../modules/views/parts'
141
- import showPart from '@/crews/show/views/parts'
142
- import globalModulePart from '@/modules/views/parts'
143
- ```
144
-
145
- ## smarthr/jsx-start-with-spread-attributes
146
-
147
- - jsxを記述する際、意図しない属性の上書きを防ぐため、spread-attributesを先に指定するように強制するruleです
148
- - eslint を `--fix` オプション付きで実行する際、 fix option を true にすると自動修正します
149
-
150
- ### rules
151
-
152
- ```js
153
- {
154
- rules: {
155
- 'smarthr/jsx-start-with-spread-attributes': [
156
- 'error', // 'warn', 'off'
157
- {
158
- fix: false, // true
159
- },
160
- ]
161
- },
162
- }
163
- ```
164
-
165
- ### ❌ Incorrect
166
-
167
- ```jsx
168
- <AnyComponent hoge="hoge" {...props} />
169
- ```
170
-
171
- ### ✅ Correct
172
-
173
- ```jsx
174
- <AnyComponent {...props} hoge="hoge" />
175
- ```
176
-
177
-
178
-
179
- ## smarthr/no-import-other-domain
180
-
181
- - ドメイン外からのimportを防ぐruleです
182
- - 例: crews/index 以下からのimportはOK, crews/index から crews/show 以下をimportするとNG
183
- - ディレクトリ構造からドメインを識別して判定することが出来ます
184
-
185
- ### config
186
-
187
- - tsconfig.json の compilerOptions.pathsに '@/*' としてroot path を指定する必要があります
188
- - ドメインを識別するために以下の設定を記述する必要があります
189
- - globalModuleDir
190
- - 全体で利用するファイルを収めているディレクトリを相対パスで指定します
191
- - domainModuleDir:
192
- - ドメイン内で共通のファイルを収めているディレクトリ名を指定します
193
- - domainConstituteDir
194
- - ドメインを構築するディレクトリ名を指定します
195
-
196
- #### ディレクトリ例
197
- ```
198
- / constants
199
- / modules // 全体共通ディレクトリ
200
- / crews
201
- / modules // 共通ディレクトリ
202
- / views
203
- / parts
204
- / index
205
- / adapters
206
- / index.ts
207
- / hoge.ts
208
- / slices
209
- / index.ts
210
- / views
211
- / index.ts
212
- / parts
213
- / Abc.ts
214
- / show
215
- / views
216
- / parts
217
- ```
218
-
219
- #### 指定例
220
- ```
221
- const DOMAIN_RULE_ARGS = {
222
- globalModuleDir: [ './constants', './modules' ],
223
- domainModuleDir: [ 'modules' ],
224
- domainConstituteDir: [ 'adapters', 'slices', 'views', 'parts' ],
225
- }
226
- ```
227
-
228
- ### rules
229
-
230
- ```js
231
- {
232
- rules: {
233
- 'smarthr/no-import-other-domain': [
234
- 'error', // 'warn', 'off'
235
- {
236
- ...DOMAIN_RULE_ARGS,
237
- // analyticsMode: 'all', // 'same-domain', 'another-domain'
238
- }
239
- ]
240
- },
241
- }
242
- ```
243
-
244
- ### ❌ Incorrect
245
-
246
- ```js
247
- // crews/index/views/index.js
248
-
249
- import showPart1 from '@/crews/show/views/parts'
250
- import showPart2 from '../../show/views/parts'
251
- ```
252
-
253
- ### ✅ Correct
254
-
255
- ```js
256
- // crews/index/views/index.js
257
-
258
- import slice from '../slice'
259
- import hoge from '../adapter/hoge'
260
- import Abc from './parts/Abc'
261
- import modulePart from '../../modules/views/parts'
262
- import globalModulePart from '@/modules/views/parts'
263
- ```
264
-
265
- ## smarthr/prohibit-import
266
-
267
- - 例えば特定の module にバグが発見されたなど、importさせたくない場合に利用するルールです
268
-
269
- ### rules
270
-
271
- ```js
272
- {
273
- rules: {
274
- 'smarthr/prohibit-import': [
275
- 'error', // 'warn', 'off'
276
- {
277
- '^.+$': {
278
- 'smarthr-ui': {
279
- imported: ['SecondaryButtonAnchor'],
280
- reportMessage: `{{module}}/{{export}} はXxxxxxなので利用せず yyyy/zzzz を利用してください`
281
- },
282
- }
283
- '\/pages\/views\/': {
284
- 'query-string': {
285
- imported: true,
286
- },
287
- },
288
- }
289
- ]
290
- },
291
- }
292
- ```
293
-
294
- ### ❌ Incorrect
295
-
296
- ```js
297
- // src/pages/views/Page.tsx
298
- import queryString from 'query-string'
299
- import { SecondaryButtonAnchor } from 'smarthr-ui'
300
- ```
301
-
302
- ### ✅ Correct
303
-
304
-
305
- ```js
306
- // src/pages/views/Page.tsx
307
- import { PrimaryButton, SecondaryButton } from 'smarthr-ui'
308
- ```
309
-
310
- ## smarthr/require-import
311
-
312
- - 対象ファイルにimportを強制させたい場合に利用します
313
- - 例: Page.tsx ではページタイトルを設定させたいので useTitle を必ずimportさせたい
314
-
315
- ### rules
316
-
317
- ```js
318
- {
319
- rules: {
320
- 'smarthr/require-import': [
321
- 'error',
322
- {
323
- 'Buttons\/.+\.tsx': {
324
- 'smarthr-ui': {
325
- imported: ['SecondaryButton'],
326
- reportMessage: 'Buttons以下のコンポーネントでは {{module}}/{{export}} を拡張するようにしてください',
327
- },
328
- },
329
- 'Page.tsx$': {
330
- './client/src/hooks/useTitle': {
331
- imported: true,
332
- reportMessage: '{{module}} を利用してください(ページタイトルを設定するため必要です)',
333
- },
334
- },
335
- },
336
- ]
337
- },
338
- }
339
- ```
340
-
341
- ### ❌ Incorrect
342
-
343
- ```js
344
- // client/src/Buttons/SecondaryButton.tsx
345
- import { SecondaryButtonAnchor } from 'smarthr-ui'
346
-
347
- // client/src/Page.tsx
348
- import { SecondaryButton } from 'smarthr-ui'
349
- ```
350
-
351
- ### ✅ Correct
352
-
353
-
354
- ```js
355
- // client/src/Buttons/SecondaryButton.tsx
356
- import { SecondaryButton } from 'smarthr-ui'
357
-
358
- // client/src/Page.tsx
359
- import useTitle from '.hooks/useTitle'
360
- ```
361
-
362
- ## smarthr/require-barrel-import
363
-
364
- - tsconfig.json の compilerOptions.pathsに '@/*' としてroot path を指定する必要があります
365
- - importした対象が本来exportされているべきであるbarrel(index.tsなど)が有る場合、import pathの変更を促します
366
- - 例: Page/parts/Menu/Item の import は Page/parts/Menu から行わせたい
367
- - ディレクトリ内のindexファイルを捜査し、対象を決定します
368
-
369
- ### rules
370
-
371
- ```js
372
- {
373
- rules: {
374
- 'smarthr/require-barrel-import': 'error',
375
- },
376
- }
377
- ```
378
-
379
- ### ❌ Incorrect
380
-
381
- ```js
382
- // client/src/views/Page/parts/Menu/index.ts
383
- export { Menu } from './Menu'
384
- export { Item } from './Item'
385
-
386
- // client/src/App.tsx
387
- import { Item } from './Page/parts/Menu/Item'
388
- ```
389
-
390
- ### ✅ Correct
391
-
392
-
393
- ```js
394
- // client/src/views/Page/parts/Menu/index.ts
395
- export { Menu } from './Menu'
396
- export { Item } from './Item'
397
-
398
- // client/src/App.tsx
399
- import { Item } from './Page/parts/Menu'
400
- ```
401
-
402
-
403
- ## smarthr/redundant-name
404
-
405
- - ファイル、コードの冗長な部分を取り除くことを提案するruleです
406
- - ファイルが設置されているディレクトリ構造からキーワードを生成し、取り除く文字列を生成します
407
-
408
- ### config
409
-
410
- - tsconfig.json の compilerOptions.pathsに '@/*' としてroot path を指定する必要があります
411
- - 以下の設定を行えます。全て省略可能です。
412
- - ignoreKeywords
413
- - ディレクトリ名から生成されるキーワードに含めたくない文字列を指定します
414
- - betterNames
415
- - 対象の名前を修正する候補を指定します
416
- - suffix:
417
- - type のみ指定出来ます
418
- - type のsuffixを指定します
419
-
420
- #### ファイル例
421
- - `@/crews/index/views/page.tsx` の場合
422
- - 生成されるキーワードは `['crews', 'crew', 'index', 'page']`
423
- - `@/crews/index/views/parts/Abc.tsx` の場合
424
- - 生成されるキーワードは `['crews', 'crew', 'index', 'Abc']`
425
- - `@/crews/index/repositories/index.ts` の場合
426
- - 生成されるキーワードは `['crews', 'crew', 'index', 'repositories', 'repository']`
427
-
428
-
429
- ### rules
430
-
431
- ```js
432
- const ignorekeywords = ['views', 'parts']
433
- const betterNames = {
434
- '\/repositories\/': {
435
- operator: '-',
436
- names: ['repository', 'Repository'],
437
- },
438
- '\/entities\/': {
439
- operator: '+',
440
- names: ['entity'],
441
- },
442
- '\/slices\/': {
443
- operator: '=',
444
- names: ['index'],
445
- },
446
- }
447
-
448
- {
449
- rules: {
450
- 'smarthr/redundant-name': [
451
- 'error', // 'warn', 'off'
452
- {
453
- type: { ignorekeywords, suffix: ['Props', 'Type'] },
454
- file: { ignorekeywords, betternames },
455
- // property: { ignorekeywords },
456
- // function: { ignorekeywords },
457
- // variable: { ignorekeywords },
458
- // class: { ignorekeywords },
459
- }
460
- ]
461
- },
462
- }
463
- ```
464
-
465
- ### ❌ Incorrect
466
-
467
- ```js
468
- // @/crews/index/views/page.tsx
469
-
470
- type CrewIndexPage = { hoge: string }
471
- type CrewsView = { hoge: string }
472
- ```
473
- ```js
474
- // @/crews/show/repositories/index.tsx
475
-
476
- type CrewIndexRepository = { hoge: () => any }
477
- ```
478
-
479
- ### ✅ Correct
480
-
481
- ```js
482
- // @/crews/index/views/page.tsx
483
-
484
- type ItemProps = { hoge: string }
485
- ```
486
- ```js
487
- // @/crews/show/repositories/index.tsx
488
-
489
- type IndexProps = { hoge: () => any }
490
- type ResponseType = { hoge: () => any }
491
- ``
3
+ - [a11y-clickable-element-has-text](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/a11y-clickable-element-has-text)
4
+ - [a11y-image-has-alt-attribute](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/a11y-image-has-alt-attribute)
5
+ - [a11y-trigger-has-button](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/a11y-trigger-has-button)
6
+ - [best-practice-for-date](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/best-practice-for-date)
7
+ - [format-import-path](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/format-import-path)
8
+ - [format-translate-component](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/format-translate-component)
9
+ - [jsx-start-with-spread-attributes](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/jsx-start-with-spread-attributes)
10
+ - [no-import-other-domain](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/no-import-other-domain)
11
+ - [prohibit-export-array-type](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/prohibit-export-array-type)
12
+ - [prohibit-file-name](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/prohibit-file-name)
13
+ - [prohibit-import](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/prohibit-import)
14
+ - [redundant-name](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/redundant-name)
15
+ - [require-barrel-import](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/require-barrel-import)
16
+ - [require-export](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/require-export)
17
+ - [require-import](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/require-import)
@@ -0,0 +1,3 @@
1
+ # https://help.github.com/en/articles/about-code-owners
2
+
3
+ * @kufu/group-dev-front-linter-reviewers
package/index.js CHANGED
@@ -14,14 +14,11 @@ module.exports = {
14
14
 
15
15
  function generateRulesMap() {
16
16
  let rulesPath = path.join(__dirname, 'rules');
17
- let files = fs.readdirSync(rulesPath);
17
+ let dirs = fs.readdirSync(rulesPath);
18
18
 
19
19
  let rulesMap = {};
20
- for (let file of files) {
21
- if (file.endsWith('.js') && !file.endsWith('.test.js')) {
22
- let ruleName = path.parse(file).name;
23
- rulesMap[ruleName] = require(`./rules/${file}`);
24
- }
20
+ for (let dir of dirs) {
21
+ rulesMap[path.parse(dir).name] = require(`./rules/${dir}`);
25
22
  }
26
23
  return rulesMap;
27
24
  }
@@ -0,0 +1,57 @@
1
+ const generateTagFormatter = ({ context, EXPECTED_NAMES }) => ({
2
+ ImportDeclaration: (node) => {
3
+ if (node.source.value !== 'styled-components') {
4
+ return
5
+ }
6
+
7
+ const invalidNameNode = node.specifiers.find((s) => s.type === 'ImportDefaultSpecifier' && s.local.name !== 'styled')
8
+
9
+ if (invalidNameNode) {
10
+ context.report({
11
+ node: invalidNameNode,
12
+ messageId: 'format-styled-components',
13
+ data: {
14
+ message: "styled-components をimportする際は、名称が`styled` となるようにしてください。例: `import styled from 'styled-components'`",
15
+ },
16
+ });
17
+ }
18
+ },
19
+ TaggedTemplateExpression: (node) => {
20
+ const { tag } = node
21
+ const base = (() => {
22
+ if (tag.type === 'CallExpression' && tag.callee.name === 'styled') {
23
+ return tag.arguments[0].name
24
+ }
25
+
26
+ if (tag?.object?.name === 'styled') {
27
+ return tag.property.name
28
+ }
29
+
30
+ return null
31
+ })()
32
+
33
+ if (!base) {
34
+ return
35
+ }
36
+
37
+ const extended = node.parent.id.name
38
+
39
+ Object.entries(EXPECTED_NAMES).forEach(([b, e]) => {
40
+ if (base.match(new RegExp(b))) {
41
+ const extendedregex = new RegExp(e)
42
+
43
+ if (!extended.match(extendedregex)) {
44
+ context.report({
45
+ node: node.parent,
46
+ messageId: 'format-styled-components',
47
+ data: {
48
+ message: `${extended}を正規表現 "${extendedregex.toString()}" がmatchする名称に変更してください`,
49
+ },
50
+ });
51
+ }
52
+ }
53
+ })
54
+ },
55
+ })
56
+
57
+ module.exports = { generateTagFormatter }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-smarthr",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "author": "SmartHR",
5
5
  "license": "MIT",
6
6
  "description": "A sharable ESLint plugin for SmartHR",
@@ -0,0 +1,61 @@
1
+ # smarthr/a11y-clickable-element-has-text
2
+
3
+ - ButtonやAnchor,Link コンポーネントにテキスト要素が設定されていない場合、アクセシビリティの問題が発生する可能性を防ぐルールです
4
+
5
+ ## rules
6
+
7
+ ```js
8
+ {
9
+ rules: {
10
+ 'smarthr/a11y-clickable-element-has-text': 'error', // 'warn', 'off'
11
+ },
12
+ }
13
+ ```
14
+
15
+ ## ❌ Incorrect
16
+
17
+ ```jsx
18
+ <XxxAnchor>
19
+ <Xxx />
20
+ </XxxAnchor>
21
+ ```
22
+
23
+ ```jsx
24
+ <XxxLink>
25
+ <Yyy />
26
+ </XxxLink>
27
+ ```
28
+
29
+ ```jsx
30
+ <XxxButton>
31
+ <Zzz />
32
+ </XxxButton>
33
+ ```
34
+
35
+ ## ✅ Correct
36
+
37
+ ```jsx
38
+ <XxxAnchor>
39
+ Hoge
40
+ </XxxAnchor>
41
+ ```
42
+ ```jsx
43
+ <XxxLink>
44
+ <YyyIcon />
45
+ Fuga
46
+ </XxxLink>
47
+ ```
48
+ ```jsx
49
+ <XxxAnchor>>
50
+ <YyyIcon visuallyHiddenText="hoge" />
51
+ </XxxAnchor>
52
+ ```
53
+ ```jsx
54
+ <XxxButton>
55
+ <YyyImage alt="fuga" />
56
+ </XxxButton>
57
+ ```
58
+
59
+ ```jsx
60
+ <YyyAnchoor />
61
+ ```