Skip to content

Commit 5302981

Browse files
committed
Support relative
1 parent ece7af8 commit 5302981

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

.changeset/mean-worlds-go.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-devup': patch
3+
---
4+
5+
Support relative

src/rules/app-page/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ESLintUtils } from '@typescript-eslint/utils'
2+
import { relative } from 'path'
23

34
const createRule = ESLintUtils.RuleCreator(
45
(name) =>
@@ -27,7 +28,7 @@ export const appPage = createRule({
2728
},
2829
},
2930
create(context) {
30-
const filename = context.physicalFilename
31+
const filename = relative(context.cwd, context.physicalFilename)
3132

3233
if (!/src[/\\]app[/\\]/.test(filename)) return {}
3334
const type = /page\.[j|t]sx?$/.test(filename)

src/rules/component/__tests__/index.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ describe('component rule', () => {
5353
code: '',
5454
filename: 'src/app/404.tsx',
5555
},
56+
{
57+
// in linux
58+
code: '',
59+
filename: '/app/apps/demo/src/A.tsx',
60+
},
5661
{
5762
code: 'export function TestComponent(){return <Row><Col></Col></Row>}',
5863
filename: 'src/components/test-component.tsx',

src/rules/component/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ESLintUtils, TSESTree } from '@typescript-eslint/utils'
2+
import { relative } from 'path'
23

34
/**
45
* 문자열을 파스칼 케이스로 변환합니다.
@@ -37,7 +38,7 @@ export const component = createRule({
3738
componentNameShouldBeFollowDirectoryStructure:
3839
'컴포넌트 이름은 디렉토리명 혹은 파일명을 따라야 합니다.',
3940
componentFileShouldExportComponent:
40-
'컴포넌트 파일은 컴포넌트를 내보내야 합니다.',
41+
'컴포넌트 파일은 컴포넌트를 내보내야 합니다. (컴포넌트명: {targetComponentName})',
4142
},
4243
type: 'problem',
4344
fixable: 'code',
@@ -47,7 +48,7 @@ export const component = createRule({
4748
},
4849
},
4950
create(context) {
50-
const filename = context.physicalFilename
51+
const filename = relative(context.cwd, context.physicalFilename)
5152

5253
// 검사 대상이 아닌 파일은 빈 객체 반환
5354
const isIncluded = INCLUDE_PATTERNS.some((pattern) =>
@@ -155,6 +156,9 @@ export const component = createRule({
155156
context.report({
156157
node: program,
157158
messageId: 'componentFileShouldExportComponent',
159+
data: {
160+
targetComponentName,
161+
},
158162
fix(fixer) {
159163
const hasContent = context.sourceCode.text.trim().length > 0
160164
const newline = hasContent ? '\n' : ''

0 commit comments

Comments
 (0)