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

Commit 12a2206

Browse files
committed
maximumLineLenght - rewrite allowFunctionSignature handling
`iterateNodesByType` is now used instead of the recursive `searchBodyForDecl` `FunctionExpression` is checked as well as (previously checked) `FunctionDeclaration` and `MethodDefiniton` closes #2032
1 parent 66f3f47 commit 12a2206

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

lib/rules/maximum-line-length.js

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -127,35 +127,23 @@ module.exports.prototype = {
127127
}
128128

129129
if (this._allowFunctionSignature) {
130-
var functionDeclarationLocs = [];
131-
var searchBodyForDecl = function searchBodyForDecl(node) {
132-
node.body.forEach(function(bodyNode) {
133-
if (bodyNode.type === 'FunctionDeclaration') {
134-
// get the loc for the `function Identifier` portion
135-
functionDeclarationLocs.push(bodyNode.id.loc);
136-
// get the locs for the params
137-
bodyNode.params.forEach(function(param) { functionDeclarationLocs.push(param.loc); });
138-
return;
139-
140-
} else if (bodyNode.type === 'ClassDeclaration') {
141-
searchBodyForDecl(bodyNode.body);
142-
return;
143-
144-
} else if (bodyNode.type === 'MethodDefinition') {
145-
// get the loc for method name
146-
functionDeclarationLocs.push(bodyNode.key.loc);
147-
// get the locs for the params
148-
bodyNode.value.params.forEach(function(param) { functionDeclarationLocs.push(param.loc); });
149-
return;
150-
}
151-
});
152-
};
153-
searchBodyForDecl(file.getTree());
154-
155-
functionDeclarationLocs.forEach(function(loc) {
156-
for (var i = loc.start.line; i <= loc.end.line; i++) {
157-
lines[i - 1] = '';
130+
file.iterateNodesByType('FunctionDeclaration', function(node) {
131+
removeLoc(node.id);
132+
node.params.forEach(removeLoc);
133+
});
134+
135+
file.iterateNodesByType('MethodDefinition', function(node) {
136+
removeLoc(node.key);
137+
// node.value is a FunctionExpression, params are handled there
138+
});
139+
140+
file.iterateNodesByType('FunctionExpression', function(node) {
141+
// need to remove the first line, because we can't be sure there's any id or params
142+
lines[node.loc.start.line - 1] = '';
143+
if (node.id) {
144+
removeLoc(node.id);
158145
}
146+
node.params.forEach(removeLoc);
159147
});
160148
}
161149

0 commit comments

Comments
 (0)