Skip to content

Commit 9e8dcd9

Browse files
authored
fix: ignore vite-plugin-inspect generated data attributes (#298)
1 parent 07aacbc commit 9e8dcd9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/runtime/validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const useChecker = (
2626
}
2727

2828
// Clean up Vue scoped style attributes
29-
html = typeof html === 'string' ? html.replace(/ ?data-v-[-a-z0-9]+\b/g, '') : html
29+
html = typeof html === 'string' ? html.replace(/ ?data-v-[-a-z0-9]+(=["']([-a-z0-9]|\/|:|\.)*["'])?/g, '') : html
3030
const { valid, results } = validator.validateString(html)
3131

3232
if (valid && !results.length) {

test/checker.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ describe('useChecker', () => {
122122
expect(console.error).not.toHaveBeenCalled()
123123
})
124124

125+
it('ignores vite-plugin-inspect generated data attributes', async () => {
126+
const mockValidator = vi.fn().mockImplementation(() => ({ valid: true, results: [] }))
127+
const { checkHTML: checker } = useChecker({ validateString: mockValidator } as any, false)
128+
129+
await checker(
130+
'https://test.com/',
131+
'<a style="color:red" class="xxx" data-v-inspector="xxxx/xxx.vue:2:3">Link</a>'
132+
)
133+
expect(mockValidator).toHaveBeenCalledWith(
134+
'<a style="color:red" class="xxx">Link</a>'
135+
)
136+
expect(console.log).toHaveBeenCalledWith(
137+
`No HTML validation errors found for ${chalk.bold('https://test.com/')}`
138+
)
139+
expect(console.warn).not.toHaveBeenCalled()
140+
expect(console.error).not.toHaveBeenCalled()
141+
})
142+
125143
it('formats HTML with prettier when asked to do so', async () => {
126144
const mockValidator = vi.fn().mockImplementation(() => ({ valid: false, results: [] }))
127145
const { checkHTML: checker } = useChecker({ validateString: mockValidator } as any, true)

0 commit comments

Comments
 (0)