Code coverage report for htmlcs/index.js

Statements: 100% (23 / 23)      Branches: 100% (2 / 2)      Functions: 100% (5 / 5)      Lines: 100% (23 / 23)      Ignored: none     

All files » htmlcs/ » index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77          1   1 1 1     1     1 20       1                                           20 20       1 37 37   37 740 740     37       1 37       37 37   37     1          
/**
 * @file main file
 * @author nighca<nighca@live.cn>
 */
 
var fs = require('fs');
 
var parse = require('./lib/parse');
var Reporter = require('./lib/reporter');
var config = require('./lib/config');
 
// rules
var rules = [];
 
// method to add rule
var addRule = function (rule) {
    rules.push(rule);
};
 
// pre-set rules based on [here](http://gitlab.baidu.com/fe/spec/blob/master/html.md)
[
    'asset-type',
    'bool-attribute-value',
    'button-name',
    'button-type',
    'charset',
    'css-in-head',
    'doctype',
    'html-lang',
    'ie-edge',
    'img-alt',
    'img-src',
    'img-title',
    'img-width-height',
    'lowercase-class-with-hyphen',
    'lowercase-id-with-hyphen',
    'rel-stylesheet',
    'script-in-tail',
    'title-required',
    'unique-id',
    'viewport'
].forEach(function (rule) {
    rule = require('./lib/rules/' + rule);
    addRule(rule);
});
 
// hint code
var hint = function (code, cfg) {
    var document = parse(code);
    var reporter = new Reporter();
 
    rules.forEach(function (rule) {
        reporter.setRule(rule.name);
        rule.lint(cfg[rule.name], document, reporter);
    });
 
    return reporter.result();
};
 
// hint file
var hintFile = function (filePath, options) {
    options = options || {
        encoding: 'utf-8'
    };
 
    var cnt = fs.readFileSync(filePath, options);
    var cfg = config.load(filePath);
 
    return hint(cnt, cfg);
};
 
module.exports = {
    addRule: addRule,
    hint: hint,
    hintFile: hintFile
};