eslint-plugin-smarthr 0.2.2 → 0.2.3

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,13 @@
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.3](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.2...v0.2.3) (2022-08-26)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * a11y-xxxx: styled(Hoge)の実行結果を変数に代入しないパターンに対応する ([#26](https://github.com/kufu/eslint-plugin-smarthr/issues/26)) ([0bb0259](https://github.com/kufu/eslint-plugin-smarthr/commit/0bb02595a3be35802c1fe8bc41011fd1e55bf319))
11
+
5
12
  ### [0.2.2](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.1...v0.2.2) (2022-08-18)
6
13
 
7
14
 
@@ -1,3 +1,31 @@
1
+ const getExtendedComponentName = (node) => {
2
+ if (!node.parent) {
3
+ return null
4
+ }
5
+
6
+ return node.parent.id?.name || getExtendedComponentName(node.parent)
7
+ }
8
+ const getBaseComponentName = (node) => {
9
+ if (!node) {
10
+ return null
11
+ }
12
+
13
+ if (node.type === 'CallExpression') {
14
+ if (node.callee.name === 'styled') {
15
+ return node.arguments[0].name
16
+ }
17
+ if (node.callee.object?.name === 'styled') {
18
+ return node.callee.property.name
19
+ }
20
+ }
21
+
22
+ if (node?.object?.name === 'styled') {
23
+ return node.property.name
24
+ }
25
+
26
+ return getBaseComponentName(node.parent)
27
+ }
28
+
1
29
  const generateTagFormatter = ({ context, EXPECTED_NAMES }) => ({
2
30
  ImportDeclaration: (node) => {
3
31
  if (node.source.value !== 'styled-components') {
@@ -17,40 +45,29 @@ const generateTagFormatter = ({ context, EXPECTED_NAMES }) => ({
17
45
  }
18
46
  },
19
47
  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
- }
48
+ const extended = getExtendedComponentName(node)
29
49
 
30
- return null
31
- })()
50
+ if (extended) {
51
+ const base = getBaseComponentName(node.tag)
32
52
 
33
- if (!base) {
34
- return
35
- }
53
+ if (base) {
54
+ Object.entries(EXPECTED_NAMES).forEach(([b, e]) => {
55
+ if (base.match(new RegExp(b))) {
56
+ const extendedregex = new RegExp(e)
36
57
 
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
- }
58
+ if (!extended.match(extendedregex)) {
59
+ context.report({
60
+ node: node.parent,
61
+ messageId: 'format-styled-components',
62
+ data: {
63
+ message: `${extended}を正規表現 "${extendedregex.toString()}" がmatchする名称に変更してください`,
64
+ },
65
+ });
66
+ }
67
+ }
68
+ })
52
69
  }
53
- })
70
+ }
54
71
  },
55
72
  })
56
73
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-smarthr",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "author": "SmartHR",
5
5
  "license": "MIT",
6
6
  "description": "A sharable ESLint plugin for SmartHR",