w3c-html-validator 1.6.4 → 1.8.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
@@ -5,10 +5,10 @@ _Check the markup validity of HTML files using the W3C validator_
5
5
 
6
6
  [![License:MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/center-key/w3c-html-validator/blob/main/LICENSE.txt)
7
7
  [![npm](https://img.shields.io/npm/v/w3c-html-validator.svg)](https://www.npmjs.com/package/w3c-html-validator)
8
- [![Build](https://github.com/center-key/w3c-html-validator/workflows/build/badge.svg)](https://github.com/center-key/w3c-html-validator/actions/workflows/run-spec-on-push.yaml)
8
+ [![Build](https://github.com/center-key/w3c-html-validator/actions/workflows/run-spec-on-push.yaml/badge.svg)](https://github.com/center-key/w3c-html-validator/actions/workflows/run-spec-on-push.yaml)
9
9
 
10
10
  **w3c-html-validator** takes HTML files and returns detailed validation results. 
11
- The reporter produces formatted output indended for use in build scripts and test suites.
11
+ The reporter produces formatted output indented for use in build scripts and test suites.
12
12
 
13
13
  <img src=https://raw.githubusercontent.com/center-key/w3c-html-validator/main/examples.png
14
14
  width=800 alt=screenshot>
@@ -20,7 +20,7 @@ $ npm install --save-dev w3c-html-validator
20
20
  ```
21
21
 
22
22
  ## B) Usage
23
- ### 1. npm scripts
23
+ ### 1. npm package.json scripts
24
24
  Run `html-validator` from the `"scripts"` section of your **package.json** file.
25
25
 
26
26
  The parameters are folders and files to be validated.
@@ -110,6 +110,8 @@ The dot (`.`) regex operator says to match any one character, which is a handy w
110
110
  ## D) Application Code and Testing Frameworks
111
111
  In addition to the CLI interface, the **w3c-html-validator** package can also be imported and called directly in ESM and TypeScript projects.
112
112
 
113
+ Note that if your application calls `w3cHtmlValidator.validate()` multiple times, you must throttle (debounce) the calls or risk getting rejected by the W3C server.
114
+
113
115
  ### 1. Import
114
116
  Example call to the `validate()` function:
115
117
  ```typescript
@@ -139,12 +141,13 @@ $ node examples.js
139
141
  | `ignoreLevel` | `'info'` or `'warning'` | `null` | Skip unwanted messages.* |
140
142
  | `ignoreMessages` | **array** | `[]` | Skip messages containing a string or matching a regex.* |
141
143
  | `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). |
142
145
  | `website` | **string** | `null` | URL of website to validate. |
143
146
 
144
147
  *The `ignoreMessages` and `ignoreLevel` options only work for `'json'` output.&nbsp;
145
148
  Setting `ignoreLevel` to `'warning'` skips both `'warning'` level and `'info'` level validation messages.
146
149
 
147
- #### w3cHtmlValidator.reporter(options)
150
+ #### w3cHtmlValidator.reporter(results, options)
148
151
  | Name (key) | Type | Default | Description |
149
152
  | :--------------- | :---------- | :------ | :-------------------------------------------------------------- |
150
153
  | `continueOnFail` | **boolean** | `false` | Report messages but do not throw an error if validation failed. |
@@ -169,6 +172,7 @@ type ValidatorResults = {
169
172
  status: number,
170
173
  messages: ValidatorResultsMessage[] | null, //for 'json' output
171
174
  display: string | null, //for 'html' output
175
+ skip: boolean,
172
176
  };
173
177
  ```
174
178
 
@@ -202,7 +206,7 @@ describe('Home page', () => {
202
206
  - 🪺 [recursive-exec](https://github.com/center-key/recursive-exec):&nbsp; _Run a command on each file in a folder and its subfolders_
203
207
  - 🔍 [replacer-util](https://github.com/center-key/replacer-util):&nbsp; _Find and replace strings or template outputs in text files_
204
208
  - 🔢 [rev-web-assets](https://github.com/center-key/rev-web-assets):&nbsp; _Revision web asset filenames with cache busting content hash fingerprints_
205
- - 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util):&nbsp; _Organize npm scripts into named groups of easy to manage commands_
209
+ - 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util):&nbsp; _Organize npm package.json scripts into named groups of easy to manage commands_
206
210
  - 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator):&nbsp; _Check the markup validity of HTML files using the W3C validator_
207
211
 
208
212
  Feel free to submit questions at:<br>
package/bin/cli.js CHANGED
@@ -36,6 +36,7 @@ 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 skip = process.env.w3cHtmlValidator === 'skip'; //bash: export w3cHtmlValidator=skip
39
40
 
40
41
  // Validator
41
42
  const globOptions = { ignore: '**/node_modules/**/*' };
@@ -54,6 +55,8 @@ const error =
54
55
  null;
55
56
  if (error)
56
57
  throw Error('[w3c-html-validator] ' + error);
58
+ if (skip)
59
+ w3cHtmlValidator.skipNotice();
57
60
  if (filenames.length > 1 && !cli.flagOn.quiet)
58
61
  w3cHtmlValidator.summary(filenames.length);
59
62
  const reporterOptions = {
@@ -71,8 +74,9 @@ const getIgnoreMessages = () => {
71
74
  const isRegex = /^\/.*\/$/; //starts and ends with a slash indicating it's a regex
72
75
  return rawLines.map(line => isRegex.test(line) ? new RegExp(line.slice(1, -1)) : line);
73
76
  };
74
- const handleReport = (report) => w3cHtmlValidator.reporter(report, reporterOptions);
75
- const options = (filename) => ({ filename: filename, ignoreMessages: getIgnoreMessages() });
76
- const getReport = (filename) => w3cHtmlValidator.validate(options(filename)).then(handleReport);
77
- const processFile = (filename, i) => globalThis.setTimeout(() => getReport(filename), i * delay);
77
+ const baseOptions = { ignoreMessages: getIgnoreMessages(), skip: skip };
78
+ const options = (filename) => ({ filename: filename, ...baseOptions });
79
+ const handleResults = (results) => w3cHtmlValidator.reporter(results, reporterOptions);
80
+ const getReport = (filename) => w3cHtmlValidator.validate(options(filename)).then(handleResults);
81
+ const processFile = (filename, i) => globalThis.setTimeout(() => getReport(filename), i * delay);
78
82
  filenames.forEach(processFile);
@@ -1,4 +1,4 @@
1
- //! w3c-html-validator v1.6.4 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v1.8.0 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
2
2
 
3
3
  export type ValidatorSettings = {
4
4
  html: string;
@@ -8,6 +8,7 @@ export type ValidatorSettings = {
8
8
  ignoreLevel: 'info' | 'warning';
9
9
  ignoreMessages: (string | RegExp)[];
10
10
  output: ValidatorResultsOutput;
11
+ skip: boolean;
11
12
  };
12
13
  export type ValidatorResultsMessage = {
13
14
  type: 'info' | 'error' | 'non-document-error' | 'network-error';
@@ -33,6 +34,7 @@ export type ValidatorResults = {
33
34
  status: number;
34
35
  messages: ValidatorResultsMessage[] | null;
35
36
  display: string | null;
37
+ skip: boolean;
36
38
  };
37
39
  export type ValidatorResultsOutput = ValidatorResults['output'];
38
40
  export type ReporterSettings = {
@@ -44,6 +46,7 @@ export type ReporterSettings = {
44
46
  declare const w3cHtmlValidator: {
45
47
  version: string;
46
48
  validate(options: Partial<ValidatorSettings>): Promise<ValidatorResults>;
49
+ skipNotice(): void;
47
50
  summary(numFiles: number): void;
48
51
  reporter(results: ValidatorResults, options?: Partial<ReporterSettings>): ValidatorResults;
49
52
  };
@@ -1,4 +1,4 @@
1
- //! w3c-html-validator v1.6.4 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v1.8.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';
@@ -6,13 +6,14 @@ import log from 'fancy-log';
6
6
  import request from 'superagent';
7
7
  import slash from 'slash';
8
8
  const w3cHtmlValidator = {
9
- version: '1.6.4',
9
+ version: '1.8.0',
10
10
  validate(options) {
11
11
  const defaults = {
12
12
  checkUrl: 'https://validator.w3.org/nu/',
13
13
  ignoreLevel: null,
14
14
  ignoreMessages: [],
15
15
  output: 'json',
16
+ skip: false,
16
17
  };
17
18
  const settings = { ...defaults, ...options };
18
19
  if (!settings.html && !settings.filename && !settings.website)
@@ -60,16 +61,26 @@ const w3cHtmlValidator = {
60
61
  status: response.statusCode || -1,
61
62
  messages: json ? response.body.messages : null,
62
63
  display: json ? null : response.text,
64
+ skip: settings.skip,
63
65
  });
64
66
  const handleError = (reason) => {
65
- const response = reason.response;
66
- const getMsg = () => [response.status, response.res.statusMessage, response.request.url];
67
- const message = response ? getMsg() : [reason.errno, reason.message];
68
- const errRes = response ?? {};
67
+ const errRes = reason.response ?? {};
68
+ const getMsg = () => [errRes.status, errRes.res.statusMessage, errRes.request.url];
69
+ const message = reason.response ? getMsg() : [reason.errno, reason.message];
69
70
  errRes.body = { messages: [{ type: 'network-error', message: message.join(' ') }] };
70
71
  return toValidatorResults(errRes);
71
72
  };
72
- return w3cRequest.then(filterMessages).then(toValidatorResults).catch(handleError);
73
+ const pseudoResponse = {
74
+ statusCode: 200,
75
+ body: { messages: [] },
76
+ text: 'Validation skipped.',
77
+ };
78
+ const pseudoRequest = () => new Promise(resolve => resolve(pseudoResponse));
79
+ const validation = settings.skip ? pseudoRequest() : w3cRequest;
80
+ return validation.then(filterMessages).then(toValidatorResults).catch(handleError);
81
+ },
82
+ skipNotice() {
83
+ log(chalk.gray('w3c-html-validator'), chalk.yellowBright('skip mode:'), chalk.whiteBright('validation being bypassed'));
73
84
  },
74
85
  summary(numFiles) {
75
86
  log(chalk.gray('w3c-html-validator'), chalk.magenta('files: ' + numFiles));
package/package.json CHANGED
@@ -1,21 +1,15 @@
1
1
  {
2
2
  "name": "w3c-html-validator",
3
- "version": "1.6.4",
3
+ "version": "1.8.0",
4
4
  "description": "Check the markup validity of HTML files using the W3C validator",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "module": "dist/w3c-html-validator.js",
8
- "main": "dist/w3c-html-validator.js",
9
8
  "types": "dist/w3c-html-validator.d.ts",
9
+ "exports": "./dist/w3c-html-validator.js",
10
10
  "files": [
11
11
  "dist"
12
12
  ],
13
- "exports": {
14
- ".": {
15
- "import": "./dist/w3c-html-validator.js"
16
- },
17
- "./": "./dist/"
18
- },
19
13
  "bin": {
20
14
  "html-validator": "bin/cli.js",
21
15
  "w3c-html-validator": "bin/cli.js"
@@ -87,24 +81,24 @@
87
81
  "fancy-log": "~2.0",
88
82
  "glob": "~10.3",
89
83
  "slash": "~5.1",
90
- "superagent": "~8.1"
84
+ "superagent": "~9.0"
91
85
  },
92
86
  "devDependencies": {
93
87
  "@types/fancy-log": "~2.0",
94
- "@types/node": "~20.10",
88
+ "@types/node": "~20.12",
95
89
  "@types/superagent": "~8.1",
96
- "@typescript-eslint/eslint-plugin": "~6.17",
97
- "@typescript-eslint/parser": "~6.17",
98
- "add-dist-header": "~1.3",
99
- "assert-deep-strict-equal": "~1.1",
100
- "copy-file-util": "~1.1",
90
+ "@typescript-eslint/eslint-plugin": "~7.7",
91
+ "@typescript-eslint/parser": "~7.7",
92
+ "add-dist-header": "~1.4",
93
+ "assert-deep-strict-equal": "~1.2",
94
+ "copy-file-util": "~1.2",
101
95
  "copy-folder-util": "~1.1",
102
- "eslint": "~8.56",
96
+ "eslint": "8.57.0",
103
97
  "jshint": "~2.13",
104
98
  "merge-stream": "~2.0",
105
- "mocha": "~10.2",
99
+ "mocha": "~10.4",
106
100
  "rimraf": "~5.0",
107
101
  "run-scripts-util": "~1.2",
108
- "typescript": "~5.3"
102
+ "typescript": "~5.4"
109
103
  }
110
104
  }