Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement][Track] Formatting tools with KCL Code style specifications #627

Open
5 of 7 tasks
Peefy opened this issue Jul 31, 2023 · 4 comments
Open
5 of 7 tasks
Assignees
Labels
tool Issues or PRs related to kcl tools inlucding format, lint, validation, document tools, etc. track

Comments

@Peefy
Copy link
Contributor

Peefy commented Jul 31, 2023

Enhancement

Spec: https://kcl-lang.io/docs/reference/lang/spec/codestyle

  • Before formatting
import path.to.package
config = package.Config {}
  • After formatting
import path.to.package

config = package.Config {}
  • 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
a = 1
b = 2

c = 3


d = 4
  • After formatting
a = 1
b = 2

c = 3

d = 4
  • For the attribute list of list/dict/schema, keep the user's line breaks.
config = {
     key = "value"
} # To prevent format to `config = {key = "value"}`
  • Wrong error recovery for list/dict
a = ["a"
"b"
]
  • Unexpected lambda expression empty line.

Before format

f = lambda x {
    x
}(1)

After format

f = lambda x {
    x

}(1)

to be discussed:

@Peefy Peefy added help wanted Extra attention is needed good first issue Good for newcomers labels Jul 31, 2023
@Peefy Peefy added this to the v0.6.0 Release milestone Jul 31, 2023
@Peefy Peefy added the tool Issues or PRs related to kcl tools inlucding format, lint, validation, document tools, etc. label Jul 31, 2023
@Peefy Peefy removed good first issue Good for newcomers help wanted Extra attention is needed labels Aug 24, 2023
@Peefy Peefy modified the milestones: v0.6.0 Release, v0.7.0 Release Sep 11, 2023
@amyXia1994
Copy link
Contributor

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 Peefy added the track label Oct 8, 2023
@Peefy Peefy changed the title [Enhancement] Formatting tools with KCL Code style specifications [Enhancement][Track] Formatting tools with KCL Code style specifications Oct 8, 2023
@Peefy Peefy unassigned Peefy and NeverRaR Oct 9, 2023
@amyXia1994
Copy link
Contributor

amyXia1994 commented Oct 18, 2023

@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).

@amyXia1994
Copy link
Contributor

amyXia1994 commented Oct 18, 2023

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):

  • empty lines between stmts should be formatted based on the user's line feed behavior: a. No empty lines between stmts should be kept as it is. b. multiple empty lines between stmts should be formatted to one empty line.
  • whether to write line breaks between each entry in the list/dict/schema expr: a. no line breaks between entries should be kept as it is. b. line breaks between entries should be formatted to one line break.

(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

@Peefy Peefy unassigned He1pa Dec 25, 2023
@Peefy Peefy modified the milestones: v0.8.0 Release, v0.9.0 Release Feb 22, 2024
@Peefy
Copy link
Contributor Author

Peefy commented Mar 27, 2024

Related Impl: https://github.com/kcl-lang/tree-sitter-kcl

@Peefy Peefy assigned He1pa and unassigned zong-zhe Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tool Issues or PRs related to kcl tools inlucding format, lint, validation, document tools, etc. track
Projects
No open projects
Status: 2023.10 Iteration Done
Development

No branches or pull requests

5 participants