w3c-html-validator 1.7.0 → 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,7 +5,7 @@ _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
11
  The reporter produces formatted output indented for use in build scripts and test suites.
@@ -141,6 +141,7 @@ $ node examples.js
141
141
  | `ignoreLevel` | `'info'` or `'warning'` | `null` | Skip unwanted messages.* |
142
142
  | `ignoreMessages` | **array** | `[]` | Skip messages containing a string or matching a regex.* |
143
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). |
144
145
  | `website` | **string** | `null` | URL of website to validate. |
145
146
 
146
147
  *The `ignoreMessages` and `ignoreLevel` options only work for `'json'` output. 
@@ -171,6 +172,7 @@ type ValidatorResults = {
171
172
  status: number,
172
173
  messages: ValidatorResultsMessage[] | null, //for 'json' output
173
174
  display: string | null, //for 'html' output
175
+ skip: boolean,
174
176
  };
175
177
  ```
176
178
 
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
  };
77
+ const baseOptions = { ignoreMessages: getIgnoreMessages(), skip: skip };
78
+ const options = (filename) => ({ filename: filename, ...baseOptions });
74
79
  const handleResults = (results) => w3cHtmlValidator.reporter(results, reporterOptions);
75
- const options = (filename) => ({ filename: filename, ignoreMessages: getIgnoreMessages() });
76
80
  const getReport = (filename) => w3cHtmlValidator.validate(options(filename)).then(handleResults);
77
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.7.0 ~~ 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.7.0 ~~ 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.7.0',
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,6 +61,7 @@ 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
67
  const errRes = reason.response ?? {};
@@ -68,7 +70,17 @@ const w3cHtmlValidator = {
68
70
  errRes.body = { messages: [{ type: 'network-error', message: message.join(' ') }] };
69
71
  return toValidatorResults(errRes);
70
72
  };
71
- 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'));
72
84
  },
73
85
  summary(numFiles) {
74
86
  log(chalk.gray('w3c-html-validator'), chalk.magenta('files: ' + numFiles));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "w3c-html-validator",
3
- "version": "1.7.0",
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",
@@ -81,22 +81,22 @@
81
81
  "fancy-log": "~2.0",
82
82
  "glob": "~10.3",
83
83
  "slash": "~5.1",
84
- "superagent": "~8.1"
84
+ "superagent": "~9.0"
85
85
  },
86
86
  "devDependencies": {
87
87
  "@types/fancy-log": "~2.0",
88
- "@types/node": "~20.11",
88
+ "@types/node": "~20.12",
89
89
  "@types/superagent": "~8.1",
90
- "@typescript-eslint/eslint-plugin": "~7.3",
91
- "@typescript-eslint/parser": "~7.3",
90
+ "@typescript-eslint/eslint-plugin": "~7.7",
91
+ "@typescript-eslint/parser": "~7.7",
92
92
  "add-dist-header": "~1.4",
93
93
  "assert-deep-strict-equal": "~1.2",
94
94
  "copy-file-util": "~1.2",
95
95
  "copy-folder-util": "~1.1",
96
- "eslint": "~8.57",
96
+ "eslint": "8.57.0",
97
97
  "jshint": "~2.13",
98
98
  "merge-stream": "~2.0",
99
- "mocha": "~10.3",
99
+ "mocha": "~10.4",
100
100
  "rimraf": "~5.0",
101
101
  "run-scripts-util": "~1.2",
102
102
  "typescript": "~5.4"