w3c-html-validator 1.7.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 +4 -1
- package/bin/cli.js +6 -2
- package/dist/w3c-html-validator.d.ts +4 -1
- package/dist/w3c-html-validator.js +15 -3
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ _Check the markup validity of HTML files using the W3C validator_
|
|
|
5
5
|
|
|
6
6
|
[](https://github.com/center-key/w3c-html-validator/blob/main/LICENSE.txt)
|
|
7
7
|
[](https://www.npmjs.com/package/w3c-html-validator)
|
|
8
|
-
[](https://github.com/center-key/w3c-html-validator/actions/workflows/run-spec-on-push.yaml)
|
|
9
9
|
|
|
10
10
|
**w3c-html-validator** takes HTML files and returns detailed validation results.
|
|
11
11
|
The reporter produces formatted output indented for use in build scripts and test suites.
|
|
@@ -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,6 +137,7 @@ $ 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.* |
|
|
@@ -171,6 +173,7 @@ type ValidatorResults = {
|
|
|
171
173
|
status: number,
|
|
172
174
|
messages: ValidatorResultsMessage[] | null, //for 'json' output
|
|
173
175
|
display: string | null, //for 'html' output
|
|
176
|
+
dryRun: boolean,
|
|
174
177
|
};
|
|
175
178
|
```
|
|
176
179
|
|
package/bin/cli.js
CHANGED
|
@@ -29,13 +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 dryRunMode = cli.flagOn.dryRun || process.env.w3cHtmlValidator === 'dry-run'; //bash: export w3cHtmlValidator=dry-run
|
|
39
40
|
|
|
40
41
|
// Validator
|
|
41
42
|
const globOptions = { ignore: '**/node_modules/**/*' };
|
|
@@ -54,6 +55,8 @@ const error =
|
|
|
54
55
|
null;
|
|
55
56
|
if (error)
|
|
56
57
|
throw Error('[w3c-html-validator] ' + error);
|
|
58
|
+
if (dryRunMode)
|
|
59
|
+
w3cHtmlValidator.dryRunNotice();
|
|
57
60
|
if (filenames.length > 1 && !cli.flagOn.quiet)
|
|
58
61
|
w3cHtmlValidator.summary(filenames.length);
|
|
59
62
|
const reporterOptions = {
|
|
@@ -71,8 +74,9 @@ const getIgnoreMessages = () => {
|
|
|
71
74
|
const isRegex = /^\/.*\/$/; //starts and ends with a slash indicating it's a regex
|
|
72
75
|
return rawLines.map(line => isRegex.test(line) ? new RegExp(line.slice(1, -1)) : line);
|
|
73
76
|
};
|
|
77
|
+
const baseOptions = { ignoreMessages: getIgnoreMessages(), dryRun: dryRunMode };
|
|
78
|
+
const options = (filename) => ({ filename: filename, ...baseOptions });
|
|
74
79
|
const handleResults = (results) => w3cHtmlValidator.reporter(results, reporterOptions);
|
|
75
|
-
const options = (filename) => ({ filename: filename, ignoreMessages: getIgnoreMessages() });
|
|
76
80
|
const getReport = (filename) => w3cHtmlValidator.validate(options(filename)).then(handleResults);
|
|
77
81
|
const processFile = (filename, i) => globalThis.setTimeout(() => getReport(filename), i * delay);
|
|
78
82
|
filenames.forEach(processFile);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! w3c-html-validator v1.
|
|
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,6 +8,7 @@ export type ValidatorSettings = {
|
|
|
8
8
|
ignoreLevel: 'info' | 'warning';
|
|
9
9
|
ignoreMessages: (string | RegExp)[];
|
|
10
10
|
output: ValidatorResultsOutput;
|
|
11
|
+
dryRun: boolean;
|
|
11
12
|
};
|
|
12
13
|
export type ValidatorResultsMessage = {
|
|
13
14
|
type: 'info' | 'error' | 'non-document-error' | 'network-error';
|
|
@@ -33,6 +34,7 @@ export type ValidatorResults = {
|
|
|
33
34
|
status: number;
|
|
34
35
|
messages: ValidatorResultsMessage[] | null;
|
|
35
36
|
display: string | null;
|
|
37
|
+
dryRun: boolean;
|
|
36
38
|
};
|
|
37
39
|
export type ValidatorResultsOutput = ValidatorResults['output'];
|
|
38
40
|
export type ReporterSettings = {
|
|
@@ -44,6 +46,7 @@ export type ReporterSettings = {
|
|
|
44
46
|
declare const w3cHtmlValidator: {
|
|
45
47
|
version: string;
|
|
46
48
|
validate(options: Partial<ValidatorSettings>): Promise<ValidatorResults>;
|
|
49
|
+
dryRunNotice(): void;
|
|
47
50
|
summary(numFiles: number): void;
|
|
48
51
|
reporter(results: ValidatorResults, options?: Partial<ReporterSettings>): ValidatorResults;
|
|
49
52
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! w3c-html-validator v1.
|
|
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,10 +6,11 @@ import log from 'fancy-log';
|
|
|
6
6
|
import request from 'superagent';
|
|
7
7
|
import slash from 'slash';
|
|
8
8
|
const w3cHtmlValidator = {
|
|
9
|
-
version: '1.
|
|
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',
|
|
@@ -60,6 +61,7 @@ const w3cHtmlValidator = {
|
|
|
60
61
|
status: response.statusCode || -1,
|
|
61
62
|
messages: json ? response.body.messages : null,
|
|
62
63
|
display: json ? null : response.text,
|
|
64
|
+
dryRun: settings.dryRun,
|
|
63
65
|
});
|
|
64
66
|
const handleError = (reason) => {
|
|
65
67
|
const errRes = reason.response ?? {};
|
|
@@ -68,7 +70,17 @@ const w3cHtmlValidator = {
|
|
|
68
70
|
errRes.body = { messages: [{ type: 'network-error', message: message.join(' ') }] };
|
|
69
71
|
return toValidatorResults(errRes);
|
|
70
72
|
};
|
|
71
|
-
|
|
73
|
+
const pseudoResponse = {
|
|
74
|
+
statusCode: 200,
|
|
75
|
+
body: { messages: [] },
|
|
76
|
+
text: 'Validation bypassed.',
|
|
77
|
+
};
|
|
78
|
+
const pseudoRequest = () => new Promise(resolve => resolve(pseudoResponse));
|
|
79
|
+
const validation = settings.dryRun ? pseudoRequest() : w3cRequest;
|
|
80
|
+
return validation.then(filterMessages).then(toValidatorResults).catch(handleError);
|
|
81
|
+
},
|
|
82
|
+
dryRunNotice() {
|
|
83
|
+
log(chalk.gray('w3c-html-validator'), chalk.yellowBright('dry run mode:'), chalk.whiteBright('validation being bypassed'));
|
|
72
84
|
},
|
|
73
85
|
summary(numFiles) {
|
|
74
86
|
log(chalk.gray('w3c-html-validator'), chalk.magenta('files: ' + numFiles));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w3c-html-validator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "Check the markup validity of HTML files using the W3C validator",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -81,22 +81,22 @@
|
|
|
81
81
|
"fancy-log": "~2.0",
|
|
82
82
|
"glob": "~10.3",
|
|
83
83
|
"slash": "~5.1",
|
|
84
|
-
"superagent": "~
|
|
84
|
+
"superagent": "~9.0"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@types/fancy-log": "~2.0",
|
|
88
|
-
"@types/node": "~20.
|
|
88
|
+
"@types/node": "~20.12",
|
|
89
89
|
"@types/superagent": "~8.1",
|
|
90
|
-
"@typescript-eslint/eslint-plugin": "~7.
|
|
91
|
-
"@typescript-eslint/parser": "~7.
|
|
90
|
+
"@typescript-eslint/eslint-plugin": "~7.7",
|
|
91
|
+
"@typescript-eslint/parser": "~7.7",
|
|
92
92
|
"add-dist-header": "~1.4",
|
|
93
93
|
"assert-deep-strict-equal": "~1.2",
|
|
94
94
|
"copy-file-util": "~1.2",
|
|
95
95
|
"copy-folder-util": "~1.1",
|
|
96
|
-
"eslint": "
|
|
96
|
+
"eslint": "8.57.0",
|
|
97
97
|
"jshint": "~2.13",
|
|
98
98
|
"merge-stream": "~2.0",
|
|
99
|
-
"mocha": "~10.
|
|
99
|
+
"mocha": "~10.4",
|
|
100
100
|
"rimraf": "~5.0",
|
|
101
101
|
"run-scripts-util": "~1.2",
|
|
102
102
|
"typescript": "~5.4"
|