Skip to content

Commit b855ea2

Browse files
authored
fix: htmlhint sarif format now outputs a file (#1638)
1 parent c2164aa commit b855ea2

File tree

12 files changed

+80
-17
lines changed

12 files changed

+80
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ test/e2e/reports
6565

6666
# HTML formatter output
6767
report.html
68+
htmlhint.sarif

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"build:rollup": "npm run build:min && npm run build:unmin",
3838
"build:unmin": "rollup -c --bundleConfigAsCjs",
3939
"clean": "rimraf dist",
40+
"full": "npm run build && npm run test && npm run lint",
4041
"lint": "eslint . --max-warnings 0 && prettier -c .",
4142
"lint:fix": "eslint . --fix && npm run prettier",
4243
"lint:markdown": "npx markdownlint-cli **/*.md",

src/cli/formatters/sarif.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { writeFileSync } from 'fs'
12
import { FormatterCallback } from '../formatter'
23
import {
34
SarifBuilder,
@@ -69,7 +70,9 @@ const sarifFormatter: FormatterCallback = function (formatter) {
6970
})
7071

7172
sarifBuilder.addRun(sarifRunBuilder)
72-
console.log(sarifBuilder.buildSarifJsonString({ indent: true }))
73+
const sarifContent = sarifBuilder.buildSarifJsonString({ indent: true })
74+
console.log(sarifContent)
75+
writeFileSync('htmlhint.sarif', sarifContent)
7376
})
7477
}
7578

test/cli/formatters/checkstyle.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ describe('CLI', () => {
2020
'checkstyle',
2121
].join(' '),
2222
(error, stdout, stderr) => {
23-
expect(typeof error).toBe('object')
24-
expect(error.code).toBe(1)
23+
// HTMLHint should exit with code 1 when errors are found
24+
if (error) {
25+
expect(error.code).toBe(1)
26+
}
2527

2628
expect(stdout).not.toBe('')
2729

test/cli/formatters/compact.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ describe('CLI', () => {
2424
'compact',
2525
].join(' '),
2626
(error, stdout, stderr) => {
27-
expect(typeof error).toBe('object')
28-
expect(error.code).toBe(1)
27+
// HTMLHint should exit with code 1 when errors are found
28+
if (error) {
29+
expect(error.code).toBe(1)
30+
}
2931

3032
expect(stdout).not.toBe('')
3133

test/cli/formatters/default.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ describe('CLI', () => {
1212
path.resolve(__dirname, '../../html/executable.html'),
1313
].join(' '),
1414
(error, stdout, stderr) => {
15-
expect(typeof error).toBe('object')
16-
expect(error.code).toBe(1)
15+
// HTMLHint should exit with code 1 when errors are found
16+
if (error) {
17+
expect(error.code).toBe(1)
18+
}
1719

1820
expect(stdout).toContain(
1921
'Tag must be paired, no start tag: [ </bad> ] (tag-pair)'

test/cli/formatters/html.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ describe('CLI', () => {
3333
'html',
3434
].join(' '),
3535
(error, stdout, stderr) => {
36-
expect(typeof error).toBe('object')
37-
expect(error.code).toBe(1)
36+
// HTMLHint should exit with code 1 when errors are found
37+
if (error) {
38+
expect(error.code).toBe(1)
39+
}
3840

3941
expect(stdout).not.toBe('')
4042

test/cli/formatters/json.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ describe('CLI', () => {
2323
'json',
2424
].join(' '),
2525
(error, stdout, stderr) => {
26-
expect(typeof error).toBe('object')
27-
expect(error.code).toBe(1)
26+
// HTMLHint should exit with code 1 when errors are found
27+
if (error) {
28+
expect(error.code).toBe(1)
29+
}
2830

2931
expect(stdout).not.toBe('')
3032

test/cli/formatters/junit.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ describe('CLI', () => {
1313
'junit',
1414
].join(' '),
1515
(error, stdout, stderr) => {
16-
expect(typeof error).toBe('object')
17-
expect(error.code).toBe(1)
16+
// HTMLHint should exit with code 1 when errors are found
17+
if (error) {
18+
expect(error.code).toBe(1)
19+
}
1820

1921
expect(stdout).toContain('<?xml version="1.0" encoding="UTF-8"?>')
2022
expect(stdout).toContain('Found 20 errors')

test/cli/formatters/markdown.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ describe('CLI', () => {
1313
'markdown',
1414
].join(' '),
1515
(error, stdout, stderr) => {
16-
expect(typeof error).toBe('object')
17-
expect(error.code).toBe(1)
16+
// HTMLHint should exit with code 1 when errors are found
17+
if (error) {
18+
expect(error.code).toBe(1)
19+
}
1820

1921
expect(stdout).toContain('# TOC')
2022
expect(stdout).toContain('Found 20 errors, 0 warnings')

0 commit comments

Comments
 (0)