w3c-html-validator 2.2.0 → 2.2.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 +14 -14
- package/dist/w3c-html-validator.d.ts +4 -4
- package/dist/w3c-html-validator.js +30 -28
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -192,6 +192,7 @@ type ValidatorResults = {
|
|
|
192
192
|
mode: 'html' | 'filename' | 'website';
|
|
193
193
|
html: string | null,
|
|
194
194
|
filename: string | null,
|
|
195
|
+
fileCount: number | null,
|
|
195
196
|
website: string | null,
|
|
196
197
|
output: 'json' | 'html',
|
|
197
198
|
status: number,
|
|
@@ -203,7 +204,7 @@ type ValidatorResults = {
|
|
|
203
204
|
|
|
204
205
|
### 4. Mocha example
|
|
205
206
|
```javascript
|
|
206
|
-
import assert from 'assert';
|
|
207
|
+
import assert from 'node:assert';
|
|
207
208
|
import { w3cHtmlValidator } from 'w3c-html-validator';
|
|
208
209
|
|
|
209
210
|
describe('Home page', () => {
|
|
@@ -224,17 +225,16 @@ describe('Home page', () => {
|
|
|
224
225
|
<br>
|
|
225
226
|
|
|
226
227
|
---
|
|
227
|
-
**CLI Build Tools for package.json**
|
|
228
|
-
- 🎋 [add-dist-header](https://github.com/center-key/add-dist-header): _Prepend a one-line banner comment (with license notice) to distribution files_
|
|
229
|
-
- 📄 [copy-file-util](https://github.com/center-key/copy-file-util): _Copy or rename a file with optional package version number_
|
|
230
|
-
- 📂 [copy-folder-util](https://github.com/center-key/copy-folder-util): _Recursively copy files from one folder to another folder_
|
|
231
|
-
- 🪺 [recursive-exec](https://github.com/center-key/recursive-exec): _Run a command on each file in a folder and its subfolders_
|
|
232
|
-
- 🔍 [replacer-util](https://github.com/center-key/replacer-util): _Find and replace strings or template outputs in text files_
|
|
233
|
-
- 🔢 [rev-web-assets](https://github.com/center-key/rev-web-assets): _Revision web asset filenames with cache busting content hash fingerprints_
|
|
234
|
-
- 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util): _Organize npm package.json scripts into groups of easy to manage commands_
|
|
235
|
-
- 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator): _Check the markup validity of HTML files using the W3C validator_
|
|
236
|
-
|
|
237
|
-
Feel free to submit questions at:<br>
|
|
238
|
-
[github.com/center-key/w3c-html-validator/issues](https://github.com/center-key/w3c-html-validator/issues)
|
|
239
|
-
|
|
240
228
|
[MIT License](LICENSE.txt)
|
|
229
|
+
|
|
230
|
+
[🛡️ npm Security Aggregator](https://center-key.github.io/npm-security-aggregator/?package=w3c-html-validator)
|
|
231
|
+
|
|
232
|
+
See the `runScriptsConfig` section of [`package.json`](package.json) for a clean way to organize build tasks:
|
|
233
|
+
- 🎋 [`add-dist-header`](https://github.com/center-key/add-dist-header) — _Prepend a one-line banner comment (with license notice) to distribution files_
|
|
234
|
+
- 📄 [`copy-file-util`](https://github.com/center-key/copy-file-util) — _Copy or rename a file with optional package version number_
|
|
235
|
+
- 📂 [`copy-folder-util`](https://github.com/center-key/copy-folder-util) — _Recursively copy files from one folder to another folder_
|
|
236
|
+
- 🪺 [`recursive-exec`](https://github.com/center-key/recursive-exec) — _Run a command on each file in a folder and its subfolders_
|
|
237
|
+
- 🔍 [`replacer-util`](https://github.com/center-key/replacer-util) — _Find and replace strings or template outputs in text files_
|
|
238
|
+
- 🔢 [`rev-web-assets`](https://github.com/center-key/rev-web-assets) — _Revision web asset filenames with cache busting content hash fingerprints_
|
|
239
|
+
- 🚆 [`run-scripts-util`](https://github.com/center-key/run-scripts-util) — _Organize npm package.json scripts into groups of easy-to-manage commands_
|
|
240
|
+
- 🚦 [`w3c-html-validator`](https://github.com/center-key/w3c-html-validator) — _Check the markup validity of HTML files using the W3C validator_
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
//! w3c-html-validator v2.2.
|
|
1
|
+
//! w3c-html-validator v2.2.2 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
|
|
2
2
|
|
|
3
3
|
export type ValidatorSettings = {
|
|
4
4
|
html: string | null;
|
|
5
5
|
filename: string | null;
|
|
6
|
+
fileCount: number | null;
|
|
6
7
|
website: string | null;
|
|
7
8
|
checkUrl: string | null;
|
|
8
9
|
ignoreLevel: 'info' | 'warning' | null;
|
|
@@ -31,6 +32,7 @@ export type ValidatorResults = {
|
|
|
31
32
|
title: string;
|
|
32
33
|
html: string | null;
|
|
33
34
|
filename: string | null;
|
|
35
|
+
fileCount: number | null;
|
|
34
36
|
website: string | null;
|
|
35
37
|
output: 'json' | 'html';
|
|
36
38
|
status: number;
|
|
@@ -48,11 +50,9 @@ declare const w3cHtmlValidator: {
|
|
|
48
50
|
version: string;
|
|
49
51
|
checkUrl: string;
|
|
50
52
|
defaultIgnoreList: string[];
|
|
51
|
-
|
|
53
|
+
assertOk(ok: unknown, message: string | null): void;
|
|
52
54
|
cli(): void;
|
|
53
55
|
validate(options: Partial<ValidatorSettings>): Promise<ValidatorResults>;
|
|
54
|
-
dryRunNotice(): void;
|
|
55
|
-
summary(numFiles: number): void;
|
|
56
56
|
reporter(results: ValidatorResults, options?: Partial<ReporterSettings>): ValidatorResults;
|
|
57
57
|
};
|
|
58
58
|
export { w3cHtmlValidator };
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
//! w3c-html-validator v2.2.
|
|
1
|
+
//! w3c-html-validator v2.2.2 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
|
|
2
2
|
|
|
3
3
|
import { cliArgvUtil } from 'cli-argv-util';
|
|
4
4
|
import { globSync } from 'glob';
|
|
5
5
|
import chalk from 'chalk';
|
|
6
|
-
import fs from 'fs';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
7
|
import log from 'fancy-log';
|
|
8
8
|
import request from 'superagent';
|
|
9
9
|
import slash from 'slash';
|
|
10
10
|
const w3cHtmlValidator = {
|
|
11
|
-
version: '2.2.
|
|
11
|
+
version: '2.2.2',
|
|
12
12
|
checkUrl: 'https://validator.w3.org/nu/',
|
|
13
13
|
defaultIgnoreList: [
|
|
14
14
|
'with computed level',
|
|
15
15
|
'Section lacks heading.',
|
|
16
16
|
],
|
|
17
|
-
|
|
17
|
+
assertOk(ok, message) {
|
|
18
18
|
if (!ok)
|
|
19
19
|
throw new Error(`[w3c-html-validator] ${message}`);
|
|
20
20
|
},
|
|
@@ -24,7 +24,7 @@ const w3cHtmlValidator = {
|
|
|
24
24
|
const cli = cliArgvUtil.parse(validFlags);
|
|
25
25
|
const files = cli.params.length ? cli.params.map(cliArgvUtil.cleanPath) : ['.'];
|
|
26
26
|
const checkUrl = cli.flagMap.checkUrl ?? w3cHtmlValidator.checkUrl;
|
|
27
|
-
const
|
|
27
|
+
const excludes = cli.flagMap.exclude?.split(',') ?? [];
|
|
28
28
|
const ignore = cli.flagMap.ignore ?? null;
|
|
29
29
|
const ignoreConfig = cli.flagMap.ignoreConfig ?? null;
|
|
30
30
|
const defaultRules = cli.flagOn.defaultRules;
|
|
@@ -32,10 +32,12 @@ const w3cHtmlValidator = {
|
|
|
32
32
|
const trim = Number(cli.flagMap.trim) || null;
|
|
33
33
|
const dryRun = cli.flagOn.dryRun || process.env.w3cHtmlValidator === 'dry-run';
|
|
34
34
|
const getFilenames = () => {
|
|
35
|
-
const
|
|
35
|
+
const globOptions = { ignore: '**/node_modules/**/*' };
|
|
36
|
+
const readFilenames = (file) => globSync(file, globOptions).map(slash);
|
|
37
|
+
const isFolder = (folder) => fs.lstatSync(folder).isDirectory();
|
|
36
38
|
const readHtmlFiles = (folder) => readFilenames(folder + '/**/*.html');
|
|
37
|
-
const addHtml = (file) =>
|
|
38
|
-
const keep = (file) =>
|
|
39
|
+
const addHtml = (file) => isFolder(file) ? readHtmlFiles(file) : file;
|
|
40
|
+
const keep = (file) => excludes.every(exclude => !file.includes(exclude));
|
|
39
41
|
return files.map(readFilenames).flat().map(addHtml).flat().filter(keep).sort();
|
|
40
42
|
};
|
|
41
43
|
const filenames = getFilenames();
|
|
@@ -43,11 +45,13 @@ const w3cHtmlValidator = {
|
|
|
43
45
|
!filenames.length ? 'No files to validate.' :
|
|
44
46
|
cli.flagOn.trim && !trim ? 'Value of "trim" must be a positive whole number.' :
|
|
45
47
|
null;
|
|
46
|
-
w3cHtmlValidator.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
w3cHtmlValidator.assertOk(!error, error);
|
|
49
|
+
const name = chalk.gray('w3c-html-validator');
|
|
50
|
+
const version = chalk.gray('v' + w3cHtmlValidator.version);
|
|
51
|
+
const summary = chalk.white(`(files: ${filenames.length})`);
|
|
52
|
+
const warning = dryRun ? chalk.yellowBright('[dry run mode - skipping validation]') : '';
|
|
53
|
+
if (!cli.flagOn.quiet || dryRun)
|
|
54
|
+
log(name, version, checkUrl, summary, warning);
|
|
51
55
|
const reporterOptions = {
|
|
52
56
|
continueOnFail: cli.flagOn.continue,
|
|
53
57
|
maxMessageLen: trim,
|
|
@@ -65,10 +69,10 @@ const w3cHtmlValidator = {
|
|
|
65
69
|
return rawLines.map(line => isRegex.test(line) ? new RegExp(line.slice(1, -1)) : line);
|
|
66
70
|
};
|
|
67
71
|
const ignoreMessages = getIgnoreMessages();
|
|
68
|
-
const options = (filename) => ({ filename, checkUrl, ignoreMessages, defaultRules, dryRun });
|
|
72
|
+
const options = (filename, fileCount) => ({ filename, fileCount, checkUrl, ignoreMessages, defaultRules, dryRun });
|
|
69
73
|
const handleResults = (results) => w3cHtmlValidator.reporter(results, reporterOptions);
|
|
70
|
-
const getReport = (filename) => w3cHtmlValidator.validate(options(filename)).then(handleResults);
|
|
71
|
-
const processFile = (filename,
|
|
74
|
+
const getReport = (filename, fileCount) => w3cHtmlValidator.validate(options(filename, fileCount)).then(handleResults);
|
|
75
|
+
const processFile = (filename, index) => globalThis.setTimeout(() => getReport(filename, index + 1), index * delay);
|
|
72
76
|
filenames.forEach(processFile);
|
|
73
77
|
},
|
|
74
78
|
validate(options) {
|
|
@@ -77,6 +81,7 @@ const w3cHtmlValidator = {
|
|
|
77
81
|
defaultRules: false,
|
|
78
82
|
dryRun: false,
|
|
79
83
|
filename: null,
|
|
84
|
+
fileCount: null,
|
|
80
85
|
html: null,
|
|
81
86
|
ignoreLevel: null,
|
|
82
87
|
ignoreMessages: [],
|
|
@@ -91,14 +96,14 @@ const w3cHtmlValidator = {
|
|
|
91
96
|
badLevel ? `Invalid ignoreLevel option: ${settings.ignoreLevel}` :
|
|
92
97
|
invalidOutput ? 'Option "output" must be "json" or "html".' :
|
|
93
98
|
null;
|
|
94
|
-
w3cHtmlValidator.
|
|
99
|
+
w3cHtmlValidator.assertOk(!error, error);
|
|
95
100
|
const filename = settings.filename ? slash(settings.filename) : null;
|
|
96
101
|
const mode = settings.html ? 'html' : filename ? 'filename' : 'website';
|
|
97
102
|
const unixify = (text) => text.replace(/\r/g, '');
|
|
98
103
|
const readFile = (filename) => unixify(fs.readFileSync(filename, 'utf-8'));
|
|
99
104
|
const inputHtml = settings.html ?? (filename ? readFile(filename) : null);
|
|
100
105
|
const makePostRequest = () => request.post(settings.checkUrl)
|
|
101
|
-
.set('
|
|
106
|
+
.set('content-type', 'text/html; encoding=utf-8')
|
|
102
107
|
.send(inputHtml);
|
|
103
108
|
const makeGetRequest = () => request.get(settings.checkUrl)
|
|
104
109
|
.query({ doc: settings.website });
|
|
@@ -131,6 +136,7 @@ const w3cHtmlValidator = {
|
|
|
131
136
|
title: titleLookup[mode],
|
|
132
137
|
html: inputHtml,
|
|
133
138
|
filename: filename,
|
|
139
|
+
fileCount: settings.fileCount,
|
|
134
140
|
website: settings.website || null,
|
|
135
141
|
output: settings.output,
|
|
136
142
|
status: response.statusCode || -1,
|
|
@@ -154,12 +160,6 @@ const w3cHtmlValidator = {
|
|
|
154
160
|
const validation = settings.dryRun ? pseudoRequest() : w3cRequest;
|
|
155
161
|
return validation.then(filterMessages).then(toValidatorResults).catch(handleError);
|
|
156
162
|
},
|
|
157
|
-
dryRunNotice() {
|
|
158
|
-
log(chalk.gray('w3c-html-validator'), chalk.yellowBright('dry run mode:'), chalk.whiteBright('validation being bypassed'));
|
|
159
|
-
},
|
|
160
|
-
summary(numFiles) {
|
|
161
|
-
log(chalk.gray('w3c-html-validator'), chalk.magenta('files: ' + String(numFiles)));
|
|
162
|
-
},
|
|
163
163
|
reporter(results, options) {
|
|
164
164
|
const defaults = {
|
|
165
165
|
continueOnFail: false,
|
|
@@ -168,14 +168,16 @@ const w3cHtmlValidator = {
|
|
|
168
168
|
title: null,
|
|
169
169
|
};
|
|
170
170
|
const settings = { ...defaults, ...options };
|
|
171
|
+
const name = chalk.gray('w3c-html-validator');
|
|
172
|
+
const fileCount = results.fileCount ? chalk.magenta(results.fileCount) + ' ' : '';
|
|
171
173
|
const hasResults = 'validates' in results && typeof results.validates === 'boolean';
|
|
172
|
-
w3cHtmlValidator.
|
|
174
|
+
w3cHtmlValidator.assertOk(hasResults, `Invalid results for reporter(): ${results}`);
|
|
173
175
|
const messages = results.messages ?? [];
|
|
174
176
|
const title = settings.title ?? results.title;
|
|
175
177
|
const status = results.validates ? chalk.green.bold('✔ pass') : chalk.red.bold('✘ fail');
|
|
176
178
|
const count = results.validates ? '' : `(messages: ${messages.length})`;
|
|
177
|
-
if (!results.validates || !settings.quiet)
|
|
178
|
-
log(
|
|
179
|
+
if (!results.validates || !settings.quiet || results.dryRun)
|
|
180
|
+
log(name, status, fileCount + chalk.blue.bold(title), chalk.white(count));
|
|
179
181
|
const typeColorMap = {
|
|
180
182
|
error: chalk.red.bold,
|
|
181
183
|
warning: chalk.yellow.bold,
|
|
@@ -198,7 +200,7 @@ const w3cHtmlValidator = {
|
|
|
198
200
|
return !results.filename ? results.messages[0].message : fileDetails();
|
|
199
201
|
};
|
|
200
202
|
const failed = !settings.continueOnFail && !results.validates;
|
|
201
|
-
w3cHtmlValidator.
|
|
203
|
+
w3cHtmlValidator.assertOk(!failed, `Failed: ${failDetails()}`);
|
|
202
204
|
return results;
|
|
203
205
|
},
|
|
204
206
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w3c-html-validator",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "Check the markup validity of HTML files using the W3C validator",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -58,27 +58,27 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"chalk": "~5.6",
|
|
61
|
-
"cli-argv-util": "~1.
|
|
61
|
+
"cli-argv-util": "~1.5",
|
|
62
62
|
"fancy-log": "~2.0",
|
|
63
63
|
"glob": "~13.0",
|
|
64
64
|
"slash": "~5.1",
|
|
65
65
|
"superagent": "~10.3"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@eslint/js": "~
|
|
68
|
+
"@eslint/js": "~10.0",
|
|
69
69
|
"@types/fancy-log": "~2.0",
|
|
70
|
-
"@types/node": "~
|
|
70
|
+
"@types/node": "~26.0",
|
|
71
71
|
"@types/superagent": "~8.1",
|
|
72
72
|
"add-dist-header": "~1.6",
|
|
73
73
|
"assert-deep-strict-equal": "~1.2",
|
|
74
74
|
"copy-file-util": "~1.3",
|
|
75
75
|
"copy-folder-util": "~1.2",
|
|
76
|
-
"eslint": "~
|
|
76
|
+
"eslint": "~10.6",
|
|
77
77
|
"jshint": "~2.13",
|
|
78
78
|
"mocha": "~11.7",
|
|
79
79
|
"rimraf": "~6.1",
|
|
80
80
|
"run-scripts-util": "~1.3",
|
|
81
|
-
"typescript": "~
|
|
82
|
-
"typescript-eslint": "~8.
|
|
81
|
+
"typescript": "~6.0",
|
|
82
|
+
"typescript-eslint": "~8.62"
|
|
83
83
|
}
|
|
84
84
|
}
|