From 30d7c84b373ac19a72789af8fe16fffa919ee16d Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Fri, 23 Aug 2024 11:56:11 +0200 Subject: [PATCH] Add formatting of newlines in blocks and trailing commas to README --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/README.md b/README.md index 77bd29e..86383d4 100644 --- a/README.md +++ b/README.md @@ -242,11 +242,13 @@ This is a list of things that Runic currently is doing: - [Toggle formatting](#toggle-formatting) - [Line width limit](#line-width-limit) + - [Newlines in blocks](#newlines-in-blocks) - [Indentation](#indentation) - [Spaces around operators, assignment, etc](#spaces-around-operators-assignment-etc) - [Spaces around keywords](#spaces-around-keywords) - [Multiline listlike expressions](#multiline-listlike-expressions) - [Spacing in listlike expressions](#spacing-in-listlike-expressions) + - [Trailing semicolons](#trailing-semicolons) - [Literal floating point numbers](#literal-floating-point-numbers) - [Literal hex and oct numbers](#literal-hex-and-oct-numbers) - [Parentheses around operator calls in colon](#parentheses-around-operator-calls-in-colon) @@ -293,6 +295,28 @@ file. No. Use your Enter key or refactor your code. +### Newlines in blocks + +The body of blocklike expressions (e.g. `if`, `for`, `while`, `function`, `struct`, etc.) +always start and end with a newline. Examples: +```diff +-if c x end ++if c ++ x ++end + +-function f(x) x^2 end ++function f(x) ++ x^2 ++end +``` + +An exception is made for empty blocks so that e.g. +```julia +struct A end +``` +is allowed. + ### Indentation Consistently four spaces for each indentation level. @@ -523,6 +547,24 @@ Leading/trailing spaces are removed. Examples: help with alignment issues. Discussed in issue [#12](https://github.com/fredrikekre/Runic.jl/issues/12). +### Trailing semicolons + +Trailing semicolons are removed in the body of blocklike expressions. Examples +```diff + function f(x) +- y = x^2; +- z = y^2; # z = x^4 +- return z; ++ y = x^2 ++ z = y^2 # z = x^4 ++ return z + end +``` + +Trailing semicolons at top level and module level are kept since they are sometimes used +there for output supression (e.g. Documenter examples or scripts that are +copy-pasted/included in the REPL). + ### Literal floating point numbers Floating point literals are normalized so that they: