w3c-html-validator 2.2.1 → 2.2.2

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
@@ -192,6 +192,7 @@ type ValidatorResults = {
192
192
  mode: 'html' | 'filename' | 'website';
193
193
  html: string | null,
194
194
  filename: string | null,
195
+ fileCount: number | null,
195
196
  website: string | null,
196
197
  output: 'json' | 'html',
197
198
  status: number,
@@ -224,17 +225,16 @@ describe('Home page', () => {
224
225
  <br>
225
226
 
226
227
  ---
227
- **CLI Build Tools for package.json**
228
- - 🎋 [add-dist-header](https://github.com/center-key/add-dist-header):&nbsp; _Prepend a one-line banner comment (with license notice) to distribution files_
229
- - 📄 [copy-file-util](https://github.com/center-key/copy-file-util):&nbsp; _Copy or rename a file with optional package version number_
230
- - 📂 [copy-folder-util](https://github.com/center-key/copy-folder-util):&nbsp; _Recursively copy files from one folder to another folder_
231
- - 🪺 [recursive-exec](https://github.com/center-key/recursive-exec):&nbsp; _Run a command on each file in a folder and its subfolders_
232
- - 🔍 [replacer-util](https://github.com/center-key/replacer-util):&nbsp; _Find and replace strings or template outputs in text files_
233
- - 🔢 [rev-web-assets](https://github.com/center-key/rev-web-assets):&nbsp; _Revision web asset filenames with cache busting content hash fingerprints_
234
- - 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util):&nbsp; _Organize npm package.json scripts into groups of easy to manage commands_
235
- - 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator):&nbsp; _Check the markup validity of HTML files using the W3C validator_
236
-
237
- Feel free to submit questions at:<br>
238
- [github.com/center-key/w3c-html-validator/issues](https://github.com/center-key/w3c-html-validator/issues)
239
-
240
228
  [MIT License](LICENSE.txt)
229
+
230
+ [🛡️ npm Security Aggregator](https://center-key.github.io/npm-security-aggregator/?package=w3c-html-validator)
231
+
232
+ See the `runScriptsConfig` section of [`package.json`](package.json) for a clean way to organize build tasks:
233
+ - 🎋 [`add-dist-header`](https://github.com/center-key/add-dist-header) &mdash;&nbsp; _Prepend a one-line banner comment (with license notice) to distribution files_
234
+ - 📄 [`copy-file-util`](https://github.com/center-key/copy-file-util) &mdash;&nbsp; _Copy or rename a file with optional package version number_
235
+ - 📂 [`copy-folder-util`](https://github.com/center-key/copy-folder-util) &mdash;&nbsp; _Recursively copy files from one folder to another folder_
236
+ - 🪺 [`recursive-exec`](https://github.com/center-key/recursive-exec) &mdash;&nbsp; _Run a command on each file in a folder and its subfolders_
237
+ - 🔍 [`replacer-util`](https://github.com/center-key/replacer-util) &mdash;&nbsp; _Find and replace strings or template outputs in text files_
238
+ - 🔢 [`rev-web-assets`](https://github.com/center-key/rev-web-assets) &mdash;&nbsp; _Revision web asset filenames with cache busting content hash fingerprints_
239
+ - 🚆 [`run-scripts-util`](https://github.com/center-key/run-scripts-util) &mdash;&nbsp; _Organize npm package.json scripts into groups of easy-to-manage commands_
240
+ - 🚦 [`w3c-html-validator`](https://github.com/center-key/w3c-html-validator) &mdash;&nbsp; _Check the markup validity of HTML files using the W3C validator_
@@ -1,8 +1,9 @@
1
- //! w3c-html-validator v2.2.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v2.2.2 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
2
2
 
3
3
  export type ValidatorSettings = {
4
4
  html: string | null;
5
5
  filename: string | null;
6
+ fileCount: number | null;
6
7
  website: string | null;
7
8
  checkUrl: string | null;
8
9
  ignoreLevel: 'info' | 'warning' | null;
@@ -31,6 +32,7 @@ export type ValidatorResults = {
31
32
  title: string;
32
33
  html: string | null;
33
34
  filename: string | null;
35
+ fileCount: number | null;
34
36
  website: string | null;
35
37
  output: 'json' | 'html';
36
38
  status: number;
@@ -48,11 +50,9 @@ declare const w3cHtmlValidator: {
48
50
  version: string;
49
51
  checkUrl: string;
50
52
  defaultIgnoreList: string[];
51
- assert(ok: unknown, message: string | null): void;
53
+ assertOk(ok: unknown, message: string | null): void;
52
54
  cli(): void;
53
55
  validate(options: Partial<ValidatorSettings>): Promise<ValidatorResults>;
54
- dryRunNotice(): void;
55
- summary(numFiles: number): void;
56
56
  reporter(results: ValidatorResults, options?: Partial<ReporterSettings>): ValidatorResults;
57
57
  };
58
58
  export { w3cHtmlValidator };
@@ -1,4 +1,4 @@
1
- //! w3c-html-validator v2.2.1 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v2.2.2 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
2
2
 
3
3
  import { cliArgvUtil } from 'cli-argv-util';
4
4
  import { globSync } from 'glob';
@@ -8,13 +8,13 @@ import log from 'fancy-log';
8
8
  import request from 'superagent';
9
9
  import slash from 'slash';
10
10
  const w3cHtmlValidator = {
11
- version: '2.2.1',
11
+ version: '2.2.2',
12
12
  checkUrl: 'https://validator.w3.org/nu/',
13
13
  defaultIgnoreList: [
14
14
  'with computed level',
15
15
  'Section lacks heading.',
16
16
  ],
17
- assert(ok, message) {
17
+ assertOk(ok, message) {
18
18
  if (!ok)
19
19
  throw new Error(`[w3c-html-validator] ${message}`);
20
20
  },
@@ -24,7 +24,7 @@ const w3cHtmlValidator = {
24
24
  const cli = cliArgvUtil.parse(validFlags);
25
25
  const files = cli.params.length ? cli.params.map(cliArgvUtil.cleanPath) : ['.'];
26
26
  const checkUrl = cli.flagMap.checkUrl ?? w3cHtmlValidator.checkUrl;
27
- const excludeList = cli.flagMap.exclude?.split(',') ?? [];
27
+ const excludes = cli.flagMap.exclude?.split(',') ?? [];
28
28
  const ignore = cli.flagMap.ignore ?? null;
29
29
  const ignoreConfig = cli.flagMap.ignoreConfig ?? null;
30
30
  const defaultRules = cli.flagOn.defaultRules;
@@ -32,10 +32,12 @@ const w3cHtmlValidator = {
32
32
  const trim = Number(cli.flagMap.trim) || null;
33
33
  const dryRun = cli.flagOn.dryRun || process.env.w3cHtmlValidator === 'dry-run';
34
34
  const getFilenames = () => {
35
- const readFilenames = (file) => globSync(file, { ignore: '**/node_modules/**/*' }).map(slash);
35
+ const globOptions = { ignore: '**/node_modules/**/*' };
36
+ const readFilenames = (file) => globSync(file, globOptions).map(slash);
37
+ const isFolder = (folder) => fs.lstatSync(folder).isDirectory();
36
38
  const readHtmlFiles = (folder) => readFilenames(folder + '/**/*.html');
37
- const addHtml = (file) => fs.lstatSync(file).isDirectory() ? readHtmlFiles(file) : file;
38
- const keep = (file) => excludeList.every(exclude => !file.includes(exclude));
39
+ const addHtml = (file) => isFolder(file) ? readHtmlFiles(file) : file;
40
+ const keep = (file) => excludes.every(exclude => !file.includes(exclude));
39
41
  return files.map(readFilenames).flat().map(addHtml).flat().filter(keep).sort();
40
42
  };
41
43
  const filenames = getFilenames();
@@ -43,11 +45,13 @@ const w3cHtmlValidator = {
43
45
  !filenames.length ? 'No files to validate.' :
44
46
  cli.flagOn.trim && !trim ? 'Value of "trim" must be a positive whole number.' :
45
47
  null;
46
- w3cHtmlValidator.assert(!error, error);
47
- if (dryRun)
48
- w3cHtmlValidator.dryRunNotice();
49
- if (filenames.length > 1 && !cli.flagOn.quiet)
50
- w3cHtmlValidator.summary(filenames.length);
48
+ w3cHtmlValidator.assertOk(!error, error);
49
+ const name = chalk.gray('w3c-html-validator');
50
+ const version = chalk.gray('v' + w3cHtmlValidator.version);
51
+ const summary = chalk.white(`(files: ${filenames.length})`);
52
+ const warning = dryRun ? chalk.yellowBright('[dry run mode - skipping validation]') : '';
53
+ if (!cli.flagOn.quiet || dryRun)
54
+ log(name, version, checkUrl, summary, warning);
51
55
  const reporterOptions = {
52
56
  continueOnFail: cli.flagOn.continue,
53
57
  maxMessageLen: trim,
@@ -65,10 +69,10 @@ const w3cHtmlValidator = {
65
69
  return rawLines.map(line => isRegex.test(line) ? new RegExp(line.slice(1, -1)) : line);
66
70
  };
67
71
  const ignoreMessages = getIgnoreMessages();
68
- const options = (filename) => ({ filename, checkUrl, ignoreMessages, defaultRules, dryRun });
72
+ const options = (filename, fileCount) => ({ filename, fileCount, checkUrl, ignoreMessages, defaultRules, dryRun });
69
73
  const handleResults = (results) => w3cHtmlValidator.reporter(results, reporterOptions);
70
- const getReport = (filename) => w3cHtmlValidator.validate(options(filename)).then(handleResults);
71
- const processFile = (filename, i) => globalThis.setTimeout(() => getReport(filename), i * delay);
74
+ const getReport = (filename, fileCount) => w3cHtmlValidator.validate(options(filename, fileCount)).then(handleResults);
75
+ const processFile = (filename, index) => globalThis.setTimeout(() => getReport(filename, index + 1), index * delay);
72
76
  filenames.forEach(processFile);
73
77
  },
74
78
  validate(options) {
@@ -77,6 +81,7 @@ const w3cHtmlValidator = {
77
81
  defaultRules: false,
78
82
  dryRun: false,
79
83
  filename: null,
84
+ fileCount: null,
80
85
  html: null,
81
86
  ignoreLevel: null,
82
87
  ignoreMessages: [],
@@ -91,7 +96,7 @@ const w3cHtmlValidator = {
91
96
  badLevel ? `Invalid ignoreLevel option: ${settings.ignoreLevel}` :
92
97
  invalidOutput ? 'Option "output" must be "json" or "html".' :
93
98
  null;
94
- w3cHtmlValidator.assert(!error, error);
99
+ w3cHtmlValidator.assertOk(!error, error);
95
100
  const filename = settings.filename ? slash(settings.filename) : null;
96
101
  const mode = settings.html ? 'html' : filename ? 'filename' : 'website';
97
102
  const unixify = (text) => text.replace(/\r/g, '');
@@ -131,6 +136,7 @@ const w3cHtmlValidator = {
131
136
  title: titleLookup[mode],
132
137
  html: inputHtml,
133
138
  filename: filename,
139
+ fileCount: settings.fileCount,
134
140
  website: settings.website || null,
135
141
  output: settings.output,
136
142
  status: response.statusCode || -1,
@@ -154,12 +160,6 @@ const w3cHtmlValidator = {
154
160
  const validation = settings.dryRun ? pseudoRequest() : w3cRequest;
155
161
  return validation.then(filterMessages).then(toValidatorResults).catch(handleError);
156
162
  },
157
- dryRunNotice() {
158
- log(chalk.gray('w3c-html-validator'), chalk.yellowBright('dry run mode:'), chalk.whiteBright('skipping validation'));
159
- },
160
- summary(numFiles) {
161
- log(chalk.gray('w3c-html-validator'), chalk.magenta('files: ' + String(numFiles)));
162
- },
163
163
  reporter(results, options) {
164
164
  const defaults = {
165
165
  continueOnFail: false,
@@ -168,14 +168,16 @@ const w3cHtmlValidator = {
168
168
  title: null,
169
169
  };
170
170
  const settings = { ...defaults, ...options };
171
+ const name = chalk.gray('w3c-html-validator');
172
+ const fileCount = results.fileCount ? chalk.magenta(results.fileCount) + ' ' : '';
171
173
  const hasResults = 'validates' in results && typeof results.validates === 'boolean';
172
- w3cHtmlValidator.assert(hasResults, `Invalid results for reporter(): ${results}`);
174
+ w3cHtmlValidator.assertOk(hasResults, `Invalid results for reporter(): ${results}`);
173
175
  const messages = results.messages ?? [];
174
176
  const title = settings.title ?? results.title;
175
177
  const status = results.validates ? chalk.green.bold('✔ pass') : chalk.red.bold('✘ fail');
176
178
  const count = results.validates ? '' : `(messages: ${messages.length})`;
177
- if (!results.validates || !settings.quiet)
178
- log(chalk.gray('w3c-html-validator'), status, chalk.blue.bold(title), chalk.white(count));
179
+ if (!results.validates || !settings.quiet || results.dryRun)
180
+ log(name, status, fileCount + chalk.blue.bold(title), chalk.white(count));
179
181
  const typeColorMap = {
180
182
  error: chalk.red.bold,
181
183
  warning: chalk.yellow.bold,
@@ -198,7 +200,7 @@ const w3cHtmlValidator = {
198
200
  return !results.filename ? results.messages[0].message : fileDetails();
199
201
  };
200
202
  const failed = !settings.continueOnFail && !results.validates;
201
- w3cHtmlValidator.assert(!failed, `Failed: ${failDetails()}`);
203
+ w3cHtmlValidator.assertOk(!failed, `Failed: ${failDetails()}`);
202
204
  return results;
203
205
  },
204
206
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "w3c-html-validator",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "Check the markup validity of HTML files using the W3C validator",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -67,18 +67,18 @@
67
67
  "devDependencies": {
68
68
  "@eslint/js": "~10.0",
69
69
  "@types/fancy-log": "~2.0",
70
- "@types/node": "~25.9",
70
+ "@types/node": "~26.0",
71
71
  "@types/superagent": "~8.1",
72
72
  "add-dist-header": "~1.6",
73
73
  "assert-deep-strict-equal": "~1.2",
74
74
  "copy-file-util": "~1.3",
75
75
  "copy-folder-util": "~1.2",
76
- "eslint": "~10.4",
76
+ "eslint": "~10.6",
77
77
  "jshint": "~2.13",
78
78
  "mocha": "~11.7",
79
79
  "rimraf": "~6.1",
80
80
  "run-scripts-util": "~1.3",
81
81
  "typescript": "~6.0",
82
- "typescript-eslint": "~8.59"
82
+ "typescript-eslint": "~8.62"
83
83
  }
84
84
  }