Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Marshall Lochbaum edited this page Jul 15, 2016 · 31 revisions

The htmllint User Manual

Welcome to the user manual. This page serves as a reference point for a user.
If you haven't yet, take a look at the ReadMe.

So You Want to Lint some HTML?

htmllint is a linting tool for HTML5. It statically checks your documents for common errors so that you can identify problems in your code.

htmllint is built on Node.js. You'll need to go here http://nodejs.org/ and install it to run htmllint.

htmllint is published on npm. (npmjs.org). You can download our latest stable release by running npm install htmllint. NPM is distributed with Node.js, so you should be able to do this without extra work once Node.js is installed.

The easiest way to test out htmllint is to use our REPL. You can run it through node repl in the htmllint directory. You can now lint HTML5 documents and snippets by calling lint('YOUR HTML HERE'). If you want to lint a file, use the Node file methods to import a file:

>> var fs = require('fs')  
>> var file = fs.readFileSync('path/to/file', 'utf8')  
>> lint(file)

htmllint only supports utf8 for now and the foreseeable future.

Scaling up!

Let's say you want to lint a large number of files consistently, say, every time you make a change to a webpage you're developing. You should use a task runner! We support Grunt. (gruntjs.org) Install our Grunt plugin by running

npm install grunt-htmllint --save-dev

Go here to learn what to do next (https://www.npmjs.org/package/grunt-htmllint).

If task runners aren't your thing, you can install a CLI interface by running npm install htmllint-cli. As of this version, it is not ready for production.

Configuring

htmllint is not jslint. This means the user has control of his linting experience. There are two parts to the configuration experience - the global options object and the local inline configurations.

Global Options

The lint function in the repl will take any number of arguments after the first - these will be loaded as properties into an options object, so they can be in the form of objects or strings. Take a look at the list of options and their valid values.

Inline Configurations

Inline configurations work like other linters - through comments. a valid htmllint inline configuration is of the form

   <!-- htmllint [option]="[string]" preset="$[preset name]" [option]="[valid JSON]" -->

   <!-- htmllint line-ending-style="false" -->
   <!-- htmllint preset="$default" -->
   <!-- htmllint tag-bans="['main','style']" -->

A more in-depth discussion of inline configurations and their power can be found at Inline Configurations.

Clone this wiki locally