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

Commit defc537

Browse files
himdelmarkelog
authored andcommitted
maximumLineLength: improve functionSignature option
Add spec for an arrow function expression, and fix it. Treat `ArrowFunctionExpression` same way as `FunctionExpression` Fixes #2032 Closes gh-2040
1 parent 12a2206 commit defc537

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

lib/rules/maximum-line-length.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,34 @@
3737
* ```js
3838
* var aLineOf41Chars = 1234567890123456789;
3939
* ```
40+
*
41+
* #### Example for allExcept functionSignature
42+
*
43+
* ```js
44+
* "maximumLineLength": { "value": 40, "allExcept": [ "functionSignature" ] }
45+
* ```
46+
*
47+
* ##### Valid
48+
*
49+
* ```js
50+
* var f = function(with, many, _many_, arguments) { .... };
51+
* let f = x => x * x * x * x * x * x * x * x;
52+
* (function(foo, bar, baz, quux, cuttlefish) {
53+
* function namesNaamesNaaamesNaaaames() {
54+
* ...
55+
* }
56+
* })();
57+
* const longNameIgnoredAsWell = (a, b) => a * b;
58+
* class X { myLongMethodName(withPossiblyManyArgs) { ... } };
59+
* ```
60+
*
61+
* ##### Invalid
62+
*
63+
* ```js
64+
* function x() { // valid
65+
* return "function_bodies_are_not_protected";
66+
* }
67+
* ```
4068
*/
4169

4270
var assert = require('assert');
@@ -134,11 +162,11 @@ module.exports.prototype = {
134162

135163
file.iterateNodesByType('MethodDefinition', function(node) {
136164
removeLoc(node.key);
137-
// node.value is a FunctionExpression, params are handled there
138165
});
139166

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
167+
file.iterateNodesByType(['ArrowFunctionExpression', 'FunctionExpression'], function(node) {
168+
169+
// Need to remove the first line, because we can't be sure there's any id or params
142170
lines[node.loc.start.line - 1] = '';
143171
if (node.id) {
144172
removeLoc(node.id);

test/specs/rules/maximum-line-length.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@ describe('rules/maximum-line-length', function() {
224224
expect(checker.checkString(code)).to.have.no.errors();
225225
});
226226

227+
it('should not report arrow functions', function() {
228+
var code = '(aVeryVeryLongLongParameter => 42);\n' +
229+
'(() => "parameterless arrow function");\n' +
230+
'((foo, bar, baz, $rootScope) => "quux");';
231+
expect(checker.checkString(code)).to.have.no.errors();
232+
});
233+
227234
it('should not report functions within IIFE blocks', function() {
228235
var code = '(function() {\n' +
229236
' function myCoolFunction(argument) { }\n' +

0 commit comments

Comments
 (0)