1
1
mirror of https://github.com/theoludwig/html-w3c-validator.git synced 2024-11-09 22:08:12 +01:00
CLI for validating multiple html pages using validator.w3.org. https://www.npmjs.com/package/html-w3c-validator
Go to file
Théo LUDWIG cc6a1278a1
fix: print correctly validation results
There was an error thrown by `table` library to print validation results
when there were 2 (or more) errors, with one error with line/column
and the other error without specified line/column.

Fixes #6
2024-11-09 15:45:31 +01:00
.github fix: update dependencies to latest 2024-05-23 21:21:34 +02:00
.husky chore: cleaner configs 2024-01-30 01:16:56 +01:00
.vscode fix: update dependencies to latest 2023-12-26 22:43:05 +01:00
example fix: update dependencies to latest 2024-05-23 21:21:34 +02:00
schema docs: fix wrong link for .html-w3c-validatorrc.json JSON schema 2024-02-02 17:28:44 +01:00
src fix: print correctly validation results 2024-11-09 15:45:31 +01:00
.commitlintrc.json chore: initial commit 2022-01-06 19:52:25 +01:00
.editorconfig chore: initial commit 2022-01-06 19:52:25 +01:00
.eslintrc.json fix: update dependencies to latest 2024-05-23 21:21:34 +02:00
.gitattributes chore: maintenance 2022-02-19 16:55:36 +01:00
.gitignore feat: usage of ESM modules imports (instead of CommonJS) 2022-04-06 19:59:31 +02:00
.html-w3c-validatorrc.json test: add automated tests 2023-08-09 16:51:34 +02:00
.lintstagedrc.json refactor: simplify logic 2024-02-02 14:47:31 +01:00
.npmrc feat: add npm package provenance 2023-05-13 16:21:58 +02:00
.prettierignore test: add automated tests 2023-08-09 16:51:34 +02:00
.prettierrc.json chore: better Prettier config for easier reviews 2023-10-23 23:21:05 +02:00
.releaserc.json feat: add html-w3c-validator command 2022-01-06 22:34:58 +01:00
.swcrc fix: update dependencies to latest 2023-12-26 22:43:05 +01:00
CODE_OF_CONDUCT.md fix: update author - Théo LUDWIG 2023-07-02 12:22:39 +02:00
CONTRIBUTING.md fix: update author - Théo LUDWIG 2023-07-02 12:22:39 +02:00
LICENSE docs(license): add email address 2024-01-29 21:57:54 +01:00
package-lock.json fix: update dependencies to latest 2024-05-23 21:21:34 +02:00
package.json fix: update dependencies to latest 2024-05-23 21:21:34 +02:00
README.md docs: fix wrong link for .html-w3c-validatorrc.json JSON schema 2024-02-02 17:28:44 +01:00
tsconfig.json fix: update dependencies to latest 2024-05-23 21:21:34 +02:00

html-w3c-validator

CLI for validating HTML pages using validator.w3.org.

CONTRIBUTING Licence MIT Contributor Covenant
Build Lint Test
Conventional Commits semantic-release npm version

📜 About

html-w3c-validator is a CLI tool to validate HTML pages using validator.w3.org.

You might use a JavaScript framework or simply use HTML but you should always validate your production HTML and this validation should be part of your CI/CD pipeline (tests, linting, etc.).

Why is HTML page validation important?

Quote from https://validator.w3.org/docs/help.html#why-validate:

One of the important maxims of computer programming is: "Be conservative in what you produce; be liberal in what you accept."

Browsers follow the second half of this maxim by accepting Web pages and trying to display them even if they're not legal HTML. Usually this means that the browser will try to make educated guesses about what you probably meant. The problem is that different browsers (or even different versions of the same browser) will make different guesses about the same illegal construct; worse, if your HTML is really pathological, the browser could get hopelessly confused and produce a mangled mess, or even crash.

⚙️ Getting Started

You can combine html-w3c-validator with start-server-and-test to validate HTML pages of your project.

Prerequisites

Node.js >= 16.0.0

Installation (with start-server-and-test)

npm install --save-dev html-w3c-validator start-server-and-test

⚙️ Configuration

package.json

{
  "scripts": {
    // Command to start the server serving your HTML pages (e.g: using vercel/serve)
    "start": "serve \"./build\"",

    // Command to validate your HTML pages
    "test:html-w3c-validator": "start-server-and-test \"start\" \"http://127.0.0.1:3000\" \"html-w3c-validator\"",
  },
}

.html-w3c-validatorrc.json

{
  "$schema": "https://raw.githubusercontent.com/theoludwig/html-w3c-validator/master/schema/html-w3c-validatorrc-schema.json",

  // URLs to validate.
  "urls": ["http://127.0.0.1:3000/", "http://127.0.0.1:3000/about"],

  // Files to validate.
  "files": ["./index.html", "./about.html"],

  // Specify the severities of the validator messages to report. (default: ["warning", "error"])
  "severities": ["info", "warning", "error"],
}

Usage

npm run test:html-w3c-validator

Example of output (in case of success):

✔ Validating http://127.0.0.1:3000/
✔ Validating http://127.0.0.1:3000/about

Success: HTML validation (W3C) passed! 🎉

See the ./example folder for practical usage.

Options

--current-working-directory <path>  The current working directory (default: `process.cwd()`).
-V, --version                       Output the version number.
-h, --help                          Display help for command.

💡 Contributing

Anyone can help to improve the project, submit a Feature Request, a bug report or even correct a simple spelling mistake.

The steps to contribute can be found in the CONTRIBUTING.md file.

📄 License

MIT