html-w3c-validator

CLI for validating multiple 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 multiple html pages using [validator.w3.org](https://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 should I validate my HTML pages? Quote from [https://validator.w3.org/docs/help.html#why-validate](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](https://github.com/bahmutov/start-server-and-test) to validate HTML pages of your project. ### Prerequisites [Node.js](https://nodejs.org/) >= 16.0.0 ### Installation (with [start-server-and-test](https://github.com/bahmutov/start-server-and-test)) ```sh npm install --save-dev html-w3c-validator start-server-and-test ``` ## ⚙️ Configuration ### `package.json` ```jsonc { "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` ```jsonc { "urls": ["http://127.0.0.1:3000/", "http://127.0.0.1:3000/about"], // You can also specify HTML files instead of URLs "files": ["./index.html", "./about.html"], // Specify the severities of the validator (default: ["warning", "error"]) "severities": ["info", "warning", "error"], } ``` ## Usage ```sh npm run test:html-w3c-validator ``` Example of output (in case of success): ```txt ✔ Validating http://127.0.0.1:3000/ ✔ Validating http://127.0.0.1:3000/about Success: HTML validation (W3C) passed! 🎉 ``` See the [./example](./example) folder for practical usage. ### Options ```text --current-working-directory #0 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](./CONTRIBUTING.md) file. ## 📄 License [MIT](./LICENSE)