@coffeelint/cli
Version:
Lint your CoffeeScript
58 lines (49 loc) • 1.86 kB
JavaScript
(function() {
var MaxLineLength, regexes;
regexes = {
literateComment: /^\s*\#\s/, // indentation, up to comment followed by at least one space.
longUrlComment: /^\s*\#\s.*http[^\s]+.*$/ // indentation, up to comment followed by at least one space.
// Any string may precedes url
// Actual link
// Line may end by other things
};
module.exports = MaxLineLength = (function() {
class MaxLineLength {
lintLine(line, lineApi) {
var isCommentLine, limitComments, lineLength, max, ref, ref1;
max = (ref = lineApi.config[this.rule.name]) != null ? ref.value : void 0;
limitComments = (ref1 = lineApi.config[this.rule.name]) != null ? ref1.limitComments : void 0;
isCommentLine = regexes.literateComment.test(line);
lineLength = line.replace(/\s+$/, '').length;
if (lineApi.isLiterate() && isCommentLine) {
lineLength -= 2;
}
if (max && max < lineLength && !regexes.longUrlComment.test(line)) {
if (!limitComments) {
if (isCommentLine) {
return;
}
}
return {
columnNumber: max,
context: `Length is ${lineLength}, max is ${max}`
};
}
}
};
MaxLineLength.prototype.rule = {
type: 'style',
name: 'max_line_length',
value: 80,
level: 'error',
limitComments: true,
message: 'Line exceeds maximum allowed length',
description: `This rule imposes a maximum line length on your code. <a
href="https://www.python.org/dev/peps/pep-0008/">Python's style
guide</a> does a good job explaining why you might want to limit the
length of your lines, though this is a matter of taste.
Lines can be no longer than eighty characters by default.`
};
return MaxLineLength;
}).call(this);
}).call(this);