From 172dffbb52ae6b61fe41c9a4c14d4be68070111f Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Sun, 14 Feb 2016 11:48:04 -0800 Subject: [PATCH] [eslint-v2][whitespace] add newline-per-chained-call rule --- README.md | 8 ++++++-- packages/eslint-config-airbnb/rules/style.js | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b52dbdcc..7290e0ac 100644 --- a/README.md +++ b/README.md @@ -387,6 +387,7 @@ Other Style Guides if (x > 2) { return true; } + return false; }); ``` @@ -1664,8 +1665,8 @@ Other Style Guides })(this);↵ ``` - - [18.6](#18.6) Use indentation when making long method chains. Use a leading dot, which - emphasizes that the line is a method call, not a new statement. + - [18.6](#18.6) Use indentation when making long method chains (more than 2 method chains). Use a leading dot, which + emphasizes that the line is a method call, not a new statement. eslint: [newline-per-chained-call](http://eslint.org/docs/rules/newline-per-chained-call) ```javascript // bad @@ -1702,6 +1703,9 @@ Other Style Guides .append('svg:g') .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')') .call(tron.led); + + // good + const leds = stage.selectAll('.led').data(data); ``` - [18.7](#18.7) Leave a blank line after blocks and before the next statement. jscs: [`requirePaddingNewLinesAfterBlocks`](http://jscs.info/rule/requirePaddingNewLinesAfterBlocks) diff --git a/packages/eslint-config-airbnb/rules/style.js b/packages/eslint-config-airbnb/rules/style.js index 0e8036ec..4e8710c3 100644 --- a/packages/eslint-config-airbnb/rules/style.js +++ b/packages/eslint-config-airbnb/rules/style.js @@ -59,6 +59,9 @@ module.exports = { 'new-parens': 0, // allow/disallow an empty newline after var statement 'newline-after-var': 0, + // enforces new line after each method call in the chain to make it more readable and easy to maintain + // http://eslint.org/docs/rules/newline-per-chained-call + 'newline-per-chained-call': [2, { "ignoreChainWithDepth": 3 }], // disallow use of the Array constructor 'no-array-constructor': 0, // disallow use of the continue statement