Skip to content

Commit

Permalink
More meaningful variable names in cli.js
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian committed Sep 16, 2023
1 parent 6ee9a42 commit 79c6c5d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Example terminal commands:
$ npm install --save-dev w3c-html-validator
$ npx html-validator docs
```
The above `npx` line validates all the HTML files in the **docs** folder.

You can also install **w3c-html-validator** globally (`--global`) and then run it anywhere directly from the terminal.

### 3. CLI flags
Expand All @@ -62,17 +64,17 @@ Examples:
- `html-validator`<br>
Validate all HTML files in the project.

- `html-validator --exclude=build,tmp`<br>
Slip all files which have "build" or "tmp" anywhere in their pathname or filename.
- `html-validator docs --exclude=build,tmp`<br>
Validate all HTML files in the **docs** folder except files which have "build" or "tmp" anywhere in their pathname or filename.

- `html-validator docs/*.html '--ignore=Trailing slash on void elements'`<br>
- `html-validator docs '--ignore=Trailing slash on void elements'`<br>
Allow the ugly slashes of self-closing tags despite XHTML being a hideous scourge on the web.

- `html-validator docs/*.html '--ignore=/^Duplicate ID/'`<br>
- `html-validator docs '--ignore=/^Duplicate ID/'`<br>
Use a RegEx (regular expression) to skip all validation messages that start with "Duplicate ID".

- `html-validator docs '--ignore=/^Duplicate ID|^Section lacks|^Element .blockquote. not allowed/'`<br>
Use a RegEx with "or" operations to skip multiple validation messages.
- `html-validator docs '--ignore=/^Duplicate ID|^Section lacks|^Element .blockquote. not allowed/'`<br>
Use a RegEx with "or" operators (`|`) to skip multiple validation messages.

- `html-validator --quiet`<br>
Suppress "pass" status messages.
Expand Down Expand Up @@ -158,7 +160,7 @@ describe('Home page', () => {
it('validates', (done) => {
const handleResults = (results) => {
assert(results.status === 200, 'Request succeeded');
assert(results.validates, 'Home page validates');
assert(results.validates, 'Home page validates');
done();
};
const options = { filename: 'docs/index.html' };
Expand All @@ -171,7 +173,7 @@ describe('Home page', () => {
<br>

---
**CLI Build Tools**
**CLI Build Tools for package.json**
- 🎋 [add-dist-header](https://github.com/center-key/add-dist-header):&nbsp; _Prepend a one-line banner comment (with license notice) to distribution files_
- 📄 [copy-file-util](https://github.com/center-key/copy-file-util):&nbsp; _Copy or rename a file with optional package version number_
- 📂 [copy-folder-util](https://github.com/center-key/copy-folder-util):&nbsp; _Recursively copy files from one folder to another folder_
Expand Down
8 changes: 4 additions & 4 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ const reporterOptions = {
quiet: cli.flagOn.quiet,
maxMessageLen: trim,
};
const slashed = /^\/.*\/$/; //starts and ends with a slash indicating it's a regex
const skip = slashed.test(ignore) ? new RegExp(ignore.slice(1, -1)) : ignore;
const isRegex = /^\/.*\/$/; //starts and ends with a slash indicating it's a regex
const skip = isRegex.test(ignore) ? new RegExp(ignore.slice(1, -1)) : ignore;
const handleReport = (report) => w3cHtmlValidator.reporter(report, reporterOptions);
const options = (file) => ({ filename: file, ignoreMessages: skip });
const getReport = (file) => w3cHtmlValidator.validate(options(file)).then(handleReport);
const options = (filename) => ({ filename: filename, ignoreMessages: skip });
const getReport = (filename) => w3cHtmlValidator.validate(options(filename)).then(handleReport);
filenames.forEach((filename, i) => globalThis.setTimeout(() => getReport(filename), i * delay));
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@
"devDependencies": {
"@types/fancy-log": "~2.0",
"@types/glob": "~8.1",
"@types/node": "~20.5",
"@types/node": "~20.6",
"@types/superagent": "~4.1",
"@typescript-eslint/eslint-plugin": "~6.6",
"@typescript-eslint/parser": "~6.6",
"@typescript-eslint/eslint-plugin": "~6.7",
"@typescript-eslint/parser": "~6.7",
"add-dist-header": "~1.3",
"assert-deep-strict-equal": "~1.1",
"copy-file-util": "~1.1",
"copy-folder-util": "~1.1",
"eslint": "~8.48",
"eslint": "~8.49",
"jshint": "~2.13",
"merge-stream": "~2.0",
"mocha": "~10.2",
Expand Down

0 comments on commit 79c6c5d

Please sign in to comment.