Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit aca9388

Browse files
committed
Add throwErrors option
1 parent b95d5d4 commit aca9388

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Error: HTML validation error(s) found
7575
```
7676

7777
## 4) Options
78+
### analyzer()
7879
| Option | Type | Description | Default |
7980
| ----------------- | ---------- | ----------------------------------------------------------------------------------------------------------- | ------- |
8081
| **proxy** | `string` | HTTP address of the proxy server if you are running behind a firewall, e.g. `'http://proxy:8080'` | `null` |
@@ -95,6 +96,11 @@ const task = {
9596
};
9697
```
9798

99+
### reporter()
100+
| Option | Type | Description | Default |
101+
| --------------- | --------- | ------------------------------------------------------------------------------------- | ------- |
102+
| **throwErrors** | `boolean` | Throw an [error](https://github.com/gulpjs/plugin-error) on HTTP validation failure. | `false` |
103+
98104
## 5) Deprecated CommonJS (gulp-w3c-html-validator v2.0)
99105
If your build system is using `require()` statements for CommonJS modules, install the older v2.0:
100106
```shell

html-validator.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ const htmlValidator = {
100100
return through2.obj(transform);
101101
},
102102

103-
reporter() {
103+
reporter(options) {
104+
const defaults = { throwErrors: false };
105+
const settings = { ...defaults, ...options };
104106
const transform = (file, encoding, done) => {
105107
done(null, file);
106-
if (file.validationResults && !file.validationResults.success)
108+
if (settings.throwErrors && file.validationResults && !file.validationResults.success)
107109
throw new PluginError(pluginName, 'HTML validation failed');
108110
};
109111
return through2.obj(transform);

spec/mocha.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('The htmlValidator.reporter() function', () => {
143143
success: false,
144144
messages: ['HTML is valid']
145145
};
146-
const stream = htmlValidator.reporter();
146+
const stream = htmlValidator.reporter({ throwErrors: true });
147147
const writeToStream = () => stream.write(mockFile);
148148
writeToStream.should.throw(/HTML validation failed/);
149149
stream.end();

0 commit comments

Comments
 (0)