w3c-html-validator 1.6.0 → 1.6.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
@@ -78,7 +78,7 @@ Examples:
78
78
  Uses a regex with "or" operators (`|`) to skip multiple HTML validation messages.
79
79
 
80
80
  - `html-validator docs --ignore-config=spec/ignore-config.txt`<br>
81
- Similar to the pervious command but strings and regexes are stored in a configuration file (see the _Ignore Configuration File_ section below).
81
+ Similar to the pervious command but strings and regexes are stored in a configuration file (see the _Configuration File for Ignore Patterns_ section below).
82
82
 
83
83
  - `html-validator --quiet`<br>
84
84
  Suppresses all the "pass" status messages.
@@ -91,7 +91,7 @@ Examples:
91
91
 
92
92
  _**Note:** Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows._
93
93
 
94
- ### 5. Ignore Configuration File
94
+ ### 5. Configuration File for Ignore Patterns
95
95
  The optional `--ignore-config=FILENAME` flag specifies a configuration file with one string or regex per line.&nbsp;
96
96
  HTML validation messages containing any of the strings or matching any of the regexes will be skipped.&nbsp;
97
97
  Empty lines and lines starting with a hash sign (`#`) are treated as comments and do nothing.
package/bin/cli.js CHANGED
@@ -26,6 +26,7 @@ import { cliArgvUtil } from 'cli-argv-util';
26
26
  import { globSync } from 'glob';
27
27
  import { w3cHtmlValidator } from '../dist/w3c-html-validator.js';
28
28
  import fs from 'fs';
29
+ import slash from 'slash';
29
30
 
30
31
  // Parameters and flags
31
32
  const validFlags = ['continue', 'delay', 'exclude', 'ignore', 'ignore-config', 'note', 'quiet', 'trim'];
@@ -39,9 +40,9 @@ const trim = Number(cli.flagMap.trim) || null;
39
40
  // Validator
40
41
  const globOptions = { ignore: '**/node_modules/**/*' };
41
42
  const keep = (filename) => !filename.includes('node_modules/');
42
- const readFolder = (folder) => globSync(folder + '**/*.html', globOptions);
43
+ const readFolder = (folder) => globSync(slash(folder + '**/*.html'), globOptions);
44
+ const getAllPaths = () => files.map(file => globSync(slash(file), globOptions)).flat();
43
45
  const expandFolder = (file) => fs.lstatSync(file).isDirectory() ? readFolder(file + '/') : file;
44
- const getAllPaths = () => files.map(file => globSync(file, globOptions)).flat();
45
46
  const getFilenames = () => getAllPaths().map(expandFolder).flat().filter(keep).sort();
46
47
  const list = files.length ? getFilenames() : readFolder('');
47
48
  const excludes = cli.flagMap.exclude?.split(',') ?? [];
@@ -1,4 +1,4 @@
1
- //! w3c-html-validator v1.6.0 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v1.6.2 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
2
2
 
3
3
  export type ValidatorSettings = {
4
4
  html: string;
@@ -1,11 +1,12 @@
1
- //! w3c-html-validator v1.6.0 ~~ https://github.com/center-key/w3c-html-validator ~~ MIT License
1
+ //! w3c-html-validator v1.6.2 ~~ 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
+ import slash from 'slash';
7
8
  const w3cHtmlValidator = {
8
- version: '1.6.0',
9
+ version: '1.6.2',
9
10
  validate(options) {
10
11
  const defaults = {
11
12
  checkUrl: 'https://validator.w3.org/nu/',
@@ -20,9 +21,10 @@ const w3cHtmlValidator = {
20
21
  throw Error('[w3c-html-validator] Invalid ignoreLevel option: ' + settings.ignoreLevel);
21
22
  if (settings.output !== 'json' && settings.output !== 'html')
22
23
  throw Error('[w3c-html-validator] Option "output" must be "json" or "html".');
23
- const mode = settings.html ? 'html' : settings.filename ? 'filename' : 'website';
24
+ const filename = settings.filename ? slash(settings.filename) : null;
25
+ const mode = settings.html ? 'html' : filename ? 'filename' : 'website';
24
26
  const readFile = (filename) => fs.readFileSync(filename, 'utf-8').replace(/\r/g, '');
25
- const inputHtml = settings.html ?? (settings.filename ? readFile(settings.filename) : null);
27
+ const inputHtml = settings.html ?? (filename ? readFile(filename) : null);
26
28
  const makePostRequest = () => request.post(settings.checkUrl)
27
29
  .set('Content-Type', 'text/html; encoding=utf-8')
28
30
  .send(inputHtml);
@@ -35,7 +37,7 @@ const w3cHtmlValidator = {
35
37
  const success = '<p class="success">';
36
38
  const titleLookup = {
37
39
  html: 'HTML String (characters: ' + inputHtml?.length + ')',
38
- filename: settings.filename,
40
+ filename: filename,
39
41
  website: settings.website,
40
42
  };
41
43
  const filterMessages = (response) => {
@@ -52,7 +54,7 @@ const w3cHtmlValidator = {
52
54
  mode: mode,
53
55
  title: titleLookup[mode],
54
56
  html: inputHtml,
55
- filename: settings.filename || null,
57
+ filename: filename,
56
58
  website: settings.website || null,
57
59
  output: settings.output,
58
60
  status: response.statusCode || -1,
@@ -63,8 +65,8 @@ const w3cHtmlValidator = {
63
65
  const response = reason.response;
64
66
  const getMsg = () => [response.status, response.res.statusMessage, response.request.url];
65
67
  const message = response ? getMsg() : [reason.errno, reason.message];
66
- const networkErr = { type: 'network-error', message: message.join(' ') };
67
- return toValidatorResults({ ...response, ...{ body: { messages: [networkErr] } } });
68
+ response.body = { messages: [{ type: 'network-error', message: message.join(' ') }] };
69
+ return toValidatorResults(response);
68
70
  };
69
71
  return w3cRequest.then(filterMessages).then(toValidatorResults).catch(handleError);
70
72
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "w3c-html-validator",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "Check the markup validity of HTML files using the W3C validator",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -86,25 +86,26 @@
86
86
  "cli-argv-util": "~1.2",
87
87
  "fancy-log": "~2.0",
88
88
  "glob": "~10.3",
89
+ "slash": "~5.1",
89
90
  "superagent": "~8.1"
90
91
  },
91
92
  "devDependencies": {
92
93
  "@types/fancy-log": "~2.0",
93
94
  "@types/glob": "~8.1",
94
- "@types/node": "~20.8",
95
- "@types/superagent": "~4.1",
96
- "@typescript-eslint/eslint-plugin": "~6.9",
97
- "@typescript-eslint/parser": "~6.9",
95
+ "@types/node": "~20.10",
96
+ "@types/superagent": "~8.1",
97
+ "@typescript-eslint/eslint-plugin": "~6.15",
98
+ "@typescript-eslint/parser": "~6.15",
98
99
  "add-dist-header": "~1.3",
99
100
  "assert-deep-strict-equal": "~1.1",
100
101
  "copy-file-util": "~1.1",
101
102
  "copy-folder-util": "~1.1",
102
- "eslint": "~8.53",
103
+ "eslint": "~8.56",
103
104
  "jshint": "~2.13",
104
105
  "merge-stream": "~2.0",
105
106
  "mocha": "~10.2",
106
107
  "rimraf": "~5.0",
107
108
  "run-scripts-util": "~1.2",
108
- "typescript": "~5.2"
109
+ "typescript": "~5.3"
109
110
  }
110
111
  }