w3c-html-validator 1.2.1 → 1.3.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/LICENSE.txt +1 -1
- package/README.md +24 -21
- package/bin/cli.js +8 -5
- package/dist/w3c-html-validator.d.ts +2 -1
- package/dist/w3c-html-validator.js +15 -7
- package/dist/w3c-html-validator.umd.cjs +15 -7
- package/package.json +9 -9
package/LICENSE.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2021-
|
|
3
|
+
Copyright (c) 2021-2023 Individual contributors to w3c-html-validator
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -47,16 +47,18 @@ $ npm install --global w3c-html-validator
|
|
|
47
47
|
$ html-validator docs/*.html flyer.html
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
### 3. CLI
|
|
50
|
+
### 3. CLI flags
|
|
51
51
|
Command-line flags:
|
|
52
|
-
| Flag
|
|
53
|
-
|
|
|
54
|
-
| `--
|
|
55
|
-
| `--
|
|
56
|
-
| `--
|
|
57
|
-
| `--
|
|
58
|
-
|
|
59
|
-
|
|
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
|
+
| `--note` | Place to add a comment only for humans. | **string** |
|
|
58
|
+
| `--quiet` | Suppress messages for successful validations. | N/A |
|
|
59
|
+
| `--trim` | Truncate validation messages to not exceed a maximum length. | **number** |
|
|
60
|
+
|
|
61
|
+
### 4. Example CLI usage
|
|
60
62
|
Examples:
|
|
61
63
|
- `html-validator`<br>
|
|
62
64
|
Validate all HTML files in the project.
|
|
@@ -66,8 +68,8 @@ Examples:
|
|
|
66
68
|
Suppress "pass" messages.
|
|
67
69
|
- `html-validator docs`<br>
|
|
68
70
|
Validate HTML files in a folder.
|
|
69
|
-
- `html-validator docs --trim=30`<br>
|
|
70
|
-
Truncate messages to 30 characters.
|
|
71
|
+
- `html-validator docs --trim=30 --continue`<br>
|
|
72
|
+
Truncate messages to 30 characters and do not abort CI if validation fails.
|
|
71
73
|
|
|
72
74
|
## D) Application Code and Testing Frameworks
|
|
73
75
|
In addition to the CLI interface, the **w3c-html-validator** package can also be imported and called directly in ESM and TypeScript projects.
|
|
@@ -107,18 +109,19 @@ $ node examples.js
|
|
|
107
109
|
Option value `'warning'` also skips `'info'`.
|
|
108
110
|
|
|
109
111
|
#### w3cHtmlValidator.reporter(options)
|
|
110
|
-
| Name (key)
|
|
111
|
-
|
|
|
112
|
-
| `
|
|
113
|
-
| `
|
|
114
|
-
| `
|
|
112
|
+
| Name (key) | Type | Default | Description |
|
|
113
|
+
| :--------------- | :---------- | :------ | :-------------------------------------------------------------- |
|
|
114
|
+
| `continueOnFail` | **boolean** | `false` | Report messages but do not throw an error if validation failed. |
|
|
115
|
+
| `maxMessageLen` | **number** | `null` | Trim validation messages to not exceed a maximum length. |
|
|
116
|
+
| `quiet` | **boolean** | `false` | Suppress messages for successful validations. |
|
|
117
|
+
| `title` | **string** | `null` | Override display title (useful for naming HTML string inputs). |
|
|
115
118
|
|
|
116
|
-
### 3. TypeScript
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
### 3. TypeScript declarations
|
|
120
|
+
See the TypeScript declarations at the top of the
|
|
121
|
+
[w3c-html-validator.ts](w3c-html-validator.ts) file.
|
|
119
122
|
|
|
120
123
|
The output of the `w3cHtmlValidator.validate(options: ValidatorOptions)` function is a **promise**
|
|
121
|
-
for `ValidatorResults` object:
|
|
124
|
+
for a `ValidatorResults` object:
|
|
122
125
|
```typescript
|
|
123
126
|
type ValidatorResults = {
|
|
124
127
|
validates: boolean,
|
|
@@ -133,7 +136,7 @@ type ValidatorResults = {
|
|
|
133
136
|
};
|
|
134
137
|
```
|
|
135
138
|
|
|
136
|
-
### 4. Mocha
|
|
139
|
+
### 4. Mocha example
|
|
137
140
|
```javascript
|
|
138
141
|
import assert from 'assert';
|
|
139
142
|
import { w3cHtmlValidator } from 'w3c-html-validator';
|
package/bin/cli.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
//
|
|
18
18
|
// Contributors to this project:
|
|
19
19
|
// $ cd w3c-html-validator
|
|
20
|
-
// $ node bin/cli.js spec/**/*.html --
|
|
20
|
+
// $ node bin/cli.js spec/**/*.html --continue
|
|
21
21
|
|
|
22
22
|
// Imports
|
|
23
23
|
import { cliArgvUtil } from 'cli-argv-util';
|
|
@@ -28,9 +28,10 @@ import glob from 'glob';
|
|
|
28
28
|
import log from 'fancy-log';
|
|
29
29
|
|
|
30
30
|
// Parameters and flags
|
|
31
|
-
const validFlags = ['exclude', 'note', 'quiet', 'trim'];
|
|
31
|
+
const validFlags = ['continue', 'delay', 'exclude', 'note', 'quiet', 'trim'];
|
|
32
32
|
const cli = cliArgvUtil.parse(validFlags);
|
|
33
33
|
const files = cli.params;
|
|
34
|
+
const delay = parseInt(cli.flagMap.delay) || 500; //default half second debounce pause
|
|
34
35
|
const trim = parseInt(cli.flagMap.trim) || null;
|
|
35
36
|
|
|
36
37
|
// Validator
|
|
@@ -51,8 +52,10 @@ if (error)
|
|
|
51
52
|
if (filenames.length > 1 && !cli.flagOn.quiet)
|
|
52
53
|
log(chalk.gray('w3c-html-validator'), chalk.magenta('files: ' + filenames.length));
|
|
53
54
|
const reporterOptions = {
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
continueOnFail: cli.flagOn.continue,
|
|
56
|
+
quiet: cli.flagOn.quiet,
|
|
57
|
+
maxMessageLen: trim,
|
|
56
58
|
};
|
|
57
59
|
const handleReport = (report) => w3cHtmlValidator.reporter(report, reporterOptions);
|
|
58
|
-
|
|
60
|
+
const getReport = (file) => w3cHtmlValidator.validate({ filename: file }).then(handleReport);
|
|
61
|
+
filenames.forEach((file, i) => globalThis.setTimeout(() => getReport(file), i * delay));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! w3c-html-validator v1.
|
|
1
|
+
//! w3c-html-validator v1.3.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
|
|
2
2
|
|
|
3
3
|
export type ValidatorSettings = {
|
|
4
4
|
html: string;
|
|
@@ -37,6 +37,7 @@ export type ValidatorResults = {
|
|
|
37
37
|
};
|
|
38
38
|
export type ValidatorResultsOutput = ValidatorResults['output'];
|
|
39
39
|
export type ReporterSettings = {
|
|
40
|
+
continueOnFail: boolean;
|
|
40
41
|
maxMessageLen: number | null;
|
|
41
42
|
quiet: boolean;
|
|
42
43
|
title: string | null;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
//! w3c-html-validator v1.
|
|
1
|
+
//! w3c-html-validator v1.3.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.3.1',
|
|
9
9
|
validate(options) {
|
|
10
10
|
var _a;
|
|
11
11
|
const defaults = {
|
|
@@ -81,6 +81,7 @@ const w3cHtmlValidator = {
|
|
|
81
81
|
reporter(results, options) {
|
|
82
82
|
var _a, _b;
|
|
83
83
|
const defaults = {
|
|
84
|
+
continueOnFail: false,
|
|
84
85
|
maxMessageLen: null,
|
|
85
86
|
quiet: false,
|
|
86
87
|
title: null,
|
|
@@ -100,17 +101,24 @@ const w3cHtmlValidator = {
|
|
|
100
101
|
info: chalk.white.bold,
|
|
101
102
|
};
|
|
102
103
|
const logMessage = (message) => {
|
|
103
|
-
var _a, _b;
|
|
104
|
-
const type = message.subType
|
|
105
|
-
const typeColor = typeColorMap[type]
|
|
104
|
+
var _a, _b, _c, _d;
|
|
105
|
+
const type = (_a = message.subType) !== null && _a !== void 0 ? _a : message.type;
|
|
106
|
+
const typeColor = (_b = typeColorMap[type]) !== null && _b !== void 0 ? _b : chalk.redBright.bold;
|
|
106
107
|
const location = `line ${message.lastLine}, column ${message.firstColumn}:`;
|
|
107
|
-
const lineText = (
|
|
108
|
-
const maxLen = (
|
|
108
|
+
const lineText = (_c = message.extract) === null || _c === void 0 ? void 0 : _c.replace(/\n/g, '\\n');
|
|
109
|
+
const maxLen = (_d = settings.maxMessageLen) !== null && _d !== void 0 ? _d : undefined;
|
|
109
110
|
log(typeColor('HTML ' + type + ':'), message.message.substring(0, maxLen));
|
|
110
111
|
if (message.lastLine)
|
|
111
112
|
log(chalk.white(location), chalk.magenta(lineText));
|
|
112
113
|
};
|
|
113
114
|
messages.forEach(logMessage);
|
|
115
|
+
const failDetails = () => {
|
|
116
|
+
const toString = (message) => { var _a; return `${(_a = message.subType) !== null && _a !== void 0 ? _a : message.type} line ${message.lastLine} column ${message.firstColumn}`; };
|
|
117
|
+
const fileDetails = () => results.filename + ' -- ' + results.messages.map(toString).join(', ');
|
|
118
|
+
return !results.filename ? results.messages[0].message : fileDetails();
|
|
119
|
+
};
|
|
120
|
+
if (!settings.continueOnFail && !results.validates)
|
|
121
|
+
throw Error('[w3c-html-validator] Failed: ' + failDetails());
|
|
114
122
|
return results;
|
|
115
123
|
},
|
|
116
124
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! w3c-html-validator v1.
|
|
1
|
+
//! w3c-html-validator v1.3.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
|
|
2
2
|
|
|
3
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -20,7 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
const fancy_log_1 = __importDefault(require("fancy-log"));
|
|
21
21
|
const superagent_1 = __importDefault(require("superagent"));
|
|
22
22
|
const w3cHtmlValidator = {
|
|
23
|
-
version: '1.
|
|
23
|
+
version: '1.3.1',
|
|
24
24
|
validate(options) {
|
|
25
25
|
var _a;
|
|
26
26
|
const defaults = {
|
|
@@ -96,6 +96,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
96
96
|
reporter(results, options) {
|
|
97
97
|
var _a, _b;
|
|
98
98
|
const defaults = {
|
|
99
|
+
continueOnFail: false,
|
|
99
100
|
maxMessageLen: null,
|
|
100
101
|
quiet: false,
|
|
101
102
|
title: null,
|
|
@@ -115,17 +116,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
115
116
|
info: chalk_1.default.white.bold,
|
|
116
117
|
};
|
|
117
118
|
const logMessage = (message) => {
|
|
118
|
-
var _a, _b;
|
|
119
|
-
const type = message.subType
|
|
120
|
-
const typeColor = typeColorMap[type]
|
|
119
|
+
var _a, _b, _c, _d;
|
|
120
|
+
const type = (_a = message.subType) !== null && _a !== void 0 ? _a : message.type;
|
|
121
|
+
const typeColor = (_b = typeColorMap[type]) !== null && _b !== void 0 ? _b : chalk_1.default.redBright.bold;
|
|
121
122
|
const location = `line ${message.lastLine}, column ${message.firstColumn}:`;
|
|
122
|
-
const lineText = (
|
|
123
|
-
const maxLen = (
|
|
123
|
+
const lineText = (_c = message.extract) === null || _c === void 0 ? void 0 : _c.replace(/\n/g, '\\n');
|
|
124
|
+
const maxLen = (_d = settings.maxMessageLen) !== null && _d !== void 0 ? _d : undefined;
|
|
124
125
|
(0, fancy_log_1.default)(typeColor('HTML ' + type + ':'), message.message.substring(0, maxLen));
|
|
125
126
|
if (message.lastLine)
|
|
126
127
|
(0, fancy_log_1.default)(chalk_1.default.white(location), chalk_1.default.magenta(lineText));
|
|
127
128
|
};
|
|
128
129
|
messages.forEach(logMessage);
|
|
130
|
+
const failDetails = () => {
|
|
131
|
+
const toString = (message) => { var _a; return `${(_a = message.subType) !== null && _a !== void 0 ? _a : message.type} line ${message.lastLine} column ${message.firstColumn}`; };
|
|
132
|
+
const fileDetails = () => results.filename + ' -- ' + results.messages.map(toString).join(', ');
|
|
133
|
+
return !results.filename ? results.messages[0].message : fileDetails();
|
|
134
|
+
};
|
|
135
|
+
if (!settings.continueOnFail && !results.validates)
|
|
136
|
+
throw Error('[w3c-html-validator] Failed: ' + failDetails());
|
|
129
137
|
return results;
|
|
130
138
|
},
|
|
131
139
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w3c-html-validator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Check the markup validity of HTML files using the W3C validator",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -78,28 +78,28 @@
|
|
|
78
78
|
"examples": "node examples.js"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"chalk": "~5.
|
|
81
|
+
"chalk": "~5.2",
|
|
82
82
|
"cli-argv-util": "~0.1",
|
|
83
83
|
"fancy-log": "~2.0",
|
|
84
|
-
"glob": "~8.
|
|
84
|
+
"glob": "~8.1",
|
|
85
85
|
"superagent": "~8.0"
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@types/fancy-log": "~2.0",
|
|
89
89
|
"@types/glob": "~8.0",
|
|
90
|
-
"@types/node": "~18.
|
|
90
|
+
"@types/node": "~18.13",
|
|
91
91
|
"@types/superagent": "~4.1",
|
|
92
|
-
"@typescript-eslint/eslint-plugin": "~5.
|
|
93
|
-
"@typescript-eslint/parser": "~5.
|
|
92
|
+
"@typescript-eslint/eslint-plugin": "~5.51",
|
|
93
|
+
"@typescript-eslint/parser": "~5.51",
|
|
94
94
|
"add-dist-header": "~0.3",
|
|
95
95
|
"assert-deep-strict-equal": "~1.0",
|
|
96
96
|
"copy-file-util": "~0.1",
|
|
97
97
|
"copy-folder-util": "~0.2",
|
|
98
|
-
"eslint": "~8.
|
|
98
|
+
"eslint": "~8.33",
|
|
99
99
|
"jshint": "~2.13",
|
|
100
100
|
"merge-stream": "~2.0",
|
|
101
|
-
"mocha": "~10.
|
|
102
|
-
"rimraf": "
|
|
101
|
+
"mocha": "~10.2",
|
|
102
|
+
"rimraf": "3",
|
|
103
103
|
"run-scripts-util": "~0.1",
|
|
104
104
|
"typescript": "~4.9"
|
|
105
105
|
}
|