w3c-html-validator 1.8.0 → 1.8.2
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 -3
- package/bin/cli.js +6 -6
- package/dist/w3c-html-validator.d.ts +5 -5
- package/dist/w3c-html-validator.js +18 -18
- package/package.json +11 -30
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
|
|
|
@@ -206,7 +207,7 @@ describe('Home page', () => {
|
|
|
206
207
|
- 🪺 [recursive-exec](https://github.com/center-key/recursive-exec): _Run a command on each file in a folder and its subfolders_
|
|
207
208
|
- 🔍 [replacer-util](https://github.com/center-key/replacer-util): _Find and replace strings or template outputs in text files_
|
|
208
209
|
- 🔢 [rev-web-assets](https://github.com/center-key/rev-web-assets): _Revision web asset filenames with cache busting content hash fingerprints_
|
|
209
|
-
- 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util): _Organize npm package.json scripts into
|
|
210
|
+
- 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util): _Organize npm package.json scripts into groups of easy to manage commands_
|
|
210
211
|
- 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator): _Check the markup validity of HTML files using the W3C validator_
|
|
211
212
|
|
|
212
213
|
Feel free to submit questions at:<br>
|
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/**/*' };
|
|
@@ -54,9 +54,9 @@ const error =
|
|
|
54
54
|
cli.flagOn.trim && !trim ? 'Value of "trim" must be a positive whole number.' :
|
|
55
55
|
null;
|
|
56
56
|
if (error)
|
|
57
|
-
throw Error('[w3c-html-validator] ' + error);
|
|
58
|
-
if (
|
|
59
|
-
w3cHtmlValidator.
|
|
57
|
+
throw new Error('[w3c-html-validator] ' + error);
|
|
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.2 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
|
|
2
2
|
|
|
3
3
|
export type ValidatorSettings = {
|
|
4
4
|
html: string;
|
|
@@ -8,13 +8,13 @@ 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';
|
|
15
15
|
subType?: 'warning' | 'fatal' | 'io' | 'schema' | 'internal';
|
|
16
16
|
message: string;
|
|
17
|
-
extract
|
|
17
|
+
extract?: string;
|
|
18
18
|
lastLine: number;
|
|
19
19
|
firstColumn: number;
|
|
20
20
|
lastColumn: number;
|
|
@@ -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.2 ~~ 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,22 +6,22 @@ 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.2',
|
|
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)
|
|
20
|
-
throw Error('[w3c-html-validator] Must specify the "html", "filename", or "website" option.');
|
|
20
|
+
throw new Error('[w3c-html-validator] Must specify the "html", "filename", or "website" option.');
|
|
21
21
|
if (![null, 'info', 'warning'].includes(settings.ignoreLevel))
|
|
22
|
-
throw Error(
|
|
22
|
+
throw new Error(`[w3c-html-validator] Invalid ignoreLevel option: ${settings.ignoreLevel}`);
|
|
23
23
|
if (settings.output !== 'json' && settings.output !== 'html')
|
|
24
|
-
throw Error('[w3c-html-validator] Option "output" must be "json" or "html".');
|
|
24
|
+
throw new Error('[w3c-html-validator] Option "output" must be "json" or "html".');
|
|
25
25
|
const filename = settings.filename ? slash(settings.filename) : null;
|
|
26
26
|
const mode = settings.html ? 'html' : filename ? 'filename' : 'website';
|
|
27
27
|
const readFile = (filename) => fs.readFileSync(filename, 'utf-8').replace(/\r/g, '');
|
|
@@ -37,7 +37,7 @@ const w3cHtmlValidator = {
|
|
|
37
37
|
const json = settings.output === 'json';
|
|
38
38
|
const success = '<p class="success">';
|
|
39
39
|
const titleLookup = {
|
|
40
|
-
html:
|
|
40
|
+
html: `HTML String (characters: ${inputHtml?.length})`,
|
|
41
41
|
filename: filename,
|
|
42
42
|
website: settings.website,
|
|
43
43
|
};
|
|
@@ -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,17 +73,17 @@ 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
|
-
log(chalk.gray('w3c-html-validator'), chalk.magenta('files: ' + numFiles));
|
|
86
|
+
log(chalk.gray('w3c-html-validator'), chalk.magenta('files: ' + String(numFiles)));
|
|
87
87
|
},
|
|
88
88
|
reporter(results, options) {
|
|
89
89
|
const defaults = {
|
|
@@ -94,11 +94,11 @@ const w3cHtmlValidator = {
|
|
|
94
94
|
};
|
|
95
95
|
const settings = { ...defaults, ...options };
|
|
96
96
|
if (typeof results?.validates !== 'boolean')
|
|
97
|
-
throw Error('[w3c-html-validator] Invalid results for reporter(): ' + String(results));
|
|
97
|
+
throw new Error('[w3c-html-validator] Invalid results for reporter(): ' + String(results));
|
|
98
98
|
const messages = results.messages ?? [];
|
|
99
99
|
const title = settings.title ?? results.title;
|
|
100
100
|
const status = results.validates ? chalk.green.bold('✔ pass') : chalk.red.bold('✘ fail');
|
|
101
|
-
const count = results.validates ? '' :
|
|
101
|
+
const count = results.validates ? '' : `(messages: ${messages.length})`;
|
|
102
102
|
if (!results.validates || !settings.quiet)
|
|
103
103
|
log(chalk.gray('w3c-html-validator'), status, chalk.blue.bold(title), chalk.white(count));
|
|
104
104
|
const typeColorMap = {
|
|
@@ -107,7 +107,7 @@ const w3cHtmlValidator = {
|
|
|
107
107
|
info: chalk.white.bold,
|
|
108
108
|
};
|
|
109
109
|
const logMessage = (message) => {
|
|
110
|
-
const type =
|
|
110
|
+
const type = message.subType ?? message.type;
|
|
111
111
|
const typeColor = typeColorMap[type] ?? chalk.redBright.bold;
|
|
112
112
|
const location = `line ${message.lastLine}, column ${message.firstColumn}:`;
|
|
113
113
|
const lineText = message.extract?.replace(/\n/g, '\\n');
|
|
@@ -119,11 +119,11 @@ const w3cHtmlValidator = {
|
|
|
119
119
|
messages.forEach(logMessage);
|
|
120
120
|
const failDetails = () => {
|
|
121
121
|
const toString = (message) => `${message.subType ?? message.type} line ${message.lastLine} column ${message.firstColumn}`;
|
|
122
|
-
const fileDetails = () => results.filename
|
|
122
|
+
const fileDetails = () => `${results.filename} -- ${results.messages.map(toString).join(', ')}`;
|
|
123
123
|
return !results.filename ? results.messages[0].message : fileDetails();
|
|
124
124
|
};
|
|
125
125
|
if (!settings.continueOnFail && !results.validates)
|
|
126
|
-
throw Error('[w3c-html-validator] Failed: ' + failDetails());
|
|
126
|
+
throw new Error('[w3c-html-validator] Failed: ' + failDetails());
|
|
127
127
|
return results;
|
|
128
128
|
},
|
|
129
129
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w3c-html-validator",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"description": "Check the markup validity of HTML files using the W3C validator",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -38,32 +38,13 @@
|
|
|
38
38
|
"node": true,
|
|
39
39
|
"mocha": true
|
|
40
40
|
},
|
|
41
|
-
"eslintConfig": {
|
|
42
|
-
"ignorePatterns": [
|
|
43
|
-
"build",
|
|
44
|
-
"dist",
|
|
45
|
-
"node_modules"
|
|
46
|
-
],
|
|
47
|
-
"root": true,
|
|
48
|
-
"parser": "@typescript-eslint/parser",
|
|
49
|
-
"plugins": [
|
|
50
|
-
"@typescript-eslint"
|
|
51
|
-
],
|
|
52
|
-
"extends": [
|
|
53
|
-
"eslint:recommended",
|
|
54
|
-
"plugin:@typescript-eslint/recommended"
|
|
55
|
-
],
|
|
56
|
-
"rules": {
|
|
57
|
-
"@typescript-eslint/no-non-null-assertion": "off"
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
41
|
"runScriptsConfig": {
|
|
61
42
|
"clean": [
|
|
62
43
|
"rimraf build dist"
|
|
63
44
|
],
|
|
64
45
|
"lint": [
|
|
65
46
|
"jshint . --exclude-path .gitignore",
|
|
66
|
-
"eslint --max-warnings 0
|
|
47
|
+
"eslint --max-warnings 0"
|
|
67
48
|
],
|
|
68
49
|
"build": [
|
|
69
50
|
"tsc",
|
|
@@ -79,26 +60,26 @@
|
|
|
79
60
|
"chalk": "~5.3",
|
|
80
61
|
"cli-argv-util": "~1.2",
|
|
81
62
|
"fancy-log": "~2.0",
|
|
82
|
-
"glob": "~
|
|
63
|
+
"glob": "~11.0",
|
|
83
64
|
"slash": "~5.1",
|
|
84
65
|
"superagent": "~9.0"
|
|
85
66
|
},
|
|
86
67
|
"devDependencies": {
|
|
68
|
+
"@eslint/js": "~9.9",
|
|
87
69
|
"@types/fancy-log": "~2.0",
|
|
88
|
-
"@types/node": "~
|
|
70
|
+
"@types/node": "~22.2",
|
|
89
71
|
"@types/superagent": "~8.1",
|
|
90
|
-
"@typescript-eslint/eslint-plugin": "~7.7",
|
|
91
|
-
"@typescript-eslint/parser": "~7.7",
|
|
92
72
|
"add-dist-header": "~1.4",
|
|
93
73
|
"assert-deep-strict-equal": "~1.2",
|
|
94
74
|
"copy-file-util": "~1.2",
|
|
95
75
|
"copy-folder-util": "~1.1",
|
|
96
|
-
"eslint": "
|
|
76
|
+
"eslint": "~9.9",
|
|
97
77
|
"jshint": "~2.13",
|
|
98
78
|
"merge-stream": "~2.0",
|
|
99
|
-
"mocha": "~10.
|
|
100
|
-
"rimraf": "~
|
|
101
|
-
"run-scripts-util": "~1.
|
|
102
|
-
"typescript": "~5.
|
|
79
|
+
"mocha": "~10.7",
|
|
80
|
+
"rimraf": "~6.0",
|
|
81
|
+
"run-scripts-util": "~1.3",
|
|
82
|
+
"typescript": "~5.5",
|
|
83
|
+
"typescript-eslint": "~8.0"
|
|
103
84
|
}
|
|
104
85
|
}
|