Skip to content

Commit b033ffb

Browse files
committed
feat: Allow generating an empty report with all validated files
Introduce a new boolean option "includeUnreported" to enable such report. Recognize a new "input" parameter in the sub-task object with all input files to include in the rport.
1 parent e77c181 commit b033ffb

File tree

8 files changed

+147
-7
lines changed

8 files changed

+147
-7
lines changed

Gruntfile.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ module.exports = function (grunt) {
4848
},
4949
src: 'tests/expected/report.json',
5050
dest: 'tests/actual/'
51+
},
52+
includeUnreported: {
53+
options: {
54+
includeUnreported: true
55+
},
56+
input: 'tests/actual/deprecated.*',
57+
src: 'tests/expected/missing.json',
58+
dest: 'tests/actual/unreported.html'
5159
}
5260
},
5361

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 Ferdinand Prantl
3+
Copyright (c) 2017-2018 Ferdinand Prantl
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,18 @@ Type: `Boolean`
6262
Default: `false`
6363

6464
If the `src` property does not point to any files, or if it is missing,
65-
the task will make the Grunt run fail. If you set the `ignoreMissing`
65+
the task will make the Grunt run fail. If you set the `ignoreMissing`
6666
option to `true`, Grunt will continue executing other tasks.
6767

68+
#### includeUnreported
69+
Type: `Boolean`
70+
Default: `false`
71+
72+
If the `src` property does not point to any files, or if it is missing,
73+
the task will assume, that no messages existed for the input files, which
74+
which were above the configured severity. It will create the report
75+
nevertheless and include all input files there.
76+
6877
#### targetExtension
6978
Type: `String`
7079
Default: ".html:
@@ -73,8 +82,8 @@ If the `dest` property specified only the target directory, the converted report
7382

7483
### Task Data
7584

76-
The configuration consists of `src` and `dest` property pairs. The `src`
77-
property has to point to an existing source path. The `dest` property has
85+
The configuration consists of `src` and `dest` property pairs. The `src`
86+
property has to point to an existing source path. The `dest` property has
7887
to point to the path, where the converted report should be written.
7988

8089
If you do not end the `dest` path by the path separator (slash, for example), the `dest` path will be considered as if it includes the converted report file name too.
@@ -84,6 +93,21 @@ converted report will be created using the source report name with the HTML expe
8493

8594
If you specify more source files or directories, or use wildcards, the target path should be a directory - ended by the path separator (slash, for example).
8695

96+
If you set `includeUnreported` to true and you expect all input files reported with zero messages, include the `input` property. Set it to the files, which were input of the `htmllint` task. For example:
97+
98+
```js
99+
'html-html-report-converter': {
100+
options: {
101+
includeUnreported: true
102+
},
103+
all: {
104+
input: 'snapshots/*.html',
105+
src: 'results/report.json',
106+
dest: 'results/report.html'
107+
}
108+
}
109+
```
110+
87111
#### src
88112
Type: `String` or `Array`
89113

@@ -94,6 +118,11 @@ Type: `String`
94118

95119
Path to the file, which will be the HTML report written to. Or only the path to the directory, where it should be written, if the source report name with the HTML expension shoudl be used.
96120

121+
#### input
122+
Type: `String|Array|Object`
123+
124+
Files, which were input of the `htmllint` task. The format is the same as for the `src` parameter - the Grunt source file specification.
125+
97126
### Loading
98127

99128
Load the plugin in `Gruntfile.js`:
@@ -162,13 +191,14 @@ your code using Grunt.
162191

163192
## Release History
164193

194+
* 2018-01-27 v0.1.0 Allow generating an empty report with all validated files
165195
* 2017-11-25 v0.0.3 Fix appending the HTML extension to the target report file
166196
* 2017-11-25 v0.0.2 Upgrade the reporter dependency to support Node.js < 7
167197
* 2017-11-25 v0.0.1 Initial release
168198

169199
## License
170200

171-
Copyright (c) 2017 Ferdinand Prantl
201+
Copyright (c) 2017-2018 Ferdinand Prantl
172202

173203
Licensed under the MIT license.
174204

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"devDependencies": {
3939
"grunt": "^1.0.1",
4040
"grunt-standard": "^3.1.0",
41-
"semantic-release": "^11.0.2"
41+
"semantic-release": "^12.4.1"
4242
},
4343
"peerDependencies": {
4444
"grunt": ">=0.4.5"

tasks/grunt-html-html-report-converter.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ module.exports = function (grunt) {
1515
const options = this.options({
1616
targetExtension: '.html',
1717
ignoreMissing: false,
18+
includeUnreported: false,
1819
force: false
1920
})
2021
const targetExtension = options.targetExtension
2122
const ignoreMissing = options.ignoreMissing
23+
const includeUnreported = options.includeUnreported
2224
const force = options.force
2325
const warn = force ? grunt.log.warn : grunt.fail.warn
2426
var files = this.files
@@ -34,6 +36,7 @@ module.exports = function (grunt) {
3436
files = [
3537
{
3638
orig: {
39+
input: [],
3740
src: input,
3841
dest: output
3942
},
@@ -62,7 +65,25 @@ module.exports = function (grunt) {
6265
}
6366

6467
function convertFiles (file) {
65-
const src = file.src
68+
let src = file.src
69+
if (!src.length && includeUnreported) {
70+
const input = file.input
71+
if (input) {
72+
const report = grunt.file.expand(input)
73+
.map(function (file) {
74+
return {
75+
file: file
76+
}
77+
})
78+
if (report.length) {
79+
const output = file.orig.src[0]
80+
fs.writeFileSync(output, JSON.stringify(report), 'utf-8')
81+
src = [output]
82+
}
83+
} else {
84+
warn('No input files specificed for ' + chalk.cyan(file.orig.src) + '.')
85+
}
86+
}
6687
if (src.length) {
6788
src.forEach(convertFile.bind(null, file))
6889
} else {

tests/expected/missing.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"file":"tests/actual/deprecated.html"}]

tests/expected/unreported.html

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<html>
2+
<head>
3+
<title>HTML Validation Report</title>
4+
<style>
5+
body {font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, “Fira Sans”, “Droid Sans”, "Helvetica Neue", Arial, sans-serif;}
6+
pre {font-family: Monaco, Consolas, "Andale Mono", "Ubuntu Mono", monospace;}
7+
#summary {font-size: 38px; color:#555}
8+
.error-count {color:red;}
9+
.warning-count {color:orange}
10+
.notice-count {color:blue}
11+
.file-count {color:black;}
12+
13+
#files {}
14+
.file {padding:20px 5px; border-bottom:2px solid #ccc; font-size:22px;}
15+
.file .file-info {display:none;}
16+
.file a:link {border-bottom:1px dotted #888; text-decoration:none; color:black;}
17+
.file a:link:hover {border-bottom:none;}
18+
19+
.errors {padding:5px 15px; margin:5px 0; border-left:3px solid red; font-size:16px;}
20+
.warnings {padding:0 15px; border-left:3px solid orange; font-size:18px; color:#666;}
21+
.notices {padding:0 15px; border-left:3px solid blue; font-size:18px; color:#999;}
22+
23+
.error, .warning, .notice {padding:5px 0; border-bottom:1px solid #DDD;}
24+
.error .info, .warning .info, .notice .info {color:#666; font-size:15px;}
25+
.error .extract, .warning .extract, .notice .extract {color:#333; font-size:12px;}
26+
27+
.file:last-child, .error:last-child, .warning:last-child, .notice:last-child {border-bottom:none;}
28+
</style>
29+
<script type="text/javascript">
30+
document.addEventListener('click', function (event) {
31+
var target = event.target
32+
if (target.tagName === 'A') {
33+
var fileInfo = event.target.parentNode.querySelector('.file-info')
34+
if (fileInfo.offsetParent === null) {
35+
fileInfo.style.display = 'block'
36+
} else {
37+
fileInfo.style.display = 'none'
38+
}
39+
}
40+
})
41+
</script>
42+
</head>
43+
<body>
44+
<div id="summary">
45+
Summary: <span class="error-count">0</span> errors,
46+
<span class="warning-count">0</span> warnings
47+
and <span class="notice-count">1</span> notices
48+
in <span class="file-count">1</span> files
49+
</div>
50+
<div id="files">
51+
<div class="file">
52+
<a href="javascript:void(null)">tests/actual/deprecated.html</a>
53+
<b>
54+
(<span class="error-count">0</span> /
55+
<span class="warning-count">0</span> /
56+
<span class="notice-count">1</span>)
57+
</b>
58+
<div class="file-info">
59+
<div class="errors">
60+
</div>
61+
<div class="warnings">
62+
</div>
63+
<div class="notices">
64+
<div class="notice">
65+
66+
<div class="info">
67+
<u>at line , column </u>
68+
<pre class="extract"></pre>
69+
</div>
70+
</div>
71+
</div>
72+
</div>
73+
</div>
74+
</div>
75+
</body>
76+
</html>

tests/test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,9 @@ exports['htmllint-html-report-converter'] = {
2424

2525
extension: function (test) {
2626
compare(test, 'report.html', 'report.htm')
27+
},
28+
29+
unreported: function (test) {
30+
compare(test, 'unreported.html', 'unreported.html')
2731
}
2832
}

0 commit comments

Comments
 (0)