HTML code style checking tool comparison.

Choose a suitable tool for quality control of the HTML code will be a very meaningful thing. This paper chose Bootlint, AriaLinter, htmllint, HTMLHint and htmlcs the five most active relevant items to compare. In addition there is also such tidy, W3C / Mozilla HTML validator and other tools, but they are focused on the HTML specification, hardly involves checking the coding style here do not compare.

Comparative angle includes the following aspects:

1) configuration and

2) Rules implement and customize

3) Performance

4) highlights

In order to facilitate the subsequent explanation, where the first grammar style simple classification rules, a first type comprising attr-value-double-quotes (double quotes surround attribute value), max-length (maximum length of a single line limit), tag- pair (explicit request requires an explicit tag closed closed) and the like; and a second category includes script-in-tail (JavaScript embedded in content requires the last page), title-required (title label claim), id-class-ad-disabled (allowed ad_, ad the values ​​of id or class -, _ ad, -ad, etc.) and the like. This rule has two obvious differences, emphasis on the first type code format (or not will not affect the final follow semantics), where call formatting rules; Correspondingly, the second emphasis semantic category, i.e., the performance of the final document, where call semantic rules. In general, the former is more suitable for the syntax analysis phase, which is more suitable for analysis after analysis based on the results of (AST / document) carried out.

Bootlint

Bootlint github may be the largest number of star HTML code style checking tool. But as its name implies, it was developed by Bootstrap team, focusing on project-based Bootstrap. And the degree of concern corresponds to a higher degree of improvement projects, complete documentation, including the introduction of use in a browser, as Grunt mission, Nodejs module and command-line tool.

Bootlint support rule granularity of configuration, but only to disable / enable. It does not support inline configuration files or configuration.

Bootlint focus on project-based Bootstrap, which is in its list of rules embodied in a more obvious: Most of the rules provided Bootlint are obviously only applies to Bootstrap project, such as W004 (plug-Modal are not allowed to be discarded remote) , W005 (if you use jQuery based Bootstrap plugin, requires the introduction page jQuery) and so on. Further, Bootlint implementation is to parse the HTML code via Cheerio, the acquired class jQuery $ (selector) interface rules which are implemented on the basis of $, which determines the current semantic rules only Bootlint offer. Moreover, Bootlint does not support adding custom rules.

Bootlint performance in general, internal Cheerio use htmlparser2 parse HTML code, then the operation will find elements of the package is $ node method, by $ Bootlint by the rules, according to inspection results.

Bootstrap for the relevant check may be regarded as one of the highlights of Bootlint. Bootlint Another unique in that it supports running as a server, lint-based service HTTP requests.

AriaLinter

AriaLinter is based on a rule (Rule based), facing the HTML document inspection tool. It supports as a Grunt mission (the most recommended form), Nodejs module or a command-line tool.

As a Grunt mission or Nodejs module is called, support incoming rules configuration. But it does not support the configuration file or inline configuration, and as a separate command-line tool is not configurable.

AriaLinter stressed that it is "for HTML documents", ie partial inspection semantic rules, practices document is based on jsdom get run-time, then check its contents, structure. In fact, AriaLinter hardly achieve any format rules. Also, do not support custom rules.

AriaLinter performance can be a problem, after all, just to get the document structure, then, jsdom too heavy.

One of the highlights is close AriaLinter supported the template parameters, when the open portion of the rule is not checked. This feature is a limited effect when the template syntax HTML syntax will cause damage.

htmllint

htmllint is a project started in 2014, positioning itself as a "html5 linter and validator", which provides a more comprehensive rule, implementation is very special. There are a lot of people involved in the development, documentation is very complete, attention is strange that it is subject to very low.

htmllint support as Grunt mission or Nodejs modules use the form. It can be passed rule configuration. Does not support profiles, comments configuration support inline.

htmllint better supports the format rules and semantic rules. Practice is to do two types of rules in two steps:

1) the code line by line lint

2) parse the complete code for AST by node lint

Also supports custom rules.

Finally, the performance, htmlparser2 parsing code, performance is better; lint additional nodes by way traversing to avoid duplication, but also on some performance gains.

HTMLHint

HTMLHint people is produced HTML code checking tool positioning "A Static Code Analysis Tool for HTML".

Use comprising introducing in a browser, as Nodejs modules, and the command-line tool. Support incoming configuration or specify the configuration file. But with Bootlint similar to that rule configuration is limited to disable / enable.

, HTMLHint only in the process of checking code parse the opposite AriaLinter. Such benefits are in performance, avoiding the operation of the AST / document is; of course, this also brings limitations: Rules partial format rules. Although HTMLHint also provide some semantic rules, but its implementation is built on listening to when parse events, it is difficult and unnatural.

Further, HTMLHint support custom rule, of course, also be custom rule these limitations, not only access to the parser AST / doument.

HTMLHint performance tool should be able to provide the best in semantic rules. Just over parse process, the search process without AST / Document of.

htmlcs

htmlcs is Baidu EFE produced HTML code style checking tool, the project began in late 2014, should demand the full implementation of the internal Baidu code specifications check for us.

htmlcs Nodejs module supports used, or in the form of command-line tool, when used in packaging manually grunt / gulp in. When invoked as a module, you can pass a custom configuration object; as a command-line tool, supports the configuration file. There is also support for inline code configuration.

htmlcs provides a wealth of rule implementation, including formatting rules and semantic rules, and also supports adding custom rules. When implementing targeted divided when parse rule (class HTMLHint implementation) and document-oriented rules (rules of conduct AriaLinter the class), former event monitor parser, which reads the document directly to the structure. In particular, where the document is subjected to packaging structures, most of the properties and to achieve a method of operation according to the read DOM specification. Thus custom rules may operate document DOM structure in the form of operating specifications for natural and convenient.

In addition htmlcs additional linter to support incoming HTML embedded JS and CSS content to be checked.

For automatic correction rules, htmlcs provides a format method. Custom rules can also customize the format corresponding behavior. Page embedded JS and CSS content can be formatted by a format corresponding to the incoming method.

htmlcs performance advantage is not, at an acceptable level. parse HTML code based htmlparser2, but a process of encapsulation of result objects; addition rule implementations (node ​​searches the frequency) to a certain extent affect the final performance.

to sum up

Bootlint and AriaLinter were significant shortcomings. The former have a certain advantage in only for Bootstrap project; the latter when only concerned with semantic rules to meet certain requirements.

htmllint in most cases to meet the basic needs, but the advantage is not obvious.

If performance is more sensitive, it is recommended HTMLHint.

And htmlcs scalability, since the definition of outstanding ability, may also be covered by the rules currently the most complete, from a personal point of view is the recommended choice in most cases.

Product is slightly Library http://www.pinlue.com/


Guess you like

Origin blog.51cto.com/14325182/2409887