What is htmlhint?
htmlhint is a static code analysis tool for HTML, which helps developers identify and fix issues in their HTML code. It provides a set of rules that can be configured to enforce coding standards and best practices.
What are htmlhint's main functionalities?
Basic HTML Linting
This feature allows you to lint HTML code to find issues such as missing alt attributes in images, unclosed tags, and other common HTML problems.
const HTMLHint = require('htmlhint').HTMLHint;
const code = '<div><img src="image.jpg"></div>';
const messages = HTMLHint.verify(code);
console.log(messages);
Custom Rule Configuration
This feature allows you to configure custom rules for linting. You can enable or disable specific rules based on your project's requirements.
const HTMLHint = require('htmlhint').HTMLHint;
const code = '<div><img src="image.jpg"></div>';
const rules = {
'tagname-lowercase': true,
'attr-lowercase': true,
'attr-value-double-quotes': true
};
const messages = HTMLHint.verify(code, rules);
console.log(messages);
Integration with Build Tools
htmlhint can be integrated with build tools like Gulp to automate the linting process as part of your build pipeline.
const gulp = require('gulp');
const htmlhint = require('gulp-htmlhint');
gulp.task('htmlhint', function() {
return gulp.src('./src/*.html')
.pipe(htmlhint())
.pipe(htmlhint.reporter());
});
Other packages similar to htmlhint
eslint-plugin-html
eslint-plugin-html is an ESLint plugin that allows you to lint and fix inline scripts contained in HTML files. It integrates with ESLint, providing a unified linting experience for both JavaScript and HTML. Unlike htmlhint, which focuses solely on HTML, eslint-plugin-html leverages ESLint's ecosystem to provide a more comprehensive linting solution.
htmllint
htmllint is another HTML linting tool that provides a wide range of rules for validating HTML code. It is similar to htmlhint in its purpose but offers a different set of rules and configurations. htmllint is known for its flexibility and extensive rule set, making it a strong alternative to htmlhint.
html-validate
html-validate is a highly configurable HTML linter that supports custom rules and plugins. It offers a modern and flexible approach to HTML linting, with support for various configurations and integrations. Compared to htmlhint, html-validate provides more advanced features and better extensibility.
HTMLHint
The static code analysis tool you need for your HTML.
How To Use • Contributing • Website
Table of Contents
📟 Installation and Usage
Prerequisites: Node.js (>=6.14), npm version 3+.
There are two ways to install HTMLHint: globally and locally.
Local Installation and Usage
In case you want to include HTMLHint as part of your project, you can install it locally using NPM:
$ npm install htmlhint --save-dev
After that, You can run HTMLHint on any file or directory like this:
$ ./node_modules/.bin/htmlhint www/index.html
$ ./node_modules/.bin/htmlhint www/**/*.html
Global Installation and Usage
If you want to make HTMLHint available to tools that run across all of your projects, you can install HTMLHint globally using NPM:
$ npm install htmlhint -g
After that, you can run HTMLHint on any file like this:
$ htmlhint www/index.html
$ htmlhint www/**/*.html
You can even launch HTMLHint to analyse an URL:
$ htmlhint https://htmlhint.com/
📃 Example output
🔧 Configuration
Search .htmlhintrc
file in current directory and all parent directories:
$ htmlhint
$ htmlhint test.html
Custom config file:
$ htmlhint --config htmlhint.conf test.html
Custom rules:
$ htmlhint --rules tag-pair,id-class-value=underline index.html
Inline rules in test.html
:
<!--htmlhint tag-pair,id-class-value:underline -->
<html>
<head>
...
📙 Docs
- How to use
- All Rules
- How to Develop
© License
MIT License
💪🏻 Contributors
This project exists thanks to all these people. Contribute.
🏅 Backers
Thank you to all our backers! Become a backer.
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. Become a sponsor.