Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 66f3f47

Browse files
committed
maximumLineLength: abstract common boilerplate into local removeLoc function
empty lines .loc.start.line - 1 through .loc.end.line - 1 is used in multiple places and warrants a helper - introduced removeLoc(tokenOrNode)
1 parent a8517fe commit 66f3f47

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/rules/maximum-line-length.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,15 @@ module.exports.prototype = {
106106
// This check should not be destructive
107107
lines = lines.slice();
108108

109+
var removeLoc = function(tokenOrNode) {
110+
for (var i = tokenOrNode.loc.start.line; i <= tokenOrNode.loc.end.line; i++) {
111+
lines[i - 1] = '';
112+
}
113+
};
114+
109115
if (this._allowRegex) {
110116
file.iterateTokensByType('RegularExpression', function(token) {
111-
for (var i = token.loc.start.line; i <= token.loc.end.line; i++) {
112-
lines[i - 1] = '';
113-
}
117+
removeLoc(token);
114118
});
115119
}
116120

@@ -158,9 +162,7 @@ module.exports.prototype = {
158162
if (this._allowRequire) {
159163
file.iterateNodesByType('CallExpression', function(node) {
160164
if (node.callee.name === 'require') {
161-
for (var i = node.loc.start.line; i <= node.loc.end.line; i++) {
162-
lines[i - 1] = '';
163-
}
165+
removeLoc(node);
164166
}
165167
});
166168
}

0 commit comments

Comments
 (0)