UNPKG

@coffeelint/cli

Version:
77 lines (69 loc) 2.45 kB
(function() { var NoTrailingWhitespace, regexes; regexes = { trailingWhitespace: /[^\s]+[\t ]+\r?$/, onlySpaces: /^[\t ]+\r?$/, spacesStart: /[\t ]+\r?$/, lineHasComment: /^\s*[^\#]*\#/ }; module.exports = NoTrailingWhitespace = (function() { class NoTrailingWhitespace { lintLine(line, lineApi) { var i, len, ref, ref1, ref2, str, token, tokens; if (!((ref = lineApi.config['no_trailing_whitespace']) != null ? ref.allowed_in_empty_lines : void 0)) { if (regexes.onlySpaces.test(line)) { return { columnNumber: line.match(regexes.spacesStart).length + 1 }; } } if (regexes.trailingWhitespace.test(line)) { // By default only the regex above is needed. if (!((ref1 = lineApi.config['no_trailing_whitespace']) != null ? ref1.allowed_in_comments : void 0)) { return { columnNumber: line.match(regexes.spacesStart).index + 1 }; } line = line; tokens = lineApi.tokensByLine[lineApi.lineNumber]; if (!tokens) { return null; } ref2 = (function() { var j, len, results; results = []; for (j = 0, len = tokens.length; j < len; j++) { token = tokens[j]; if (token[0] === 'STRING') { results.push(token[1]); } } return results; })(); // To avoid confusion when a string might contain a "#", every string // on this line will be removed. before checking for a comment for (i = 0, len = ref2.length; i < len; i++) { str = ref2[i]; line = line.replace(str, 'STRING'); } if (!regexes.lineHasComment.test(line)) { return { columnNumber: line.match(regexes.spacesStart).index + 1 }; } } } }; NoTrailingWhitespace.prototype.rule = { type: 'style', name: 'no_trailing_whitespace', level: 'error', message: 'Line ends with trailing whitespace', allowed_in_comments: false, allowed_in_empty_lines: true, description: `This rule forbids trailing whitespace in your code, since it is needless cruft. It is enabled by default.` }; return NoTrailingWhitespace; }).call(this); }).call(this);