w3c-html-validator 1.2.1 → 1.3.0

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 CHANGED
@@ -47,16 +47,17 @@ $ npm install --global w3c-html-validator
47
47
  $ html-validator docs/*.html flyer.html
48
48
  ```
49
49
 
50
- ### 3. CLI Flags
50
+ ### 3. CLI flags
51
51
  Command-line flags:
52
- | Flag | Description | Value |
53
- | ----------- | ------------------------------------------------------------ | ---------- |
54
- | `--exclude` | Comma separated list of strings to match in paths to skip. | **string** |
55
- | `--note` | Place to add a comment only for humans. | **string** |
56
- | `--quiet` | Suppress messages for successful validations. | N/A |
57
- | `--trim` | Truncate validation messages to not exceed a maximum length. | **number** |
58
-
59
- ### 4. Example CLI Usage
52
+ | Flag | Description | Value |
53
+ | ------------ | --------------------------------------------------------------- | ---------- |
54
+ | `--continue` | Report messages but do not throw an error if validation failed. | N/A |
55
+ | `--exclude` | Comma separated list of strings to match in paths to skip. | **string** |
56
+ | `--note` | Place to add a comment only for humans. | **string** |
57
+ | `--quiet` | Suppress messages for successful validations. | N/A |
58
+ | `--trim` | Truncate validation messages to not exceed a maximum length. | **number** |
59
+
60
+ ### 4. Example CLI usage
60
61
  Examples:
61
62
  - `html-validator`<br>
62
63
  Validate all HTML files in the project.
@@ -66,8 +67,8 @@ Examples:
66
67
  Suppress "pass" messages.
67
68
  - `html-validator docs`<br>
68
69
  Validate HTML files in a folder.
69
- - `html-validator docs --trim=30`<br>
70
- Truncate messages to 30 characters.
70
+ - `html-validator docs --trim=30 --continue`<br>
71
+ Truncate messages to 30 characters and do not abort CI if validation fails.
71
72
 
72
73
  ## D) Application Code and Testing Frameworks
73
74
  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 +108,19 @@ $ node examples.js
107
108
  Option value `'warning'` also skips `'info'`.
108
109
 
109
110
  #### w3cHtmlValidator.reporter(options)
110
- | Name (key) | Type | Default | Description |
111
- | :-------------- | :---------- | :------ | :------------------------------------------------------------- |
112
- | `maxMessageLen` | **number** | `null` | Trim validation messages to not exceed a maximum length. |
113
- | `quiet` | **boolean** | `false` | Suppress messages for successful validations. |
114
- | `title` | **string** | `null` | Override display title (useful for naming HTML string inputs). |
111
+ | Name (key) | Type | Default | Description |
112
+ | :--------------- | :---------- | :------ | :-------------------------------------------------------------- |
113
+ | `continueOnFail` | **boolean** | `false` | Report messages but do not throw an error if validation failed. |
114
+ | `maxMessageLen` | **number** | `null` | Trim validation messages to not exceed a maximum length. |
115
+ | `quiet` | **boolean** | `false` | Suppress messages for successful validations. |
116
+ | `title` | **string** | `null` | Override display title (useful for naming HTML string inputs). |
115
117
 
116
- ### 3. TypeScript Declarations
117
- The **TypeScript Declaration File** file is [w3c-html-validator.d.ts](dist/w3c-html-validator.d.ts)
118
- in the **dist** folder.
118
+ ### 3. TypeScript declarations
119
+ See the TypeScript declarations at the top of the
120
+ [w3c-html-validator.ts](w3c-html-validator.ts) file.
119
121
 
120
122
  The output of the `w3cHtmlValidator.validate(options: ValidatorOptions)` function is a **promise**
121
- for `ValidatorResults` object:
123
+ for a `ValidatorResults` object:
122
124
  ```typescript
123
125
  type ValidatorResults = {
124
126
  validates: boolean,
@@ -133,7 +135,7 @@ type ValidatorResults = {
133
135
  };
134
136
  ```
135
137
 
136
- ### 4. Mocha Example
138
+ ### 4. Mocha example
137
139
  ```javascript
138
140
  import assert from 'assert';
139
141
  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 --quiet
20
+ // $ node bin/cli.js spec/**/*.html --continue
21
21
 
22
22
  // Imports
23
23
  import { cliArgvUtil } from 'cli-argv-util';
@@ -28,7 +28,7 @@ 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', 'exclude', 'note', 'quiet', 'trim'];
32
32
  const cli = cliArgvUtil.parse(validFlags);
33
33
  const files = cli.params;
34
34
  const trim = parseInt(cli.flagMap.trim) || null;
@@ -51,8 +51,9 @@ if (error)
51
51
  if (filenames.length > 1 && !cli.flagOn.quiet)
52
52
  log(chalk.gray('w3c-html-validator'), chalk.magenta('files: ' + filenames.length));
53
53
  const reporterOptions = {
54
- quiet: cli.flagOn.quiet,
55
- maxMessageLen: trim,
54
+ continueOnFail: cli.flagOn.continue,
55
+ quiet: cli.flagOn.quiet,
56
+ maxMessageLen: trim,
56
57
  };
57
58
  const handleReport = (report) => w3cHtmlValidator.reporter(report, reporterOptions);
58
59
  filenames.forEach(file => w3cHtmlValidator.validate({ filename: file }).then(handleReport));
@@ -1,4 +1,4 @@
1
- //! w3c-html-validator v1.2.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v1.3.0 ~~ 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.2.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v1.3.0 ~~ 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.2.1',
8
+ version: '1.3.0',
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 || message.type;
105
- const typeColor = typeColorMap[type] || chalk.redBright.bold;
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 = (_a = message.extract) === null || _a === void 0 ? void 0 : _a.replace(/\n/g, '\\n');
108
- const maxLen = (_b = settings.maxMessageLen) !== null && _b !== void 0 ? _b : undefined;
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.2.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v1.3.0 ~~ 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.2.1',
23
+ version: '1.3.0',
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 || message.type;
120
- const typeColor = typeColorMap[type] || chalk_1.default.redBright.bold;
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 = (_a = message.extract) === null || _a === void 0 ? void 0 : _a.replace(/\n/g, '\\n');
123
- const maxLen = (_b = settings.maxMessageLen) !== null && _b !== void 0 ? _b : undefined;
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.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "Check the markup validity of HTML files using the W3C validator",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -78,7 +78,7 @@
78
78
  "examples": "node examples.js"
79
79
  },
80
80
  "dependencies": {
81
- "chalk": "~5.1",
81
+ "chalk": "~5.2",
82
82
  "cli-argv-util": "~0.1",
83
83
  "fancy-log": "~2.0",
84
84
  "glob": "~8.0",
@@ -89,16 +89,16 @@
89
89
  "@types/glob": "~8.0",
90
90
  "@types/node": "~18.11",
91
91
  "@types/superagent": "~4.1",
92
- "@typescript-eslint/eslint-plugin": "~5.43",
93
- "@typescript-eslint/parser": "~5.43",
92
+ "@typescript-eslint/eslint-plugin": "~5.47",
93
+ "@typescript-eslint/parser": "~5.47",
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.28",
98
+ "eslint": "~8.31",
99
99
  "jshint": "~2.13",
100
100
  "merge-stream": "~2.0",
101
- "mocha": "~10.1",
101
+ "mocha": "~10.2",
102
102
  "rimraf": "~3.0",
103
103
  "run-scripts-util": "~0.1",
104
104
  "typescript": "~4.9"