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

[bug] format tool: the index signatures in schema stmt are always formatted before attributes #789

Closed
amyXia1994 opened this issue Oct 18, 2023 · 4 comments

Comments

@amyXia1994
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  • create main.k with content:
schema A:
    name: str
    [other: str]: str
  • run kcl-fmt main.k

2. What did you expect to see? (Required)

schema A:
    [other: str]: str
    name: str


3. What did you see instead (Required)

schema A:
    name: str
    [other: str]: str

4. What is your KCL components version? (Required)

@amyXia1994
Copy link
Contributor Author

cause:
The format tool works by printing the ast as the formatted code. And the schema stmt walker always first walk the index signature nodes, then walk the schema body node(which contains the attributes)

image

Since the AST is designed to not include the index signatures in the schema body, the order between the index signatures and attributes is not recorded.

@Peefy Is this the AST is designed to not include the index signatures in the schema body designed in purpose? or could somebody explain why?
cc @NeverRaR

@Peefy
Copy link
Contributor

Peefy commented Oct 18, 2023

@amyXia1994 In a schema, the syntax of index signatures is not close to the syntax of schema attribute definitions, and the order is independent in the schema. We need to define index signatures in the specification as being written as early as possible because they represent the overall composition of schema attributes.

@amyXia1994
Copy link
Contributor Author

@amyXia1994 In a schema, the syntax of index signatures is not close to the syntax of schema attribute definitions, and the order is independent in the schema. We need to define index signatures in the specification as being written as early as possible because they represent the overall composition of schema attributes.

Ok, got it, so the behavior of described in this issue is actually a feature of the code style spec. Let's add new rules to clarify this.

@amyXia1994
Copy link
Contributor Author

tracked in kcl-lang/kcl-lang.io#183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants