Closed Peefy closed 1 month ago
Hi @Peefy, could you please describe this requirement more detailed? I didn't get it precisely 😶🌫️
The import statement and the following code are left blank on one line
@Peefy I‘ve added some test cases to clarify the expected formatting behaviors on the issues raised above. ptal and verify the golden files. #786
And here are some ambiguities:
Do not format out user reserved blank lines
This statement is kind of ambiguous -- I believe this sentence is not referring to preserving all user-written blank lines (for example, typically only one blank line should be kept between statements, and there shouldn't be any blank lines between entries in list/dict/schema expressions). Could you please clarify the specific cases when blank lines should be preserved?
The import statement and the following code are left blank on one line
Is this statement corresponding to the rule "Break one blank line between different statements e.g., import, schema and expression statements."? If so, I think this is exactly the same as another case to fix that you provide: "Leave additional line spacing between schema definitions and imports"
It would be helpful if you could provide some code examples (or you can directly add some file.input
and file.golden
).
cc @NeverRaR , @Peefy , @i-zhen
Here are some cases that the formatting behavior depends on the CST(which records the original token infos such as parenthesis, comments, whitespace and line breaks):
(the code samples could be found in this issue's initial content)
and the tracking issue of the context of the (Lossless/Describing/Concrete) Syntax Tree
Related Impl: https://github.com/kcl-lang/tree-sitter-kcl
Enhancement
Spec: https://kcl-lang.io/docs/reference/lang/spec/codestyle
[X] The import statement and the following code are left blank on one line, leave additional line spacing between schema definitions and imports. fixed in #792
Before formatting
[X] For the union type, leave space between all types e.g.,
"Alice" | "Bob"
instead of"Alice"|"Bob"
: fixed in #790[x] Sometimes do not format out user-reserved blank lines: which does not mean that to preserve all user-written blank lines (for example, typically only one blank line should be kept between statements, and there shouldn't be any blank lines between entries in list/dict/schema expressions).
Before formatting
Before format
After format
to be discussed: