Skip to content

Commit

Permalink
fix: ignore vite-plugin-inspect generated data attributes (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuoqi-chen authored Feb 17, 2023
1 parent 07aacbc commit 9e8dcd9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/runtime/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const useChecker = (
}

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

if (valid && !results.length) {
Expand Down
18 changes: 18 additions & 0 deletions test/checker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,24 @@ describe('useChecker', () => {
expect(console.error).not.toHaveBeenCalled()
})

it('ignores vite-plugin-inspect generated data attributes', async () => {
const mockValidator = vi.fn().mockImplementation(() => ({ valid: true, results: [] }))
const { checkHTML: checker } = useChecker({ validateString: mockValidator } as any, false)

await checker(
'https://test.com/',
'<a style="color:red" class="xxx" data-v-inspector="xxxx/xxx.vue:2:3">Link</a>'
)
expect(mockValidator).toHaveBeenCalledWith(
'<a style="color:red" class="xxx">Link</a>'
)
expect(console.log).toHaveBeenCalledWith(
`No HTML validation errors found for ${chalk.bold('https://test.com/')}`
)
expect(console.warn).not.toHaveBeenCalled()
expect(console.error).not.toHaveBeenCalled()
})

it('formats HTML with prettier when asked to do so', async () => {
const mockValidator = vi.fn().mockImplementation(() => ({ valid: false, results: [] }))
const { checkHTML: checker } = useChecker({ validateString: mockValidator } as any, true)
Expand Down

0 comments on commit 9e8dcd9

Please sign in to comment.