Code coverage report for htmlcs/lib/reporter.js

Statements: 100% (16 / 16)      Branches: 100% (11 / 11)      Functions: 100% (7 / 7)      Lines: 100% (16 / 16)      Ignored: none     

All files » htmlcs/lib/ » reporter.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          1 46   46     1 740     1 65             65                   1 3 57                 1 46 33     46     1  
/**
 * @file class Reporter
 * @author nighca<nighca@live.cn>
 */
 
function Reporter(options) {
    this._options = options;
 
    this._results = [];
}
 
Reporter.prototype.setRule = function (rule) {
    this.rule = rule;
};
 
Reporter.prototype.report = function (item) {
    var pos = item.pos ||
        (item.elem && item.elem.startPos) ||
        {
            line: 0,
            col: 0
        };
 
    this._results.push({
        type: item.type,
        code: item.code,
        rule: item.rule || this.rule,
        line: pos.line,
        col: pos.col,
        message: item.message
    });
};
 
['info', 'warn', 'error'].forEach(function (type) {
    Reporter.prototype[type] = function (element, code, message) {
        return this.report({
            type: type.toUpperCase(),
            code: code,
            message: message,
            elem: element
        });
    };
});
 
Reporter.prototype.result = function () {
    this._results.sort(function (a, b) {
        return (a.line > b.line || a.line === b.line && a.col > b.col) ? 1 : -1;
    });
 
    return this._results;
};
 
module.exports = Reporter;