question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule for banner/Ratliff style indentation

See original GitHub issue

Environment: latest ESLint in Visual Studio Code.

I’ve read the indent rule’s guide.

I don’t understand whether it’s possible to setup a rule to allow me to use “banner” AKA “Ratliff” style indentation? That’s when the closing brace is indented to the same level as the code block.

// eg control block
if (foo) {
  doSomething();
  }

// eg array declaration
var foo = [
  bar,
  baz,
  qux
  ];

// same for arrays, expressions, etc...

Right now ESLint complains that Expected indentation of 0 spaces but found 2. (indent).

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jr-grenoblecommented, Dec 2, 2017

I just issued a pull request for this, hopefully this can serve as a basis for the new feature.

On Sat, Dec 2, 2017 at 08:48 grokky1 notifications@github.com wrote:

@platinumazure https://github.com/platinumazure I have what @jr-grenoble https://github.com/jr-grenoble posted. I basically just made that one change recommended at the top of this thread, but it seems @jr-grenoble https://github.com/jr-grenoble improved on that, so I’d use his post as the starting point.

I really hope we can get this baked into the library.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/eslint/eslint/issues/9361#issuecomment-348675513, or mute the thread https://github.com/notifications/unsubscribe-auth/AXUjplZYAuaVTp9BhFdkphQrwFeB0ndGks5s8QDagaJpZM4Pl8YV .

https://icon.me/jeanrene?from=emailsignature&access=65b8b3e1677d51e77b65c69e8bd3fdc30ecbebb6 Jeanrene Bouvier Head of Facts Haven jeanrene.bouvier@gmail.com View my Icon https://icon.me/jeanrene?from=emailsignature&access=65b8b3e1677d51e77b65c69e8bd3fdc30ecbebb6

1reaction
jr-grenoblecommented, Dec 1, 2017

@platinumazure I just played with a local version so far and I didn’t write any corresponding tests beyond checking on some of my own code that it produced the right results. Here’s the diff:

@@ -600,6 +600,9 @@ module.exports = {
                                 pattern: ":exit$"
                             }
                         }
+                    },
+                    banner: {
+                        type: "boolean"
                     }
                 },
                 additionalProperties: false
@@ -638,6 +641,7 @@ module.exports = {
             ObjectExpression: 1,
             ImportDeclaration: 1,
             flatTernaryExpressions: false,
+            banner: false,
             ignoredNodes: []
         };
 
@@ -783,6 +787,7 @@ module.exports = {
          */
         function addElementListIndent(elements, startToken, endToken, offset) {
 
+
             /**
              * Gets the first token of a given element, including surrounding parentheses.
              * @param {ASTNode} element A node in the `elements` list
@@ -803,7 +808,7 @@ module.exports = {
                 startToken,
                 typeof offset === "number" ? offset : 1
             );
-            offsets.setDesiredOffset(endToken, startToken, 0);
+            offsets.setDesiredOffset(endToken, startToken, options.banner ? 1 : 0);
 
             // If the preference is "first" but there is no first element (e.g. sparse arrays w/ empty first slot), fall back to 1 level.
             if (offset === "first" && elements.length && !elements[0]) {
@@ -931,7 +936,7 @@ module.exports = {
                     });
                 }
 
-                offsets.setDesiredOffset(rightParen, leftParen, 0);
+                offsets.setDesiredOffset(rightParen, leftParen, options.banner ? 1 : 0);
             });
         }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Indentation style - Wikipedia
In computer programming, an indentation style is a convention governing the indentation of blocks of code to convey program structure.
Read more >
Artistic Style 3.1
Ratliff style uses attached, indented braces. Switch blocks and class blocks are indented to prevent a 'hanging indent' with following case statements and...
Read more >
Formatting braces: Ratliff / "Banner" style : RSRP-455769
Basically like K&R, except the closing brace matches the body, not the head. for (i = 0; i < ...
Read more >
impact of indentation in programming - arXiv
This paper describes about different indentation styles used in Programming and also describes context of each indentation style. It also describes indentation.
Read more >
Indent style - Informatics Engineering | Wiki eduNitas.com
Indent style Informatics Engineering Indent style In computer programming an indent ... 3.7 Pico style; 3.8 Banner style; 3.9 Lisp style; 3.10 Ratliff...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found