2 * @fileoverview Rule to check for max length on a line.
3 * @author Matt DuVall <http://www.mattduvall.com>
4 * @copyright 2013 Matt DuVall. All rights reserved.
9 //------------------------------------------------------------------------------
11 //------------------------------------------------------------------------------
13 module.exports = function(context) {
16 * Creates a string that is made up of repeating a given string a certain
17 * number of times. This uses exponentiation of squares to achieve significant
18 * performance gains over the more traditional implementation of such
20 * @param {string} str The string to repeat.
21 * @param {int} num The number of times to repeat the string.
22 * @returns {string} The created string.
25 function stringRepeat(str, num) {
27 for (num |= 0; num > 0; num >>>= 1, str += str) {
35 var tabWidth = context.options[1];
37 var maxLength = context.options[0],
38 tabString = stringRepeat(" ", tabWidth);
40 //--------------------------------------------------------------------------
42 //--------------------------------------------------------------------------
43 function checkProgramForMaxLength(node) {
44 var lines = context.getSourceLines();
47 // Split (honors line-ending)
49 lines.forEach(function(line, i) {
50 if (line.replace(/\t/g, tabString).length > maxLength) {
51 context.report(node, { line: i + 1, col: 1 }, "Line " + (i + 1) + " exceeds the maximum line length of " + maxLength + ".");
57 //--------------------------------------------------------------------------
59 //--------------------------------------------------------------------------
62 "Program": checkProgramForMaxLength