w3c-html-validator 1.3.1 → 1.3.3

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
@@ -54,6 +54,7 @@ Command-line flags:
54
54
  | `--continue` | Report messages but do not throw an error if validation failed. | N/A |
55
55
  | `--delay` | Debounce pause in milliseconds between each file validation. | **number** |
56
56
  | `--exclude` | Comma separated list of strings to match in paths to skip. | **string** |
57
+ | `--ignore` | Skip messages containing a string or matching a RegEx. | **string** |
57
58
  | `--note` | Place to add a comment only for humans. | **string** |
58
59
  | `--quiet` | Suppress messages for successful validations. | N/A |
59
60
  | `--trim` | Truncate validation messages to not exceed a maximum length. | **number** |
@@ -62,14 +63,24 @@ Command-line flags:
62
63
  Examples:
63
64
  - `html-validator`<br>
64
65
  Validate all HTML files in the project.
66
+
65
67
  - `html-validator --exclude=build,tmp`<br>
66
68
  Slip all files which have "build" or "tmp" anywhere in their pathname or filename.
69
+
70
+ - `html-validator docs/*.html '--ignore=Trailing slash on void elements'`<br>
71
+ Allow the ugly slashes of self-closing tags despite XHTML being a hideous scourge on the web.
72
+
73
+ - `html-validator docs/*.html '--ignore=/^Duplicate ID/'`<br>
74
+ Use a RegEx (regular expression) to skip all validation messages that start with "Duplicate ID".
75
+
67
76
  - `html-validator --quiet`<br>
68
- Suppress "pass" messages.
69
- - `html-validator docs`<br>
70
- Validate HTML files in a folder.
77
+ Suppress "pass" status messages.
78
+
79
+ - `html-validator docs --delay=200`<br>
80
+ Validate all HTML files in the "docs" folder at a rate of 1 file per 200 ms (default is 500 ms).
81
+
71
82
  - `html-validator docs --trim=30 --continue`<br>
72
- Truncate messages to 30 characters and do not abort CI if validation fails.
83
+ Truncate validation messages to 30 characters and do not abort CI if validation fails.
73
84
 
74
85
  ## D) Application Code and Testing Frameworks
75
86
  In addition to the CLI interface, the **w3c-html-validator** package can also be imported and called directly in ESM and TypeScript projects.
@@ -97,13 +108,13 @@ $ node examples.js
97
108
  #### w3cHtmlValidator.validate(options)
98
109
  | Name (key) | Type | Default | Description |
99
110
  | :--------------- | :---------------------- | :------------------------------- | :------------------------------------------------------------------- |
100
- | `html` | **string** | `null` | HTML string to validate. |
101
- | `filename` | **string** | `null` | HTML file to validate. |
102
- | `website` | **string** | `null` | URL of website to validate. |
103
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. |
104
114
  | `ignoreLevel` | `'info'` or `'warning'` | `null` | Skip unwanted messages.* |
105
115
  | `ignoreMessages` | **string** or **regex** | `null` | Skip messages containing a string or matching a regular expression.* |
106
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. |
107
118
 
108
119
  *The `ignoreMessages` and `ignoreLevel` options only work for `'json'` output.&nbsp;
109
120
  Option value `'warning'` also skips `'info'`.
@@ -113,7 +124,7 @@ Option value `'warning'` also skips `'info'`.
113
124
  | :--------------- | :---------- | :------ | :-------------------------------------------------------------- |
114
125
  | `continueOnFail` | **boolean** | `false` | Report messages but do not throw an error if validation failed. |
115
126
  | `maxMessageLen` | **number** | `null` | Trim validation messages to not exceed a maximum length. |
116
- | `quiet` | **boolean** | `false` | Suppress messages for successful validations. |
127
+ | `quiet` | **boolean** | `false` | Suppress status messages for successful validations. |
117
128
  | `title` | **string** | `null` | Override display title (useful for naming HTML string inputs). |
118
129
 
119
130
  ### 3. TypeScript declarations
package/bin/cli.js CHANGED
@@ -21,22 +21,23 @@
21
21
 
22
22
  // Imports
23
23
  import { cliArgvUtil } from 'cli-argv-util';
24
+ import { globSync } from 'glob';
24
25
  import { w3cHtmlValidator } from '../dist/w3c-html-validator.js';
25
26
  import chalk from 'chalk';
26
27
  import fs from 'fs';
27
- import glob from 'glob';
28
28
  import log from 'fancy-log';
29
29
 
30
30
  // Parameters and flags
31
- const validFlags = ['continue', 'delay', 'exclude', 'note', 'quiet', 'trim'];
31
+ const validFlags = ['continue', 'delay', 'exclude', 'ignore', 'note', 'quiet', 'trim'];
32
32
  const cli = cliArgvUtil.parse(validFlags);
33
33
  const files = cli.params;
34
+ const ignore = cli.flagMap.ignore ?? null;
34
35
  const delay = parseInt(cli.flagMap.delay) || 500; //default half second debounce pause
35
36
  const trim = parseInt(cli.flagMap.trim) || null;
36
37
 
37
38
  // Validator
38
39
  const keep = (filename) => !filename.includes('node_modules/');
39
- const readFolder = (folder) => glob.sync(folder + '**/*.html', { ignore: '**/node_modules/**/*' });
40
+ const readFolder = (folder) => globSync(folder + '**/*.html', { ignore: '**/node_modules/**/*' });
40
41
  const expandFolder = (file) => fs.lstatSync(file).isDirectory() ? readFolder(file + '/') : file;
41
42
  const getFilenames = () => [...new Set(files.map(expandFolder).flat().filter(keep))].sort();
42
43
  const list = files.length ? getFilenames() : readFolder('');
@@ -56,6 +57,9 @@ const reporterOptions = {
56
57
  quiet: cli.flagOn.quiet,
57
58
  maxMessageLen: trim,
58
59
  };
60
+ const slashed = /^\/.*\/$/; //starts and ends with a slash indicating it's a regex
61
+ const skip = slashed.test(ignore) ? new RegExp(ignore.slice(1, -1)) : ignore;
59
62
  const handleReport = (report) => w3cHtmlValidator.reporter(report, reporterOptions);
60
- const getReport = (file) => w3cHtmlValidator.validate({ filename: file }).then(handleReport);
61
- filenames.forEach((file, i) => globalThis.setTimeout(() => getReport(file), i * delay));
63
+ const options = (file) => ({ filename: file, ignoreMessages: skip });
64
+ const getReport = (file) => w3cHtmlValidator.validate(options(file)).then(handleReport);
65
+ filenames.forEach((filename, i) => globalThis.setTimeout(() => getReport(filename), i * delay));
@@ -1,4 +1,4 @@
1
- //! w3c-html-validator v1.3.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v1.3.3 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
2
2
 
3
3
  export type ValidatorSettings = {
4
4
  html: string;
@@ -1,11 +1,11 @@
1
- //! w3c-html-validator v1.3.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v1.3.3 ~~ 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.3.1',
8
+ version: '1.3.3',
9
9
  validate(options) {
10
10
  var _a;
11
11
  const defaults = {
@@ -102,7 +102,7 @@ const w3cHtmlValidator = {
102
102
  };
103
103
  const logMessage = (message) => {
104
104
  var _a, _b, _c, _d;
105
- const type = (_a = message.subType) !== null && _a !== void 0 ? _a : message.type;
105
+ const type = ((_a = message.subType) !== null && _a !== void 0 ? _a : message.type);
106
106
  const typeColor = (_b = typeColorMap[type]) !== null && _b !== void 0 ? _b : chalk.redBright.bold;
107
107
  const location = `line ${message.lastLine}, column ${message.firstColumn}:`;
108
108
  const lineText = (_c = message.extract) === null || _c === void 0 ? void 0 : _c.replace(/\n/g, '\\n');
@@ -1,4 +1,4 @@
1
- //! w3c-html-validator v1.3.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v1.3.3 ~~ 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.3.1',
23
+ version: '1.3.3',
24
24
  validate(options) {
25
25
  var _a;
26
26
  const defaults = {
@@ -117,7 +117,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
117
117
  };
118
118
  const logMessage = (message) => {
119
119
  var _a, _b, _c, _d;
120
- const type = (_a = message.subType) !== null && _a !== void 0 ? _a : message.type;
120
+ const type = ((_a = message.subType) !== null && _a !== void 0 ? _a : message.type);
121
121
  const typeColor = (_b = typeColorMap[type]) !== null && _b !== void 0 ? _b : chalk_1.default.redBright.bold;
122
122
  const location = `line ${message.lastLine}, column ${message.firstColumn}:`;
123
123
  const lineText = (_c = message.extract) === null || _c === void 0 ? void 0 : _c.replace(/\n/g, '\\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "w3c-html-validator",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "Check the markup validity of HTML files using the W3C validator",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -63,7 +63,7 @@
63
63
  },
64
64
  "runScriptsConfig": {
65
65
  "build": [
66
- "rimraf build dist **/.DS_Store",
66
+ "rimraf build dist",
67
67
  "jshint . --exclude-path .gitignore",
68
68
  "eslint --max-warnings 0 . --ext .ts",
69
69
  "tsc",
@@ -79,28 +79,28 @@
79
79
  },
80
80
  "dependencies": {
81
81
  "chalk": "~5.2",
82
- "cli-argv-util": "~0.1",
82
+ "cli-argv-util": "~1.0",
83
83
  "fancy-log": "~2.0",
84
- "glob": "~8.1",
84
+ "glob": "~9.3",
85
85
  "superagent": "~8.0"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@types/fancy-log": "~2.0",
89
- "@types/glob": "~8.0",
90
- "@types/node": "~18.13",
89
+ "@types/glob": "~8.1",
90
+ "@types/node": "~18.15",
91
91
  "@types/superagent": "~4.1",
92
- "@typescript-eslint/eslint-plugin": "~5.51",
93
- "@typescript-eslint/parser": "~5.51",
94
- "add-dist-header": "~0.3",
92
+ "@typescript-eslint/eslint-plugin": "~5.55",
93
+ "@typescript-eslint/parser": "~5.55",
94
+ "add-dist-header": "~1.0",
95
95
  "assert-deep-strict-equal": "~1.0",
96
- "copy-file-util": "~0.1",
97
- "copy-folder-util": "~0.2",
98
- "eslint": "~8.33",
96
+ "copy-file-util": "~1.0",
97
+ "copy-folder-util": "~1.0",
98
+ "eslint": "~8.36",
99
99
  "jshint": "~2.13",
100
100
  "merge-stream": "~2.0",
101
101
  "mocha": "~10.2",
102
- "rimraf": "3",
103
- "run-scripts-util": "~0.1",
104
- "typescript": "~4.9"
102
+ "rimraf": "~4.4",
103
+ "run-scripts-util": "~1.0",
104
+ "typescript": "~5.0"
105
105
  }
106
106
  }