all files / htmlcs/ index.js

100% Statements 14/14
100% Branches 4/4
100% Functions 2/2
100% Lines 14/14
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                            87×       87× 87×   87×                   33×       33× 33×   33×                          
/**
 * @file main file
 * @author nighca<nighca@live.cn>
 */
 
var fs = require('fs');
 
var config = require('./lib/config');
var htmlcs = require('./lib/htmlcs');
 
/**
 * Do hint with given filePath & option for readFile.
 *
 * @param {string} filePath - path of the target file
 * @param {Object=} options - option for readFile
 * @return {Report[]} the hint result, list of reports
 */
var hintFile = function (filePath, options) {
    options = options || {
        encoding: 'utf-8'
    };
 
    var cnt = fs.readFileSync(filePath, options);
    var cfg = config.load(filePath);
 
    return htmlcs.hint(cnt, cfg);
};
 
/**
 * Do format with given filePath & option for readFile
 *
 * @param {string} filePath - path of the target file
 * @param {Object=} options - option for readFile
 * @return {string} the formatted code
 */
var formatFile = function (filePath, options) {
    options = options || {
        encoding: 'utf-8'
    };
 
    var cnt = fs.readFileSync(filePath, options);
    var cfg = config.load(filePath);
 
    return htmlcs.format(cnt, cfg);
};
 
module.exports = {
    addRule: htmlcs.addRule,
 
    hint: htmlcs.hint,
    hintAsync: htmlcs.hintAsync,
    format: htmlcs.format,
    formatAsync: htmlcs.formatAsync,
 
    hintFile: hintFile,
    formatFile: formatFile
};