GithubHelp home page GithubHelp logo

linthtml's Introduction

LintHTML

npm version license Build Status codebeat badge Coverage Status

An unofficial HTML5 linter and validator.

LintHTML is a fork of htmllint featuring a built-in CLI and multiple bug fixes and improvements. The migration from htmllint to LintHTML is easy, as all htmllint's rules can be used with LintHTML – just follow this simple guide.

Installation and Usage

You can install LintHTML either locally or globally. For most cases we recommend the former, which can be achieved this way with npm:

npm install @linthtml/linthtml --save-dev

You should then init a configuration file:

npx linthtml --init

This will generate a file .linthtmlrc in the current directory.

After that, you can run LintHTML on any file or directory like this:

npx linthtml 'yourfile.html'
npx linthtml 'src/**/*.html'

If you want to read about alternative installation and usage methods, have a look at the extended section in docs/installation_and_usage.md.

Migrate from htmllint

To migrate from htmllint to LintHTML, first remove all the htmllint-related packages you were using:

npm uninstall htmllint htmllint-cli

Then rename the file .htmlintrc to .linthtmlrc. You might want to remove the rules indent-delta and indent-width-cont from there in case you where using them, since LintHTML's indent style checker deals with those aspects out of the box.

Finally, install LintHTML:

npm install @linthtml/linthtml --save-dev

Rules

Current list of rules and deprecations can be found in docs/rules.md.

Global Configuration

By default, LintHTML will look for a JSON, YAML or JavaScript file named .linthtmlrc.* or a linthtmlConfig section in package.json. Anyway, you can specify a custom configuration file using the --config option when running LintHTML in the command line.

Inline Configuration

Sometimes it is necessary to disable certain rules for a specific line, block or HTML file. This might be the case, for example, for an inline SVG block of code. This can be achieved with inline configurations.

Inline configurations are HTML comments beginning with the keyword linthtml-configure:

<!-- linthtml-configure [rule]="[value]" -->

Multiple rules can be set in a single inline configuration comment. Values must be surrounded with double/single quotes if they contain spaces, and must be either a valid value for the rule (encoded in pretty-much-JSON), or the string $previous (which is special value that recalls the former value of the rule for your convenience).

Some examples:

  • turn off the attr-bans rule
<!-- linthtml-configure attr-bans="false" -->
<!-- linthtml-configure attr-bans=false -->
<!-- linthtml-configure attr-bans="off" -->
  • turn on the attr-bans rule
<!-- linthtml-configure attr-bans="true" -->
<!-- linthtml-configure attr-bans=true -->

⚠️ you can only turn on rules that have being deactivated by an inline config

  • change the tag-bans rule value
<!-- linthtml-configure tag-bans="['p','style']" -->
<!-- linthtml-configure tag-bans=['p','style'] -->
  • restore the previous value of the tag-bans rule
<!-- linthtml-configure tag-bans="$previous" -->

⚠️ works only with the legacy config at the moment

It's worth noting that inline configurations only affect the file they're on, so if they are not explicitly reversed with the $previous value, they will just apply until the end of the file.

Ecosystem

Apart from the built-in CLI, you might want to use some of the following tools to integrate LintHTML in different scenarios:

🚧 Coming soon:

  • linthtml-loader: LintHTML loader for webpack
  • broccoli-linthtml: Integrates HTML linting with LintHTML as part of your Broccoli build pipeline

Contributing

Contributions are welcome, please make sure to use the proper GitHub tag on your issue/PR.

  • cli: anything related to LintHTML's CLI
  • rule: anything related to the rules (bugs, improvements, docs, new rules...)
  • core: anything related to LintHTML's core (file parsing, plugin system...)

linthtml's People

Contributors

alecmerdler avatar alfaproject avatar c7pt7in avatar captain-yossarian avatar coalman avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar dheerajvs avatar erikvold avatar fossabot avatar gangstertim avatar hartca avatar jonatanpedersen avatar kamikillerto avatar kamoqq avatar knyga avatar krekkied avatar loicbourgois avatar messman avatar michael-siek avatar mlochbaum avatar nash716 avatar porcelainheart avatar romnempire avatar sylvaindumont avatar waldyrious avatar waterfoul avatar yodasws avatar yvanavermaet 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.