all files / htmlcs/lib/rules/ unnecessary-whitespace-in-text.js

100% Statements 8/8
100% Branches 4/4
100% Functions 2/2
100% Lines 8/8
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                            103× 1371× 1357×     14× 14× 14×                    
/**
 * @file rule: unnecessary-whitespace-in-text
 * @author Oleg Krivtsov <oleg@webmarketingroi.com.au>
 */
 
module.exports = {
 
    name: 'unnecessary-whitespace-in-text',
 
    desc: 'Unnecessary usage of white-space(s) in text',
 
    target: 'parser',
 
    lint: function (getCfg, parser, reporter) {
 
        parser.on('text', function (data) {
            if (!getCfg()) {
                return;
            }
 
            var pattern = /^.+([ \t]+)$/;
            var match = data.match(pattern);
            if (match) {
                reporter.warn(
                    this.startIndex + match.length + 1,
                        '052',
                        'Unnecessary usage of a trailing white-space(s) in text'
                    );
 
            }
        });
    }
};