w3c-html-validator 1.4.0 → 1.5.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 +58 -34
- package/bin/cli.js +28 -20
- package/dist/w3c-html-validator.d.ts +5 -6
- package/dist/w3c-html-validator.js +34 -43
- package/package.json +25 -20
package/README.md
CHANGED
|
@@ -5,7 +5,6 @@ _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://snyk.io/test/github/center-key/w3c-html-validator)
|
|
9
8
|
[](https://github.com/center-key/w3c-html-validator/actions/workflows/run-spec-on-push.yaml)
|
|
10
9
|
|
|
11
10
|
**w3c-html-validator** takes HTML files and returns detailed validation results.
|
|
@@ -24,12 +23,12 @@ $ npm install --save-dev w3c-html-validator
|
|
|
24
23
|
### 1. npm scripts
|
|
25
24
|
Run `html-validator` from the `"scripts"` section of your **package.json** file.
|
|
26
25
|
|
|
27
|
-
The parameters are files to be validated.
|
|
26
|
+
The parameters are folders and files to be validated.
|
|
28
27
|
|
|
29
28
|
Example **package.json** scripts:
|
|
30
29
|
```json
|
|
31
30
|
"scripts": {
|
|
32
|
-
"validate": "html-validator docs
|
|
31
|
+
"validate": "html-validator docs flyer.html",
|
|
33
32
|
"one-folder": "html-validator docs",
|
|
34
33
|
"all": "html-validator --quiet"
|
|
35
34
|
},
|
|
@@ -38,40 +37,48 @@ Example **package.json** scripts:
|
|
|
38
37
|
Passing no parameters defaults to validating all HTML files in the project (skipping the
|
|
39
38
|
**node_modules** folder).
|
|
40
39
|
|
|
41
|
-
### 2.
|
|
42
|
-
You can install **w3c-html-validator** globally and then run it anywhere directly from the terminal.
|
|
43
|
-
|
|
40
|
+
### 2. Command-line npx
|
|
44
41
|
Example terminal commands:
|
|
45
42
|
```shell
|
|
46
|
-
$ npm install --
|
|
47
|
-
$ html-validator docs
|
|
43
|
+
$ npm install --save-dev w3c-html-validator
|
|
44
|
+
$ npx html-validator docs
|
|
48
45
|
```
|
|
46
|
+
The above `npx` line validates all the HTML files in the **docs** folder.
|
|
47
|
+
|
|
48
|
+
You can also install **w3c-html-validator** globally (`--global`) and then run it anywhere directly from the terminal.
|
|
49
49
|
|
|
50
50
|
### 3. CLI flags
|
|
51
51
|
Command-line flags:
|
|
52
|
-
| Flag
|
|
53
|
-
|
|
|
54
|
-
| `--continue`
|
|
55
|
-
| `--delay`
|
|
56
|
-
| `--exclude`
|
|
57
|
-
| `--ignore`
|
|
58
|
-
| `--
|
|
59
|
-
| `--
|
|
60
|
-
| `--
|
|
52
|
+
| Flag | Description | Value |
|
|
53
|
+
| ----------------- | ------------------------------------------------------------------- | ---------- |
|
|
54
|
+
| `--continue` | Report messages but do not throw an error if validation failed. | N/A |
|
|
55
|
+
| `--delay` | Debounce pause in milliseconds between each file validation. | **number** |
|
|
56
|
+
| `--exclude` | Comma separated list of strings to match in paths to skip. | **string** |
|
|
57
|
+
| `--ignore` | Skip validation messages containing a string or matching a regex. | **string** |
|
|
58
|
+
| `--ignore-config` | File containing strings and regexes of validation messages to skip. | **string** |
|
|
59
|
+
| `--note` | Place to add a comment only for humans. | **string** |
|
|
60
|
+
| `--quiet` | Suppress messages for successful validations. | N/A |
|
|
61
|
+
| `--trim` | Truncate validation messages to not exceed a maximum length. | **number** |
|
|
61
62
|
|
|
62
63
|
### 4. Example CLI usage
|
|
63
64
|
Examples:
|
|
64
65
|
- `html-validator`<br>
|
|
65
66
|
Validate all HTML files in the project.
|
|
66
67
|
|
|
67
|
-
- `html-validator --exclude=build,tmp`<br>
|
|
68
|
-
|
|
68
|
+
- `html-validator docs --exclude=build,tmp`<br>
|
|
69
|
+
Validate all HTML files in the **docs** folder except files which have "build" or "tmp" anywhere in their pathname or filename.
|
|
69
70
|
|
|
70
|
-
- `html-validator docs
|
|
71
|
+
- `html-validator docs '--ignore=Trailing slash on void elements'`<br>
|
|
71
72
|
Allow the ugly slashes of self-closing tags despite XHTML being a hideous scourge on the web.
|
|
72
73
|
|
|
73
|
-
- `html-validator docs
|
|
74
|
-
Use a
|
|
74
|
+
- `html-validator docs '--ignore=/^Duplicate ID/'`<br>
|
|
75
|
+
Use a regex (regular expression) to skip all HTML validation messages that start with "Duplicate ID".
|
|
76
|
+
|
|
77
|
+
- `html-validator docs '--ignore=/^Duplicate ID|^Section lacks|^Element .blockquote. not allowed/'`<br>
|
|
78
|
+
Use a regex with "or" operators (`|`) to skip multiple HTML validation messages.
|
|
79
|
+
|
|
80
|
+
- `html-validator docs --ignore-config=spec/ignore-config.txt`<br>
|
|
81
|
+
Similar to the pervious command but strings and regexes are stored in a configuration file (see the _Ignore Configuration File_ section below).
|
|
75
82
|
|
|
76
83
|
- `html-validator --quiet`<br>
|
|
77
84
|
Suppress "pass" status messages.
|
|
@@ -82,6 +89,22 @@ Examples:
|
|
|
82
89
|
- `html-validator docs --trim=30 --continue`<br>
|
|
83
90
|
Truncate validation messages to 30 characters and do not abort CI if validation fails.
|
|
84
91
|
|
|
92
|
+
### 5. Ignore Configuration File
|
|
93
|
+
The optional `--ignore-config=FILENAME` flag specifies a configuration file with one string or regex per line.
|
|
94
|
+
HTML validation messages containing any of the strings or matching any of the regexes will be skipped.
|
|
95
|
+
Empty lines and lines starting with a hash sign (`#`) are treated as comments and do nothing.
|
|
96
|
+
|
|
97
|
+
Example configuration file with 3 regexes:
|
|
98
|
+
```config
|
|
99
|
+
# Ignore Config for w3c-html-validator
|
|
100
|
+
|
|
101
|
+
/^Duplicate ID/
|
|
102
|
+
/^Element .blockquote. not allowed/
|
|
103
|
+
/^Element .style. not allowed/
|
|
104
|
+
```
|
|
105
|
+
The caret (`^`) regex operator says to match from the beginning of the validation message.
|
|
106
|
+
The dot (`.`) regex operator says to match any one character, which is a handy way to avoid typing the special curly quote characters in some of the validation messages.
|
|
107
|
+
|
|
85
108
|
## D) Application Code and Testing Frameworks
|
|
86
109
|
In addition to the CLI interface, the **w3c-html-validator** package can also be imported and called directly in ESM and TypeScript projects.
|
|
87
110
|
|
|
@@ -106,18 +129,18 @@ $ node examples.js
|
|
|
106
129
|
|
|
107
130
|
### 2. Options
|
|
108
131
|
#### w3cHtmlValidator.validate(options)
|
|
109
|
-
| Name (key) | Type | Default | Description
|
|
110
|
-
| :--------------- | :---------------------- | :------------------------------- |
|
|
111
|
-
| `checkUrl` | **string** | `'https://validator.w3.org/nu/'` | W3C validation API endpoint.
|
|
112
|
-
| `filename` | **string** | `null` | HTML file to validate.
|
|
113
|
-
| `html` | **string** | `null` | HTML string to validate.
|
|
114
|
-
| `ignoreLevel` | `'info'` or `'warning'` | `null` | Skip unwanted messages.*
|
|
115
|
-
| `ignoreMessages` | **
|
|
116
|
-
| `output` | `'json'` or `'html'` | `'json'` | Get results as an array or as a web page.
|
|
117
|
-
| `website` | **string** | `null` | URL of website to validate.
|
|
132
|
+
| Name (key) | Type | Default | Description |
|
|
133
|
+
| :--------------- | :---------------------- | :------------------------------- | :------------------------------------------------------ |
|
|
134
|
+
| `checkUrl` | **string** | `'https://validator.w3.org/nu/'` | W3C validation API endpoint. |
|
|
135
|
+
| `filename` | **string** | `null` | HTML file to validate. |
|
|
136
|
+
| `html` | **string** | `null` | HTML string to validate. |
|
|
137
|
+
| `ignoreLevel` | `'info'` or `'warning'` | `null` | Skip unwanted messages.* |
|
|
138
|
+
| `ignoreMessages` | **array** | `[]` | Skip messages containing a string or matching a regex.* |
|
|
139
|
+
| `output` | `'json'` or `'html'` | `'json'` | Get results as an array or as a web page. |
|
|
140
|
+
| `website` | **string** | `null` | URL of website to validate. |
|
|
118
141
|
|
|
119
142
|
*The `ignoreMessages` and `ignoreLevel` options only work for `'json'` output.
|
|
120
|
-
|
|
143
|
+
Setting `ignoreLevel` to `'warning'` skips both `'warning'` level and `'info'` level validation messages.
|
|
121
144
|
|
|
122
145
|
#### w3cHtmlValidator.reporter(options)
|
|
123
146
|
| Name (key) | Type | Default | Description |
|
|
@@ -157,7 +180,7 @@ describe('Home page', () => {
|
|
|
157
180
|
it('validates', (done) => {
|
|
158
181
|
const handleResults = (results) => {
|
|
159
182
|
assert(results.status === 200, 'Request succeeded');
|
|
160
|
-
assert(results.validates,
|
|
183
|
+
assert(results.validates, 'Home page validates');
|
|
161
184
|
done();
|
|
162
185
|
};
|
|
163
186
|
const options = { filename: 'docs/index.html' };
|
|
@@ -170,10 +193,11 @@ describe('Home page', () => {
|
|
|
170
193
|
<br>
|
|
171
194
|
|
|
172
195
|
---
|
|
173
|
-
**CLI Build Tools**
|
|
196
|
+
**CLI Build Tools for package.json**
|
|
174
197
|
- 🎋 [add-dist-header](https://github.com/center-key/add-dist-header): _Prepend a one-line banner comment (with license notice) to distribution files_
|
|
175
198
|
- 📄 [copy-file-util](https://github.com/center-key/copy-file-util): _Copy or rename a file with optional package version number_
|
|
176
199
|
- 📂 [copy-folder-util](https://github.com/center-key/copy-folder-util): _Recursively copy files from one folder to another folder_
|
|
200
|
+
- 🪺 [recursive-exec](https://github.com/center-key/recursive-exec): _Run a command on each file in a folder and its subfolders_
|
|
177
201
|
- 🔍 [replacer-util](https://github.com/center-key/replacer-util): _Find and replace strings or template outputs in text files_
|
|
178
202
|
- 🔢 [rev-web-assets](https://github.com/center-key/rev-web-assets): _Revision web asset filenames with cache busting content hash fingerprints_
|
|
179
203
|
- 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util): _Organize npm scripts into named groups of easy to manage commands_
|
package/bin/cli.js
CHANGED
|
@@ -6,34 +6,33 @@
|
|
|
6
6
|
|
|
7
7
|
// Usage in package.json:
|
|
8
8
|
// "scripts": {
|
|
9
|
-
// "validate": "html-validator docs
|
|
9
|
+
// "validate": "html-validator docs flyer.html",
|
|
10
10
|
// "all": "html-validator"
|
|
11
11
|
// },
|
|
12
12
|
//
|
|
13
13
|
// Usage from command line:
|
|
14
|
-
// $ npm install --
|
|
15
|
-
// $ html-validator
|
|
16
|
-
// $ html-validator
|
|
14
|
+
// $ npm install --save-dev w3c-html-validator
|
|
15
|
+
// $ npx html-validator dist #validate all html files in the dist folder
|
|
16
|
+
// $ npx html-validator docs flyer.html
|
|
17
17
|
//
|
|
18
18
|
// Contributors to this project:
|
|
19
19
|
// $ cd w3c-html-validator
|
|
20
|
-
// $ node bin/cli.js spec
|
|
20
|
+
// $ node bin/cli.js spec --continue
|
|
21
21
|
|
|
22
22
|
// Imports
|
|
23
23
|
import { cliArgvUtil } from 'cli-argv-util';
|
|
24
24
|
import { globSync } from 'glob';
|
|
25
25
|
import { w3cHtmlValidator } from '../dist/w3c-html-validator.js';
|
|
26
|
-
import
|
|
27
|
-
import fs from 'fs';
|
|
28
|
-
import log from 'fancy-log';
|
|
26
|
+
import fs from 'fs';
|
|
29
27
|
|
|
30
28
|
// Parameters and flags
|
|
31
|
-
const validFlags = ['continue', 'delay', 'exclude', 'ignore', 'note', 'quiet', 'trim'];
|
|
32
|
-
const cli =
|
|
33
|
-
const files =
|
|
34
|
-
const ignore =
|
|
35
|
-
const
|
|
36
|
-
const
|
|
29
|
+
const validFlags = ['continue', 'delay', 'exclude', 'ignore', 'ignore-config', 'note', 'quiet', 'trim'];
|
|
30
|
+
const cli = cliArgvUtil.parse(validFlags);
|
|
31
|
+
const files = cli.params;
|
|
32
|
+
const ignore = cli.flagMap.ignore ?? null;
|
|
33
|
+
const ignoreConfig = cli.flagMap.ignoreConfig ?? null;
|
|
34
|
+
const delay = Number(cli.flagMap.delay) || 500; //default half second debounce pause
|
|
35
|
+
const trim = Number(cli.flagMap.trim) || null;
|
|
37
36
|
|
|
38
37
|
// Validator
|
|
39
38
|
const keep = (filename) => !filename.includes('node_modules/');
|
|
@@ -51,15 +50,24 @@ const error =
|
|
|
51
50
|
if (error)
|
|
52
51
|
throw Error('[w3c-html-validator] ' + error);
|
|
53
52
|
if (filenames.length > 1 && !cli.flagOn.quiet)
|
|
54
|
-
|
|
53
|
+
w3cHtmlValidator.summary(filenames.length);
|
|
55
54
|
const reporterOptions = {
|
|
56
55
|
continueOnFail: cli.flagOn.continue,
|
|
57
56
|
quiet: cli.flagOn.quiet,
|
|
58
57
|
maxMessageLen: trim,
|
|
59
58
|
};
|
|
60
|
-
const
|
|
61
|
-
const
|
|
59
|
+
const getIgnoreMessages = () => {
|
|
60
|
+
const toArray = (text) => text.replace(/\r/g, '').split('\n').map(line => line.trim());
|
|
61
|
+
const notComment = (line) => line.length > 1 && !line.startsWith('#');
|
|
62
|
+
const readLines = (file) => toArray(fs.readFileSync(file).toString()).filter(notComment);
|
|
63
|
+
const rawLines = ignoreConfig ? readLines(ignoreConfig) : [];
|
|
64
|
+
if (ignore)
|
|
65
|
+
rawLines.push(ignore);
|
|
66
|
+
const isRegex = /^\/.*\/$/; //starts and ends with a slash indicating it's a regex
|
|
67
|
+
return rawLines.map(line => isRegex.test(line) ? new RegExp(line.slice(1, -1)) : line);
|
|
68
|
+
};
|
|
62
69
|
const handleReport = (report) => w3cHtmlValidator.reporter(report, reporterOptions);
|
|
63
|
-
const options = (
|
|
64
|
-
const getReport = (
|
|
65
|
-
|
|
70
|
+
const options = (filename) => ({ filename: filename, ignoreMessages: getIgnoreMessages() });
|
|
71
|
+
const getReport = (filename) => w3cHtmlValidator.validate(options(filename)).then(handleReport);
|
|
72
|
+
const processFile = (filename, i) => globalThis.setTimeout(() => getReport(filename), i * delay);
|
|
73
|
+
filenames.forEach(processFile);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! w3c-html-validator v1.
|
|
1
|
+
//! w3c-html-validator v1.5.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
|
|
2
2
|
|
|
3
3
|
export type ValidatorSettings = {
|
|
4
4
|
html: string;
|
|
@@ -6,10 +6,9 @@ export type ValidatorSettings = {
|
|
|
6
6
|
website: string;
|
|
7
7
|
checkUrl: string;
|
|
8
8
|
ignoreLevel: 'info' | 'warning';
|
|
9
|
-
ignoreMessages: string | RegExp;
|
|
9
|
+
ignoreMessages: (string | RegExp)[];
|
|
10
10
|
output: ValidatorResultsOutput;
|
|
11
11
|
};
|
|
12
|
-
export type ValidatorOptions = Partial<ValidatorSettings>;
|
|
13
12
|
export type ValidatorResultsMessage = {
|
|
14
13
|
type: 'info' | 'error' | 'non-document-error' | 'network-error';
|
|
15
14
|
subType?: 'warning' | 'fatal' | 'io' | 'schema' | 'internal';
|
|
@@ -42,10 +41,10 @@ export type ReporterSettings = {
|
|
|
42
41
|
quiet: boolean;
|
|
43
42
|
title: string | null;
|
|
44
43
|
};
|
|
45
|
-
export type ReporterOptions = Partial<ReporterSettings>;
|
|
46
44
|
declare const w3cHtmlValidator: {
|
|
47
45
|
version: string;
|
|
48
|
-
validate(options:
|
|
49
|
-
|
|
46
|
+
validate(options: Partial<ValidatorSettings>): Promise<ValidatorResults>;
|
|
47
|
+
summary(numFiles: number): void;
|
|
48
|
+
reporter(results: ValidatorResults, options?: Partial<ReporterSettings>): ValidatorResults;
|
|
50
49
|
};
|
|
51
50
|
export { w3cHtmlValidator };
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
//! w3c-html-validator v1.
|
|
1
|
+
//! w3c-html-validator v1.5.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';
|
|
5
5
|
import log from 'fancy-log';
|
|
6
6
|
import request from 'superagent';
|
|
7
7
|
const w3cHtmlValidator = {
|
|
8
|
-
version: '1.
|
|
8
|
+
version: '1.5.1',
|
|
9
9
|
validate(options) {
|
|
10
|
-
var _a;
|
|
11
10
|
const defaults = {
|
|
12
11
|
checkUrl: 'https://validator.w3.org/nu/',
|
|
13
12
|
ignoreLevel: null,
|
|
14
|
-
ignoreMessages:
|
|
13
|
+
ignoreMessages: [],
|
|
15
14
|
output: 'json',
|
|
16
15
|
};
|
|
17
|
-
const settings =
|
|
16
|
+
const settings = { ...defaults, ...options };
|
|
18
17
|
if (!settings.html && !settings.filename && !settings.website)
|
|
19
18
|
throw Error('[w3c-html-validator] Must specify the "html", "filename", or "website" option.');
|
|
20
19
|
if (![null, 'info', 'warning'].includes(settings.ignoreLevel))
|
|
@@ -23,7 +22,7 @@ const w3cHtmlValidator = {
|
|
|
23
22
|
throw Error('[w3c-html-validator] Option "output" must be "json" or "html".');
|
|
24
23
|
const mode = settings.html ? 'html' : settings.filename ? 'filename' : 'website';
|
|
25
24
|
const readFile = (filename) => fs.readFileSync(filename, 'utf-8').replace(/\r/g, '');
|
|
26
|
-
const inputHtml =
|
|
25
|
+
const inputHtml = settings.html ?? (settings.filename ? readFile(settings.filename) : null);
|
|
27
26
|
const makePostRequest = () => request.post(settings.checkUrl)
|
|
28
27
|
.set('Content-Type', 'text/html; encoding=utf-8')
|
|
29
28
|
.send(inputHtml);
|
|
@@ -35,62 +34,55 @@ const w3cHtmlValidator = {
|
|
|
35
34
|
const json = settings.output === 'json';
|
|
36
35
|
const success = '<p class="success">';
|
|
37
36
|
const titleLookup = {
|
|
38
|
-
html: 'HTML String (characters: ' +
|
|
37
|
+
html: 'HTML String (characters: ' + inputHtml?.length + ')',
|
|
39
38
|
filename: settings.filename,
|
|
40
39
|
website: settings.website,
|
|
41
40
|
};
|
|
42
41
|
const filterMessages = (response) => {
|
|
43
|
-
var _a, _b;
|
|
44
42
|
const aboveInfo = (subType) => settings.ignoreLevel === 'info' && !!subType;
|
|
45
43
|
const aboveIgnoreLevel = (message) => !settings.ignoreLevel || message.type !== 'info' || aboveInfo(message.subType);
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
var _a;
|
|
49
|
-
return ((_a = settings.ignoreMessages) === null || _a === void 0 ? void 0 : _a.constructor.name) === 'RegExp' &&
|
|
50
|
-
settings.ignoreMessages.test(title);
|
|
51
|
-
};
|
|
52
|
-
const isImportant = (message) => aboveIgnoreLevel(message) && !skipSubstr(message.message) && !skipRegEx(message.message);
|
|
44
|
+
const matchesSkipPattern = (title) => settings.ignoreMessages.some(pattern => typeof pattern === 'string' ? title.includes(pattern) : pattern.test(title));
|
|
45
|
+
const isImportant = (message) => aboveIgnoreLevel(message) && !matchesSkipPattern(message.message);
|
|
53
46
|
if (json)
|
|
54
|
-
response.body.messages =
|
|
47
|
+
response.body.messages = response.body.messages?.filter(isImportant) ?? [];
|
|
55
48
|
return response;
|
|
56
49
|
};
|
|
57
|
-
const toValidatorResults = (response) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
display: json ? null : response.text,
|
|
70
|
-
});
|
|
71
|
-
};
|
|
50
|
+
const toValidatorResults = (response) => ({
|
|
51
|
+
validates: json ? !response.body.messages.length : !!response.text?.includes(success),
|
|
52
|
+
mode: mode,
|
|
53
|
+
title: titleLookup[mode],
|
|
54
|
+
html: inputHtml,
|
|
55
|
+
filename: settings.filename || null,
|
|
56
|
+
website: settings.website || null,
|
|
57
|
+
output: settings.output,
|
|
58
|
+
status: response.statusCode || -1,
|
|
59
|
+
messages: json ? response.body.messages : null,
|
|
60
|
+
display: json ? null : response.text,
|
|
61
|
+
});
|
|
72
62
|
const handleError = (reason) => {
|
|
73
63
|
const response = reason.response;
|
|
74
64
|
const getMsg = () => [response.status, response.res.statusMessage, response.request.url];
|
|
75
65
|
const message = response ? getMsg() : [reason.errno, reason.message];
|
|
76
66
|
const networkErr = { type: 'network-error', message: message.join(' ') };
|
|
77
|
-
return toValidatorResults(
|
|
67
|
+
return toValidatorResults({ ...response, ...{ body: { messages: [networkErr] } } });
|
|
78
68
|
};
|
|
79
69
|
return w3cRequest.then(filterMessages).then(toValidatorResults).catch(handleError);
|
|
80
70
|
},
|
|
71
|
+
summary(numFiles) {
|
|
72
|
+
log(chalk.gray('w3c-html-validator'), chalk.magenta('files: ' + numFiles));
|
|
73
|
+
},
|
|
81
74
|
reporter(results, options) {
|
|
82
|
-
var _a, _b;
|
|
83
75
|
const defaults = {
|
|
84
76
|
continueOnFail: false,
|
|
85
77
|
maxMessageLen: null,
|
|
86
78
|
quiet: false,
|
|
87
79
|
title: null,
|
|
88
80
|
};
|
|
89
|
-
const settings =
|
|
90
|
-
if (typeof
|
|
81
|
+
const settings = { ...defaults, ...options };
|
|
82
|
+
if (typeof results?.validates !== 'boolean')
|
|
91
83
|
throw Error('[w3c-html-validator] Invalid results for reporter(): ' + String(results));
|
|
92
|
-
const messages =
|
|
93
|
-
const title =
|
|
84
|
+
const messages = results.messages ?? [];
|
|
85
|
+
const title = settings.title ?? results.title;
|
|
94
86
|
const status = results.validates ? chalk.green.bold('✔ pass') : chalk.red.bold('✘ fail');
|
|
95
87
|
const count = results.validates ? '' : '(messages: ' + messages.length + ')';
|
|
96
88
|
if (!results.validates || !settings.quiet)
|
|
@@ -101,19 +93,18 @@ const w3cHtmlValidator = {
|
|
|
101
93
|
info: chalk.white.bold,
|
|
102
94
|
};
|
|
103
95
|
const logMessage = (message) => {
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
const typeColor = (_b = typeColorMap[type]) !== null && _b !== void 0 ? _b : chalk.redBright.bold;
|
|
96
|
+
const type = (message.subType ?? message.type);
|
|
97
|
+
const typeColor = typeColorMap[type] ?? chalk.redBright.bold;
|
|
107
98
|
const location = `line ${message.lastLine}, column ${message.firstColumn}:`;
|
|
108
|
-
const lineText =
|
|
109
|
-
const maxLen =
|
|
99
|
+
const lineText = message.extract?.replace(/\n/g, '\\n');
|
|
100
|
+
const maxLen = settings.maxMessageLen ?? undefined;
|
|
110
101
|
log(typeColor('HTML ' + type + ':'), message.message.substring(0, maxLen));
|
|
111
102
|
if (message.lastLine)
|
|
112
103
|
log(chalk.white(location), chalk.magenta(lineText));
|
|
113
104
|
};
|
|
114
105
|
messages.forEach(logMessage);
|
|
115
106
|
const failDetails = () => {
|
|
116
|
-
const toString = (message) =>
|
|
107
|
+
const toString = (message) => `${message.subType ?? message.type} line ${message.lastLine} column ${message.firstColumn}`;
|
|
117
108
|
const fileDetails = () => results.filename + ' -- ' + results.messages.map(toString).join(', ');
|
|
118
109
|
return !results.filename ? results.messages[0].message : fileDetails();
|
|
119
110
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w3c-html-validator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Check the markup validity of HTML files using the W3C validator",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -20,7 +20,10 @@
|
|
|
20
20
|
"html-validator": "bin/cli.js",
|
|
21
21
|
"w3c-html-validator": "bin/cli.js"
|
|
22
22
|
},
|
|
23
|
-
"repository":
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/center-key/w3c-html-validator.git"
|
|
26
|
+
},
|
|
24
27
|
"homepage": "https://github.com/center-key/w3c-html-validator",
|
|
25
28
|
"bugs": "https://github.com/center-key/w3c-html-validator/issues",
|
|
26
29
|
"docs": "https://github.com/center-key/w3c-html-validator#readme",
|
|
@@ -64,42 +67,44 @@
|
|
|
64
67
|
"clean": [
|
|
65
68
|
"rimraf build dist"
|
|
66
69
|
],
|
|
67
|
-
"
|
|
70
|
+
"lint": [
|
|
68
71
|
"jshint . --exclude-path .gitignore",
|
|
69
|
-
"eslint --max-warnings 0 . --ext .ts"
|
|
72
|
+
"eslint --max-warnings 0 . --ext .ts"
|
|
73
|
+
],
|
|
74
|
+
"build": [
|
|
70
75
|
"tsc",
|
|
71
76
|
"add-dist-header build dist"
|
|
72
77
|
]
|
|
73
78
|
},
|
|
74
79
|
"scripts": {
|
|
75
|
-
"pretest": "run-scripts clean build",
|
|
76
|
-
"test": "mocha spec/*.spec.js --timeout
|
|
80
|
+
"pretest": "run-scripts clean lint build",
|
|
81
|
+
"test": "mocha spec/*.spec.js --timeout 7000",
|
|
77
82
|
"examples": "node examples.js"
|
|
78
83
|
},
|
|
79
84
|
"dependencies": {
|
|
80
|
-
"chalk": "~5.
|
|
81
|
-
"cli-argv-util": "~1.
|
|
85
|
+
"chalk": "~5.3",
|
|
86
|
+
"cli-argv-util": "~1.2",
|
|
82
87
|
"fancy-log": "~2.0",
|
|
83
|
-
"glob": "
|
|
84
|
-
"superagent": "~8.
|
|
88
|
+
"glob": "10.3.6",
|
|
89
|
+
"superagent": "~8.1"
|
|
85
90
|
},
|
|
86
91
|
"devDependencies": {
|
|
87
92
|
"@types/fancy-log": "~2.0",
|
|
88
93
|
"@types/glob": "~8.1",
|
|
89
|
-
"@types/node": "~20.
|
|
94
|
+
"@types/node": "~20.6",
|
|
90
95
|
"@types/superagent": "~4.1",
|
|
91
|
-
"@typescript-eslint/eslint-plugin": "~
|
|
92
|
-
"@typescript-eslint/parser": "~
|
|
93
|
-
"add-dist-header": "~1.
|
|
94
|
-
"assert-deep-strict-equal": "~1.
|
|
95
|
-
"copy-file-util": "~1.
|
|
96
|
-
"copy-folder-util": "~1.
|
|
97
|
-
"eslint": "~8.
|
|
96
|
+
"@typescript-eslint/eslint-plugin": "~6.7",
|
|
97
|
+
"@typescript-eslint/parser": "~6.7",
|
|
98
|
+
"add-dist-header": "~1.3",
|
|
99
|
+
"assert-deep-strict-equal": "~1.1",
|
|
100
|
+
"copy-file-util": "~1.1",
|
|
101
|
+
"copy-folder-util": "~1.1",
|
|
102
|
+
"eslint": "~8.50",
|
|
98
103
|
"jshint": "~2.13",
|
|
99
104
|
"merge-stream": "~2.0",
|
|
100
105
|
"mocha": "~10.2",
|
|
101
106
|
"rimraf": "~5.0",
|
|
102
|
-
"run-scripts-util": "~1.
|
|
103
|
-
"typescript": "~5.
|
|
107
|
+
"run-scripts-util": "~1.2",
|
|
108
|
+
"typescript": "~5.2"
|
|
104
109
|
}
|
|
105
110
|
}
|