1
1
mirror of https://github.com/theoludwig/html-w3c-validator.git synced 2024-12-08 00:45:37 +01:00

fix: only show error messages related to configured severities

This commit is contained in:
Théo LUDWIG 2023-08-09 17:04:03 +02:00
parent 284b9fb057
commit e3cd809e56
Signed by: theoludwig
GPG Key ID: ADFE5A563D718F3B
5 changed files with 67 additions and 0 deletions

View File

@ -176,6 +176,13 @@ export class HTMLValidatorCommand extends Command {
results.push({ data, isSuccess: false })
const messagesTable: string[][] = []
for (const message of result.messages) {
if (
!severities.includes(message.type as Severity) &&
!severities.includes(message.subType as Severity)
) {
continue
}
const row: string[] = []
if (message.type === 'info') {
if (message.subType === 'warning') {

View File

@ -374,4 +374,43 @@ await test('html-w3c-validator', async (t) => {
errors.join('\n')
)
})
await t.test('fails with invalid W3C HTML', async () => {
const workingDirectory = path.join(FIXTURES_PATH, 'error-invalid-w3c-html')
const errors: string[] = []
sinon.stub(console, 'error').value((error: string) => {
errors.push(error)
})
const consoleErrorSpy = sinon.spy(console, 'error')
const stream = new PassThrough()
const exitCode = await cli.run(
[`--current-working-directory=${workingDirectory}`],
{
stdin: process.stdin,
stdout: stream,
stderr: stream
}
)
stream.end()
assert.strictEqual(exitCode, 1)
const messagesTable = [
[
chalk.yellow('warning'),
'Consider adding a “lang” attribute to the “html” start tag to declare the language of this document.',
'line: 2, column: 16-6'
]
]
assert.strictEqual(
consoleErrorSpy.calledWith(
chalk.bold.red('Error:') + ' HTML validation (W3C) failed!'
),
true,
errors.join('\n')
)
assert.strictEqual(
consoleErrorSpy.calledWith(table(messagesTable)),
true,
errors.join('\n')
)
})
})

View File

@ -0,0 +1,3 @@
{
"files": ["./build/index.html", "./build/about.html"]
}

View File

@ -0,0 +1,9 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>About</title>
</head>
<body></body>
</html>

View File

@ -0,0 +1,9 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Home</title>
</head>
<body></body>
</html>