Skip to content

Commit ec81f48

Browse files
committed
Allow class
1 parent 2b2af1f commit ec81f48

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/rules/component/index.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ export const component = createRule({
5050
const filename = context.physicalFilename
5151

5252
// 검사 대상이 아닌 파일은 빈 객체 반환
53-
const isIncluded = INCLUDE_PATTERNS.some(pattern => pattern.test(filename))
54-
const isExcluded = EXCLUDE_PATTERNS.some(pattern => pattern.test(filename))
55-
53+
const isIncluded = INCLUDE_PATTERNS.some((pattern) =>
54+
pattern.test(filename),
55+
)
56+
const isExcluded = EXCLUDE_PATTERNS.some((pattern) =>
57+
pattern.test(filename),
58+
)
59+
5660
if (!isIncluded || isExcluded) {
5761
return {}
5862
}
@@ -61,12 +65,12 @@ export const component = createRule({
6165
const targetComponentRegex = /([^/\\]+)[/\\]([^/\\]+)\.[jt]sx$/i.exec(
6266
filename,
6367
)!
64-
68+
6569
const isIndex = targetComponentRegex[2].startsWith('index')
66-
const targetComponentName = isIndex
67-
? toPascal(targetComponentRegex[1])
70+
const targetComponentName = isIndex
71+
? toPascal(targetComponentRegex[1])
6872
: toPascal(targetComponentRegex[2])
69-
73+
7074
const exportFunc: TSESTree.Node[] = []
7175
let ok = false
7276

@@ -80,16 +84,16 @@ export const component = createRule({
8084
return {
8185
ExportNamedDeclaration(namedExport) {
8286
if (ok) return
83-
87+
8488
// index 파일에서 export 구문이 있는 경우 검사 통과
8589
if (namedExport.specifiers.length && isIndex) {
8690
ok = true
8791
return
8892
}
89-
93+
9094
const declaration = namedExport.declaration
9195
if (!declaration) return
92-
96+
9397
// 함수 선언 검사
9498
if (declaration.type === 'FunctionDeclaration' && declaration.id) {
9599
if (isTargetComponent(declaration.id.name)) {
@@ -98,29 +102,29 @@ export const component = createRule({
98102
}
99103
exportFunc.push(declaration.id)
100104
}
101-
105+
102106
// 클래스 선언 검사
103107
if (declaration.type === 'ClassDeclaration' && declaration.id) {
104108
if (isTargetComponent(declaration.id.name)) {
105109
ok = true
106110
return
107111
}
108112
}
109-
113+
110114
// 변수 선언 검사 (화살표 함수, 함수 표현식 등)
111115
if (declaration.type === 'VariableDeclaration') {
112116
for (const el of declaration.declarations) {
113117
if (el.id.type !== 'Identifier') continue
114-
118+
115119
if (isTargetComponent(el.id.name)) {
116120
ok = true
117121
return
118122
}
119-
120-
const isComponentFunction =
123+
124+
const isComponentFunction =
121125
el.init?.type === 'ArrowFunctionExpression' ||
122126
el.init?.type === 'FunctionExpression'
123-
127+
124128
if (isComponentFunction) {
125129
exportFunc.push(el.id)
126130
}
@@ -129,7 +133,7 @@ export const component = createRule({
129133
},
130134
'Program:exit'(program) {
131135
if (ok) return
132-
136+
133137
// 컴포넌트 이름이 일치하지 않는 경우 수정 제안
134138
if (exportFunc.length) {
135139
for (const exported of exportFunc) {
@@ -143,7 +147,7 @@ export const component = createRule({
143147
}
144148
return
145149
}
146-
150+
147151
// 컴포넌트를 내보내지 않는 경우 기본 컴포넌트 추가 제안
148152
context.report({
149153
node: program,

0 commit comments

Comments
 (0)