Giter Site home page Giter Site logo

html-linter's Introduction

HTML Linter

https://api.travis-ci.org/sk-/html-linter.svg?branch=master https://coveralls.io/repos/sk-/html-linter/badge.svg?branch=master

HTML Linter is an HTML5 linter that follows the style guide defined by Google.

Motivation

Handling HTML5 files generated by lots of different of people is a difficult task, because the standard is evolving quite fast and also because browsers are quite open to accept any malformed/invalid/incomplete input.

That's why we decided to have an automated tool to check our coding standard.

We start with the Google standard and we enhance it with some extra rules defined by the project html-minifier. You can read his detailed article.

The list of extra rules we added are:

  • Boolean attributes should not have an explicit value.
  • Do not use the name attribute in a tags.
  • Do not use the language attribute in script tags.
  • Do not use the charset attribute in script tags when there is no source.
  • Javascript:void(0) links are evil.
  • onclick='javascript: ...' is not required. This will raise also a Concerns Separation error.
  • meta http-equiv: use only standard properties + X-UA-compatible
  • No extra white-spaces between attributes or before the opening or closing tag.

What is missing?

Check if the file has BOM.

The ability to validate the HTML using the tool HTML5 tidy and to integrate some schema.org or microdata validator.

However, we do not have any short terms plans to handle the latter, due to a couple of reasons:

  • Tidy can be easily integrated using the tool git-lint
  • Any other validator can also be integrated with git-lint
  • Adding any extra validator would pull many more dependencies and change the scope.

Limitations

html_linter used the project template-remover to remove the PHP and Jinja markup from the files and this project works has some limitations.

One example that won't work is the following:

<?php echo "?>" ?>

The reason it does not work is because when the method sees the first '?>' (the one inside the string), it thinks it's a closing tag.

Example use

Below are example of how template_remover.py is used:

$ html_lint.py filename.html

Installation

You can install, upgrade or uninstall html-linter with these commands:

$ pip install html-linter
$ pip install --upgrade html-linter
$ pip uninstall html-linter

Python Versions

Python 2.7, 3.3, 3.4, 3.5 and 3.6 are supported.

Development

Help for this project is more than welcomed, so feel free to create an issue or to send a pull request via http://github.com/deezer/html-linter.

Tests are run using nose, either with:

$ python -R setup.py nosetests
$ nosetests

Use the tool git-lint before any commit, so errors and style problems are caught early.

TODOS and Possible Features

  • Make the output less verbose.
  • Integrate with HTML5 tidy.
  • Integrate with a schema.org/microdata validator.

Contributors

Changelog

v0.4 (2017-03-30)

  • Support for a --printfilename option (#8)
  • Support for Python 3.6 (#12)

v0.3 (2016-01-24)

  • Support for multiple files (by @di)

v0.2 (2015-12-13)

  • Support for Python 3.5

v0.1 (2014-05-07)

  • Initial commit.

html-linter's People

Contributors

di avatar elsmorian avatar jayvdb avatar sk- avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

html-linter's Issues

Boolean attribute check is incorrect

A field like <label spellcheck="false">Example Label</label> will raise the following error:

241:173: Error: Boolean Attributes: Boolean attributes define their value based on the presence or abscence of the attribute: Change 'spellcheck="false"' to just 'spellcheck'.

First, this is wrong because spellcheck="false" is not the same as just spellcheck, however the documentation for the spellcheck attribute says:

This attribute is an enumerated one and not a Boolean one. This means that the explicit usage of one of the values true or false is mandatory and that a shorthand like <label spellcheck>Example Label</label> is not allowed. The correct usage is <label spellcheck="true">Example Label</label>.

So this error should not be raised for spellcheck or any similar enumerated field.

Are non javascript script tags harmful?

For files with handlebars templates like <script id="template" type="text/x-handlebars-template"> the following error is shown:

line 22, col 1: Error: Separation of concerns: Javascript should be defined in its own file: Move the contents of this tag to its own JS file.

Can't disable some checks

I just tried to launch the command with --disable=indentation but indentation errors are still showing up.

Release please!

I'd be awesomely delighted by a timely release since the current one doesn't work with Python 3.5 but you apparently fixed that :)

Cheers!

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.