Skip to content

Commit 951119b

Browse files
committed
Improve HTML Report formatting
- Ensure valid, semantic HTML - Nicer fonts
1 parent a8d2b80 commit 951119b

File tree

5 files changed

+72
-19
lines changed

5 files changed

+72
-19
lines changed

.cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"msapplication",
3838
"nocolor",
3939
"nodir",
40+
"noopener",
4041
"nomix",
4142
"npmjs",
4243
"onttt",

.github/copilot-instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
- Rules in src/core/core.ts should be listed alphabetically.
1919
- Use the provided code snippets as examples for rule documentation.
2020
- Newly added rules pages for the website should have the frontmatter: sidebar: hidden: true badge: New
21+
- Always run `npm run build` before running tests or committing changes.

dist/cli/formatters/html.js

Lines changed: 19 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli/formatters/html.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,36 @@ import { FormatterCallback } from '../formatter'
33

44
const htmlFormatter: FormatterCallback = function (formatter) {
55
formatter.on('end', (event) => {
6-
let fileContent = '<html>'
7-
fileContent += '<head><title>HTML Hint Violation Report</title></head>'
8-
fileContent += '<body>'
9-
fileContent += '<center><h2>Violation Report</h2></center>'
10-
11-
fileContent += '<table border="1">'
6+
let fileContent = '<!DOCTYPE html><html lang="en">'
7+
fileContent += '\n<meta charset="UTF-8">'
8+
fileContent +=
9+
'\n<meta name="viewport" content="width=device-width, initial-scale=1">'
10+
fileContent += '\n<head><title>HTML Hint Violation Report</title>'
11+
fileContent += '\n<meta name="generator" content="HTMLHint"></head>'
12+
fileContent += '\n<body style="font-family: Arial, helvetica, sans-serif;">'
13+
fileContent += '\n<h1>Violation Report</h1>'
14+
fileContent += '\n<main>'
15+
fileContent += '\n<table>'
1216
fileContent +=
13-
'<tr><th>Number#</th><th>File Name</th><th>Line Number</th><th>Message</th></tr>'
17+
'\n<tr><th>Number#</th><th>File Name</th><th>Line Number</th><th>Message</th></tr>'
1418

1519
for (const { file, messages } of event.arrAllMessages) {
1620
fileContent += messages
1721
.map(
1822
({ line, message }, i) =>
19-
`<tr><td>${
23+
`\n<tr><td>${
2024
i + 1
2125
}</td><td>${file}</td><td>${line}</td><td>${message}</td></tr>`
2226
)
2327
.join('')
2428
}
2529

26-
fileContent += '</table></body></html>'
30+
fileContent += '</table>'
31+
fileContent +=
32+
'\n<p><footer><small>Generated by <a href="https://htmlhint.com" target="_blank" rel="noopener">HTMLHint</a></small></footer></p>'
33+
fileContent += '\n</main>'
34+
fileContent += '\n</body>'
35+
fileContent += '</html>'
2736
console.log(fileContent)
2837
writeFileSync('report.html', fileContent)
2938
})

test/cli/formatters/html.html

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1-
<html><head><title>HTML Hint Violation Report</title></head><body><center><h2>Violation Report</h2></center><table border="1"><tr><th>Number#</th><th>File Name</th><th>Line Number</th><th>Message</th></tr><tr><td>1</td><td>{{path}}</td><td>8</td><td>The value of attribute [ bad ] must be in double quotes.</td></tr><tr><td>2</td><td>{{path}}</td><td>8</td><td>The value of attribute [ bad ] must be in double quotes.</td></tr><tr><td>3</td><td>{{path}}</td><td>8</td><td>Duplicate of attribute name [ bad ] was found.</td></tr><tr><td>4</td><td>{{path}}</td><td>9</td><td>The value of attribute [ bad ] must be in double quotes.</td></tr><tr><td>5</td><td>{{path}}</td><td>9</td><td>The value of attribute [ bad ] must be in double quotes.</td></tr><tr><td>6</td><td>{{path}}</td><td>9</td><td>Duplicate of attribute name [ bad ] was found.</td></tr><tr><td>7</td><td>{{path}}</td><td>10</td><td>Tag must be paired, no start tag: [ </input> ]</td></tr><tr><td>8</td><td>{{path}}</td><td>11</td><td>Special characters must be escaped : [ < ].</td></tr><tr><td>9</td><td>{{path}}</td><td>11</td><td>Special characters must be escaped : [ > ].</td></tr><tr><td>10</td><td>{{path}}</td><td>13</td><td>Tag must be paired, no start tag: [ </div> ]</td></tr><tr><td>11</td><td>{{path}}</td><td>14</td><td>Tag must be paired, no start tag: [ </div> ]</td></tr><tr><td>12</td><td>{{path}}</td><td>15</td><td>Tag must be paired, no start tag: [ </hello> ]</td></tr><tr><td>13</td><td>{{path}}</td><td>16</td><td>Tag must be paired, no start tag: [ </test> ]</td></tr><tr><td>14</td><td>{{path}}</td><td>17</td><td>Tag must be paired, no start tag: [ </div> ]</td></tr><tr><td>15</td><td>{{path}}</td><td>21</td><td>The value of attribute [ class ] must be in double quotes.</td></tr><tr><td>16</td><td>{{path}}</td><td>21</td><td>The value of attribute [ what ] must be in double quotes.</td></tr><tr><td>17</td><td>{{path}}</td><td>21</td><td>The value of attribute [ something ] must be in double quotes.</td></tr><tr><td>18</td><td>{{path}}</td><td>25</td><td>Tag must be paired, no start tag: [ </div> ]</td></tr><tr><td>19</td><td>{{path}}</td><td>26</td><td>Tag must be paired, no start tag: [ </bad> ]</td></tr><tr><td>20</td><td>{{path}}</td><td>27</td><td>Tag must be paired, no start tag: [ </bad> ]</td></tr></table></body></html>
1+
<!DOCTYPE html><html lang="en">
2+
<meta charset="UTF-8">
3+
<meta name="viewport" content="width=device-width, initial-scale=1">
4+
<head><title>HTML Hint Violation Report</title>
5+
<meta name="generator" content="HTMLHint"></head>
6+
<body style="font-family: Arial, helvetica, sans-serif;">
7+
<h1>Violation Report</h1>
8+
<main>
9+
<table>
10+
<tr><th>Number#</th><th>File Name</th><th>Line Number</th><th>Message</th></tr>
11+
<tr><td>1</td><td>{{path}}</td><td>8</td><td>The value of attribute [ bad ] must be in double quotes.</td></tr>
12+
<tr><td>2</td><td>{{path}}</td><td>8</td><td>The value of attribute [ bad ] must be in double quotes.</td></tr>
13+
<tr><td>3</td><td>{{path}}</td><td>8</td><td>Duplicate of attribute name [ bad ] was found.</td></tr>
14+
<tr><td>4</td><td>{{path}}</td><td>9</td><td>The value of attribute [ bad ] must be in double quotes.</td></tr>
15+
<tr><td>5</td><td>{{path}}</td><td>9</td><td>The value of attribute [ bad ] must be in double quotes.</td></tr>
16+
<tr><td>6</td><td>{{path}}</td><td>9</td><td>Duplicate of attribute name [ bad ] was found.</td></tr>
17+
<tr><td>7</td><td>{{path}}</td><td>10</td><td>Tag must be paired, no start tag: [ </input> ]</td></tr>
18+
<tr><td>8</td><td>{{path}}</td><td>11</td><td>Special characters must be escaped : [ < ].</td></tr>
19+
<tr><td>9</td><td>{{path}}</td><td>11</td><td>Special characters must be escaped : [ > ].</td></tr>
20+
<tr><td>10</td><td>{{path}}</td><td>13</td><td>Tag must be paired, no start tag: [ </div> ]</td></tr>
21+
<tr><td>11</td><td>{{path}}</td><td>14</td><td>Tag must be paired, no start tag: [ </div> ]</td></tr>
22+
<tr><td>12</td><td>{{path}}</td><td>15</td><td>Tag must be paired, no start tag: [ </hello> ]</td></tr>
23+
<tr><td>13</td><td>{{path}}</td><td>16</td><td>Tag must be paired, no start tag: [ </test> ]</td></tr>
24+
<tr><td>14</td><td>{{path}}</td><td>17</td><td>Tag must be paired, no start tag: [ </div> ]</td></tr>
25+
<tr><td>15</td><td>{{path}}</td><td>21</td><td>The value of attribute [ class ] must be in double quotes.</td></tr>
26+
<tr><td>16</td><td>{{path}}</td><td>21</td><td>The value of attribute [ what ] must be in double quotes.</td></tr>
27+
<tr><td>17</td><td>{{path}}</td><td>21</td><td>The value of attribute [ something ] must be in double quotes.</td></tr>
28+
<tr><td>18</td><td>{{path}}</td><td>25</td><td>Tag must be paired, no start tag: [ </div> ]</td></tr>
29+
<tr><td>19</td><td>{{path}}</td><td>26</td><td>Tag must be paired, no start tag: [ </bad> ]</td></tr>
30+
<tr><td>20</td><td>{{path}}</td><td>27</td><td>Tag must be paired, no start tag: [ </bad> ]</td></tr></table>
31+
<p><footer><small>Generated by <a href="https://htmlhint.com" target="_blank" rel="noopener">HTMLHint</a></small></footer></p>
32+
</main>
33+
</body></html>

0 commit comments

Comments
 (0)