w3c-html-validator 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/bin/cli.js +5 -5
- package/dist/w3c-html-validator.d.ts +4 -4
- package/dist/w3c-html-validator.js +8 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,6 +53,7 @@ Command-line flags:
|
|
|
53
53
|
| ----------------- | ------------------------------------------------------------------- | ---------- |
|
|
54
54
|
| `--continue` | Report messages but do not throw an error if validation failed. | N/A |
|
|
55
55
|
| `--delay` | Debounce pause in milliseconds between each file validation. | **number** |
|
|
56
|
+
| `--dry-run` | Bypass validation (for usage while building your CI). | N/A |
|
|
56
57
|
| `--exclude` | Comma separated list of strings to match in paths to skip. | **string** |
|
|
57
58
|
| `--ignore` | Skip validation messages containing a string or matching a regex. | **string** |
|
|
58
59
|
| `--ignore-config` | File containing strings and regexes of validation messages to skip. | **string** |
|
|
@@ -136,12 +137,12 @@ $ node examples.js
|
|
|
136
137
|
| Name (key) | Type | Default | Description |
|
|
137
138
|
| :--------------- | :---------------------- | :------------------------------- | :------------------------------------------------------ |
|
|
138
139
|
| `checkUrl` | **string** | `'https://validator.w3.org/nu/'` | W3C validation API endpoint. |
|
|
140
|
+
| `dryRun` | **boolean** | `false` | Bypass validation (for usage while building your CI). |
|
|
139
141
|
| `filename` | **string** | `null` | HTML file to validate. |
|
|
140
142
|
| `html` | **string** | `null` | HTML string to validate. |
|
|
141
143
|
| `ignoreLevel` | `'info'` or `'warning'` | `null` | Skip unwanted messages.* |
|
|
142
144
|
| `ignoreMessages` | **array** | `[]` | Skip messages containing a string or matching a regex.* |
|
|
143
145
|
| `output` | `'json'` or `'html'` | `'json'` | Get results as an array or as a web page. |
|
|
144
|
-
| `skip` | **boolean** | `false` | bypass validation (for usage while building your CI). |
|
|
145
146
|
| `website` | **string** | `null` | URL of website to validate. |
|
|
146
147
|
|
|
147
148
|
*The `ignoreMessages` and `ignoreLevel` options only work for `'json'` output.
|
|
@@ -172,7 +173,7 @@ type ValidatorResults = {
|
|
|
172
173
|
status: number,
|
|
173
174
|
messages: ValidatorResultsMessage[] | null, //for 'json' output
|
|
174
175
|
display: string | null, //for 'html' output
|
|
175
|
-
|
|
176
|
+
dryRun: boolean,
|
|
176
177
|
};
|
|
177
178
|
```
|
|
178
179
|
|
package/bin/cli.js
CHANGED
|
@@ -29,14 +29,14 @@ import fs from 'fs';
|
|
|
29
29
|
import slash from 'slash';
|
|
30
30
|
|
|
31
31
|
// Parameters and flags
|
|
32
|
-
const validFlags = ['continue', 'delay', 'exclude', 'ignore', 'ignore-config', 'note', 'quiet', 'trim'];
|
|
32
|
+
const validFlags = ['continue', 'delay', 'dry-run', 'exclude', 'ignore', 'ignore-config', 'note', 'quiet', 'trim'];
|
|
33
33
|
const cli = cliArgvUtil.parse(validFlags);
|
|
34
34
|
const files = cli.params;
|
|
35
35
|
const ignore = cli.flagMap.ignore ?? null;
|
|
36
36
|
const ignoreConfig = cli.flagMap.ignoreConfig ?? null;
|
|
37
37
|
const delay = Number(cli.flagMap.delay) || 500; //default half second debounce pause
|
|
38
38
|
const trim = Number(cli.flagMap.trim) || null;
|
|
39
|
-
const
|
|
39
|
+
const dryRunMode = cli.flagOn.dryRun || process.env.w3cHtmlValidator === 'dry-run'; //bash: export w3cHtmlValidator=dry-run
|
|
40
40
|
|
|
41
41
|
// Validator
|
|
42
42
|
const globOptions = { ignore: '**/node_modules/**/*' };
|
|
@@ -55,8 +55,8 @@ const error =
|
|
|
55
55
|
null;
|
|
56
56
|
if (error)
|
|
57
57
|
throw Error('[w3c-html-validator] ' + error);
|
|
58
|
-
if (
|
|
59
|
-
w3cHtmlValidator.
|
|
58
|
+
if (dryRunMode)
|
|
59
|
+
w3cHtmlValidator.dryRunNotice();
|
|
60
60
|
if (filenames.length > 1 && !cli.flagOn.quiet)
|
|
61
61
|
w3cHtmlValidator.summary(filenames.length);
|
|
62
62
|
const reporterOptions = {
|
|
@@ -74,7 +74,7 @@ const getIgnoreMessages = () => {
|
|
|
74
74
|
const isRegex = /^\/.*\/$/; //starts and ends with a slash indicating it's a regex
|
|
75
75
|
return rawLines.map(line => isRegex.test(line) ? new RegExp(line.slice(1, -1)) : line);
|
|
76
76
|
};
|
|
77
|
-
const baseOptions = { ignoreMessages: getIgnoreMessages(),
|
|
77
|
+
const baseOptions = { ignoreMessages: getIgnoreMessages(), dryRun: dryRunMode };
|
|
78
78
|
const options = (filename) => ({ filename: filename, ...baseOptions });
|
|
79
79
|
const handleResults = (results) => w3cHtmlValidator.reporter(results, reporterOptions);
|
|
80
80
|
const getReport = (filename) => w3cHtmlValidator.validate(options(filename)).then(handleResults);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! w3c-html-validator v1.8.
|
|
1
|
+
//! w3c-html-validator v1.8.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
|
|
2
2
|
|
|
3
3
|
export type ValidatorSettings = {
|
|
4
4
|
html: string;
|
|
@@ -8,7 +8,7 @@ export type ValidatorSettings = {
|
|
|
8
8
|
ignoreLevel: 'info' | 'warning';
|
|
9
9
|
ignoreMessages: (string | RegExp)[];
|
|
10
10
|
output: ValidatorResultsOutput;
|
|
11
|
-
|
|
11
|
+
dryRun: boolean;
|
|
12
12
|
};
|
|
13
13
|
export type ValidatorResultsMessage = {
|
|
14
14
|
type: 'info' | 'error' | 'non-document-error' | 'network-error';
|
|
@@ -34,7 +34,7 @@ export type ValidatorResults = {
|
|
|
34
34
|
status: number;
|
|
35
35
|
messages: ValidatorResultsMessage[] | null;
|
|
36
36
|
display: string | null;
|
|
37
|
-
|
|
37
|
+
dryRun: boolean;
|
|
38
38
|
};
|
|
39
39
|
export type ValidatorResultsOutput = ValidatorResults['output'];
|
|
40
40
|
export type ReporterSettings = {
|
|
@@ -46,7 +46,7 @@ export type ReporterSettings = {
|
|
|
46
46
|
declare const w3cHtmlValidator: {
|
|
47
47
|
version: string;
|
|
48
48
|
validate(options: Partial<ValidatorSettings>): Promise<ValidatorResults>;
|
|
49
|
-
|
|
49
|
+
dryRunNotice(): void;
|
|
50
50
|
summary(numFiles: number): void;
|
|
51
51
|
reporter(results: ValidatorResults, options?: Partial<ReporterSettings>): ValidatorResults;
|
|
52
52
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! w3c-html-validator v1.8.
|
|
1
|
+
//! w3c-html-validator v1.8.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
|
|
2
2
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import fs from 'fs';
|
|
@@ -6,14 +6,14 @@ import log from 'fancy-log';
|
|
|
6
6
|
import request from 'superagent';
|
|
7
7
|
import slash from 'slash';
|
|
8
8
|
const w3cHtmlValidator = {
|
|
9
|
-
version: '1.8.
|
|
9
|
+
version: '1.8.1',
|
|
10
10
|
validate(options) {
|
|
11
11
|
const defaults = {
|
|
12
12
|
checkUrl: 'https://validator.w3.org/nu/',
|
|
13
|
+
dryRun: false,
|
|
13
14
|
ignoreLevel: null,
|
|
14
15
|
ignoreMessages: [],
|
|
15
16
|
output: 'json',
|
|
16
|
-
skip: false,
|
|
17
17
|
};
|
|
18
18
|
const settings = { ...defaults, ...options };
|
|
19
19
|
if (!settings.html && !settings.filename && !settings.website)
|
|
@@ -61,7 +61,7 @@ const w3cHtmlValidator = {
|
|
|
61
61
|
status: response.statusCode || -1,
|
|
62
62
|
messages: json ? response.body.messages : null,
|
|
63
63
|
display: json ? null : response.text,
|
|
64
|
-
|
|
64
|
+
dryRun: settings.dryRun,
|
|
65
65
|
});
|
|
66
66
|
const handleError = (reason) => {
|
|
67
67
|
const errRes = reason.response ?? {};
|
|
@@ -73,14 +73,14 @@ const w3cHtmlValidator = {
|
|
|
73
73
|
const pseudoResponse = {
|
|
74
74
|
statusCode: 200,
|
|
75
75
|
body: { messages: [] },
|
|
76
|
-
text: 'Validation
|
|
76
|
+
text: 'Validation bypassed.',
|
|
77
77
|
};
|
|
78
78
|
const pseudoRequest = () => new Promise(resolve => resolve(pseudoResponse));
|
|
79
|
-
const validation = settings.
|
|
79
|
+
const validation = settings.dryRun ? pseudoRequest() : w3cRequest;
|
|
80
80
|
return validation.then(filterMessages).then(toValidatorResults).catch(handleError);
|
|
81
81
|
},
|
|
82
|
-
|
|
83
|
-
log(chalk.gray('w3c-html-validator'), chalk.yellowBright('
|
|
82
|
+
dryRunNotice() {
|
|
83
|
+
log(chalk.gray('w3c-html-validator'), chalk.yellowBright('dry run mode:'), chalk.whiteBright('validation being bypassed'));
|
|
84
84
|
},
|
|
85
85
|
summary(numFiles) {
|
|
86
86
|
log(chalk.gray('w3c-html-validator'), chalk.magenta('files: ' + numFiles));
|