From a0047f1a0fdaa38eca5d5dac81f5df670db6f9e0 Mon Sep 17 00:00:00 2001 From: turtleisaac Date: Thu, 12 Nov 2026 20:17:51 +0000 Subject: [PATCH] Sync Java style rules with NitroViewer Co-authored-by: turtleisaac --- .cursor/rules/java-style.mdc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.cursor/rules/java-style.mdc b/.cursor/rules/java-style.mdc index 2a0ae46..2372a27 100644 --- a/.cursor/rules/java-style.mdc +++ b/.cursor/rules/java-style.mdc @@ -63,9 +63,9 @@ End-of-line braces show up in a minority of files (`MemBuf`, `Buffer`, `BinaryWr A single-statement `if` or `else` may be unbraced. The statement goes on the next line, indented one level. Never `if (x) return;`. -`for` and `while` are braced even when the body is one statement. Brace new loops. +A single-statement `for` or `while` may be unbraced the same way. Brace a loop when the body is longer than one statement. -After a `for` or `while`, leave a blank line before the next statement. That applies to a one-line body and to a braced body. Skip the blank line when the loop is the last thing in the method: the closing brace of the method comes next. +A braced block always gets one blank line after it before the next statement, unless it is the last thing in its enclosing block. A braceless single-line loop or `if` follows the grouping rules below. ```java for (String filename : files) @@ -78,6 +78,18 @@ for (String folderName : folders.keySet()) } ``` +## Blank lines + +Group the lines that do one step, and put one blank line between steps. A run of the same kind of statement stays together. When that run switches to a different kind, add a blank line. + +A long run of the same kind of statement is not one step just because the lines look alike. Split where a new stage begins, when later lines are built from the results above. + +A braced block, anything that ends in `}`, gets one blank line after it before the next statement, unless it is the last thing in its enclosing block. Nested blocks that end together share that one blank line. A braced loop with a `return` after it gets that blank too, even in a short method. The parts of one construct stay joined, with no blank between them: `if`/`else` (including `else if`), `try`/`catch`/`finally`, and `do`/`while`. So `} else {`, `} catch (...) {`, `} finally {`, and `} while (...);` attach to the block before them. The blank line comes after the whole construct. + +A braceless single-line `if`, `for`, or `while` may skip the blank. Tiny guards stay together. A step's lines stay grouped, and a blank line separates steps. A chain of `if`/`return` stays together, and the fallback `return` gets a blank line above it. Back-to-back short similar blocks, and `if` pairs that read like `if`/`else`, get no blank between them. + +Put a blank line before a `return`, except when it is the only line in its block, or when it follows one or two short statements. A braceless loop in a very short block may return on the next line. A braced loop may not. + ## Methods, signatures, tests Leave one blank line between methods. The formatter preserves a blank line that is already there and will not insert one you forgot.