Skip to content

Commit c7f99ce

Browse files
committed
Fix lint
1 parent 72cf9f9 commit c7f99ce

File tree

6 files changed

+179
-155
lines changed

6 files changed

+179
-155
lines changed

apps/rsbuild/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"build": "rsbuild build",
88
"dev": "rsbuild dev --open",
9-
"preview": "rsbuild preview"
9+
"preview": "rsbuild preview",
10+
"lint": "tsc && eslint"
1011
},
1112
"dependencies": {
1213
"react": "^19.1.0",

apps/rsbuild/src/App.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ const App = () => {
1111
};
1212

1313
export default App;
14+

apps/rsbuild/src/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ root.render(
88
<App />
99
</React.StrictMode>,
1010
);
11+
Lines changed: 147 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,157 +1,177 @@
1-
import { DevupUIRsbuildPlugin } from "../plugin"
2-
import { vi } from 'vitest'
31
import { mkdir, writeFile } from 'node:fs/promises'
42
import { resolve } from 'node:path'
5-
import { codeExtract } from "@devup-ui/wasm"
6-
import { write } from "node:fs"
3+
4+
import { codeExtract } from '@devup-ui/wasm'
5+
import { vi } from 'vitest'
6+
7+
import { DevupUIRsbuildPlugin } from '../plugin'
78

89
// Mock dependencies
910
vi.mock('node:fs/promises')
1011
vi.mock('@devup-ui/wasm', () => ({
11-
codeExtract: vi.fn().mockReturnValue({
12-
code: '',
13-
css: ''
14-
})
12+
codeExtract: vi.fn().mockReturnValue({
13+
code: '',
14+
css: '',
15+
}),
1516
}))
1617

1718
describe('DevupUIRsbuildPlugin', () => {
18-
beforeEach(() => {
19-
vi.resetAllMocks()
20-
vi.mocked(mkdir).mockResolvedValue(undefined)
21-
vi.mocked(writeFile).mockResolvedValue(undefined)
22-
})
19+
beforeEach(() => {
20+
vi.resetAllMocks()
21+
vi.mocked(mkdir).mockResolvedValue(undefined)
22+
vi.mocked(writeFile).mockResolvedValue(undefined)
23+
})
2324

24-
it('should export DevupUIRsbuildPlugin', () => {
25-
expect(DevupUIRsbuildPlugin).toBeDefined()
26-
})
25+
it('should export DevupUIRsbuildPlugin', () => {
26+
expect(DevupUIRsbuildPlugin).toBeDefined()
27+
})
2728

28-
it('should be a function', () => {
29-
expect(DevupUIRsbuildPlugin).toBeInstanceOf(Function)
30-
})
29+
it('should be a function', () => {
30+
expect(DevupUIRsbuildPlugin).toBeInstanceOf(Function)
31+
})
3132

32-
it('should return a plugin object with correct name', async () => {
33-
const plugin = DevupUIRsbuildPlugin()
34-
expect(plugin).toBeDefined()
35-
expect(plugin.name).toBe('devup-ui-rsbuild-plugin')
36-
expect(typeof plugin.setup).toBe('function')
33+
it('should return a plugin object with correct name', async () => {
34+
const plugin = DevupUIRsbuildPlugin()
35+
expect(plugin).toBeDefined()
36+
expect(plugin.name).toBe('devup-ui-rsbuild-plugin')
37+
expect(typeof plugin.setup).toBe('function')
3738

38-
const transform = vi.fn()
39-
await plugin.setup({
40-
transform,
41-
} as any)
42-
expect(transform).toHaveBeenCalled()
43-
})
39+
const transform = vi.fn()
40+
await plugin.setup({
41+
transform,
42+
} as any)
43+
expect(transform).toHaveBeenCalled()
44+
})
4445

45-
it('should not register css transform', async () => {
46-
const plugin = DevupUIRsbuildPlugin({
47-
extractCss: false
48-
})
49-
expect(plugin).toBeDefined()
50-
expect(plugin.setup).toBeDefined()
51-
const transform = vi.fn()
52-
await plugin.setup({
53-
transform,
54-
} as any)
55-
expect(transform).not.toHaveBeenCalled()
46+
it('should not register css transform', async () => {
47+
const plugin = DevupUIRsbuildPlugin({
48+
extractCss: false,
5649
})
50+
expect(plugin).toBeDefined()
51+
expect(plugin.setup).toBeDefined()
52+
const transform = vi.fn()
53+
await plugin.setup({
54+
transform,
55+
} as any)
56+
expect(transform).not.toHaveBeenCalled()
57+
})
5758

58-
it('should accept custom options', () => {
59-
const customOptions = {
60-
package: '@custom/devup-ui',
61-
cssFile: './custom.css',
62-
devupPath: './custom-df',
63-
interfacePath: './custom-interface',
64-
extractCss: false,
65-
debug: true,
66-
include: ['src/**/*']
67-
}
59+
it('should accept custom options', () => {
60+
const customOptions = {
61+
package: '@custom/devup-ui',
62+
cssFile: './custom.css',
63+
devupPath: './custom-df',
64+
interfacePath: './custom-interface',
65+
extractCss: false,
66+
debug: true,
67+
include: ['src/**/*'],
68+
}
6869

69-
const plugin = DevupUIRsbuildPlugin(customOptions)
70-
expect(plugin).toBeDefined()
71-
expect(plugin.name).toBe('devup-ui-rsbuild-plugin')
72-
})
73-
it('should transform css', async () => {
74-
const plugin = DevupUIRsbuildPlugin()
75-
expect(plugin).toBeDefined()
76-
expect(plugin.setup).toBeDefined()
77-
const transform = vi.fn()
78-
await plugin.setup({
79-
transform,
80-
} as any)
81-
expect(transform).toHaveBeenCalled()
82-
expect(transform).toHaveBeenCalledWith({
83-
test: resolve('.df', 'devup-ui.css'),
84-
}, expect.any(Function))
70+
const plugin = DevupUIRsbuildPlugin(customOptions)
71+
expect(plugin).toBeDefined()
72+
expect(plugin.name).toBe('devup-ui-rsbuild-plugin')
73+
})
74+
it('should transform css', async () => {
75+
const plugin = DevupUIRsbuildPlugin()
76+
expect(plugin).toBeDefined()
77+
expect(plugin.setup).toBeDefined()
78+
const transform = vi.fn()
79+
await plugin.setup({
80+
transform,
81+
} as any)
82+
expect(transform).toHaveBeenCalled()
83+
expect(transform).toHaveBeenCalledWith(
84+
{
85+
test: resolve('.df', 'devup-ui.css'),
86+
},
87+
expect.any(Function),
88+
)
8589

86-
expect(transform.mock.calls[0][1]({
87-
code: `
90+
expect(
91+
transform.mock.calls[0][1]({
92+
code: `
8893
.devup-ui-1 {
8994
color: red;
9095
}
9196
`,
92-
})).toBe('')
93-
})
94-
it('should transform code', async () => {
95-
const plugin = DevupUIRsbuildPlugin()
96-
expect(plugin).toBeDefined()
97-
expect(plugin.setup).toBeDefined()
98-
const transform = vi.fn()
99-
await plugin.setup({
100-
transform,
101-
} as any)
102-
expect(transform).toHaveBeenCalled()
103-
expect(transform).toHaveBeenCalledWith({
104-
test: /\.(tsx|ts|js|mjs|jsx)$/,
105-
}, expect.any(Function))
97+
}),
98+
).toBe('')
99+
})
100+
it('should transform code', async () => {
101+
const plugin = DevupUIRsbuildPlugin()
102+
expect(plugin).toBeDefined()
103+
expect(plugin.setup).toBeDefined()
104+
const transform = vi.fn()
105+
await plugin.setup({
106+
transform,
107+
} as any)
108+
expect(transform).toHaveBeenCalled()
109+
expect(transform).toHaveBeenCalledWith(
110+
{
111+
test: /\.(tsx|ts|js|mjs|jsx)$/,
112+
},
113+
expect.any(Function),
114+
)
106115

107-
expect(transform.mock.calls[0][1]({
108-
code: ``
109-
})).toBe('')
116+
expect(
117+
transform.mock.calls[0][1]({
118+
code: ``,
119+
}),
120+
).toBe('')
110121

111-
vi.mocked(codeExtract).mockReturnValue({
112-
code: '<div></div>',
113-
css: ''
114-
} as any)
115-
await expect(transform.mock.calls[1][1]({
116-
code: `import { Box } from '@devup-ui/react'
122+
vi.mocked(codeExtract).mockReturnValue({
123+
code: '<div></div>',
124+
css: '',
125+
} as any)
126+
await expect(
127+
transform.mock.calls[1][1]({
128+
code: `import { Box } from '@devup-ui/react'
117129
const App = () => <Box></Box>`,
118-
resourcePath: 'src/App.tsx'
119-
})).resolves.toBe('<div></div>')
130+
resourcePath: 'src/App.tsx',
131+
}),
132+
).resolves.toBe('<div></div>')
133+
})
134+
it('should transform with include', async () => {
135+
const plugin = DevupUIRsbuildPlugin({
136+
include: ['lib'],
120137
})
121-
it('should transform with include', async () => {
122-
const plugin = DevupUIRsbuildPlugin({
123-
include: ['lib']
124-
})
125-
expect(plugin).toBeDefined()
126-
expect(plugin.setup).toBeDefined()
127-
const transform = vi.fn()
128-
await plugin.setup({
129-
transform,
130-
} as any)
131-
expect(transform).toHaveBeenCalled()
132-
expect(transform).toHaveBeenCalledWith({
133-
test: /\.(tsx|ts|js|mjs|jsx)$/,
134-
}, expect.any(Function))
135-
vi.mocked(codeExtract).mockReturnValue({
136-
code: '<div></div>',
137-
css: '.devup-ui-1 { color: red; }'
138-
} as any)
139-
let ret = await transform.mock.calls[1][1]({
140-
code: `import { Box } from '@devup-ui/react'
138+
expect(plugin).toBeDefined()
139+
expect(plugin.setup).toBeDefined()
140+
const transform = vi.fn()
141+
await plugin.setup({
142+
transform,
143+
} as any)
144+
expect(transform).toHaveBeenCalled()
145+
expect(transform).toHaveBeenCalledWith(
146+
{
147+
test: /\.(tsx|ts|js|mjs|jsx)$/,
148+
},
149+
expect.any(Function),
150+
)
151+
vi.mocked(codeExtract).mockReturnValue({
152+
code: '<div></div>',
153+
css: '.devup-ui-1 { color: red; }',
154+
} as any)
155+
const ret = await transform.mock.calls[1][1]({
156+
code: `import { Box } from '@devup-ui/react'
141157
const App = () => <Box></Box>`,
142-
resourcePath: 'src/App.tsx'
143-
})
144-
expect(ret).toBe('<div></div>')
145-
expect(writeFile).toHaveBeenCalledWith(resolve('.df', 'devup-ui.css'), expect.stringMatching(/\/\* src\/App\.tsx \d+ \*\//), {
146-
encoding: 'utf-8'
147-
})
158+
resourcePath: 'src/App.tsx',
159+
})
160+
expect(ret).toBe('<div></div>')
161+
expect(writeFile).toHaveBeenCalledWith(
162+
resolve('.df', 'devup-ui.css'),
163+
expect.stringMatching(/\/\* src\/App\.tsx \d+ \*\//),
164+
{
165+
encoding: 'utf-8',
166+
},
167+
)
148168

149-
let ret1 = await transform.mock.calls[1][1]({
150-
code: `import { Box } from '@devup-ui/react'
169+
const ret1 = await transform.mock.calls[1][1]({
170+
code: `import { Box } from '@devup-ui/react'
151171
const App = () => <Box></Box>`,
152-
resourcePath: 'node_modules/@devup-ui/react/index.tsx'
153-
})
154-
expect(ret1).toBe(`import { Box } from '@devup-ui/react'
155-
const App = () => <Box></Box>`)
172+
resourcePath: 'node_modules/@devup-ui/react/index.tsx',
156173
})
157-
})
174+
expect(ret1).toBe(`import { Box } from '@devup-ui/react'
175+
const App = () => <Box></Box>`)
176+
})
177+
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export {
22
DevupUIRsbuildPlugin,
3-
type DevupUIRsbuildPluginOptions
3+
type DevupUIRsbuildPluginOptions,
44
} from './plugin'

0 commit comments

Comments
 (0)