GithubHelp home page GithubHelp logo

htmlhint's Introduction

HTMLHint

The static code analysis tool you need for your HTML.

HTMLHint Github

Installation and Usage

Global Installation

$ npm install htmlhint -g

Inlcude HTMLHint as part of your project

$ npm install htmlhint --save-dev

you can run the help of HTMLHint

$ htmlhint --help

Output

Usage: htmlhint <file|folder|pattern|stdin|url ...> [options]

Options:
  -V, --version                                                    output the version number
  -l, --list                                                       show all of the rules available
  -c, --config <file>                                              custom configuration file
  -r, --rules <ruleid, ruleid=value ...>                           set all of the rules available
  -R, --rulesdir <file|folder>                                     load custom rules from file or folder
  -f, --format <checkstyle|compact|html|json|junit|markdown|unix>  output messages as custom format
  -i, --ignore <pattern, pattern ...>                              add pattern to exclude matches
  --nocolor                                                        disable color
  --warn                                                           Warn only, exit with 0
  -h, --help                                                       display help for command
  Examples:

    htmlhint
    htmlhint www
    htmlhint www/test.html
    htmlhint www/**/*.xhtml
    htmlhint www/**/*.{htm,html}
    htmlhint http://www.alibaba.com/
    cat test.html | htmlhint stdin
    htmlhint --list
    htmlhint --rules tag-pair,id-class-value=underline test.html
    htmlhint --config .htmlhintrc test.html
    htmlhint --ignore **/build/**,**/test/**
    htmlhint --rulesdir ./rules/

You can run HTMLHint on any file, directory or analyse an URL

$ htmlhint errors.html
$ htmlhint **/*.html
$ htmlhint https://htmlhint.com/

Configuration

You can generate htmlhintrc file with tool htmlhint-playground and usage

Custom config file:

$ htmlhint --config htmlhintrc **/**/**/*.{htm,html}

Custom rules for console:

$ htmlhint --rules tag-pair,id-class-value=underline errors.html

Create rules:

test-rule.js

module.exports = function(HTMLHint) {
    HTMLHint.addRule({
        id: 'test-rule',
        description: 'test rule.',
        init: function(parser, reporter){
            var self = this;
            parser.addListener('tagstart', function(event){
                var tagName = event.tagName.toLowerCase();
                if(tagName === 'body'){
                    reporter.warn('Found body.', event.line, event.col, self, event.raw);
                }
            });
        }
    });
};

Run custom rules

$ htmlhint --rulesdir ./rules/ --rules test-rule

Output

/home/../HTMLHint/errors.html
      L7 |<body>
          ^ Found body. (test-rule)

Scanned 1 files, found 1 errors in 1 files (12 ms)

Docs

Official Documentation

htmlhint's People

Contributors

olsmca avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.