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]: Formatter incorrectly formats expressions #39813

Closed
madushajg opened this issue Mar 7, 2023 · 3 comments · Fixed by #39876
Closed

[Bug]: Formatter incorrectly formats expressions #39813

madushajg opened this issue Mar 7, 2023 · 3 comments · Fixed by #39876
Assignees
Labels
Team/DevTools Ballerina Developer Tooling ( CLI, Test FW, Package Management, OpenAPI, APIDocs ) Type/Bug

Comments

@madushajg
Copy link
Contributor

madushajg commented Mar 7, 2023

Description

Most of the time, the formatter performs incorrect formatting when I try to format expressions.

ie:
original source:

population - infantCount

formatted source:

 population- infantCount

--

original source:

age > 18 ? "Adult" : "Child"

formatted source:

age> 18 ? "Adult" : "Child"

Once use case of this is the Ballerina Statement Editor where it performs formatting the snippets before rendering.

Affected Version(s)

Ballerina 2201.3.2

@madushajg madushajg added Type/Bug Team/DevTools Ballerina Developer Tooling ( CLI, Test FW, Package Management, OpenAPI, APIDocs ) labels Mar 7, 2023
@AzeemMuzammil
Copy link
Member

Since we are trying to format syntax erroneous code snippets, the erroneous code snippet gets mapped to a valid Syntax Node with missing Nodes. and the mapped valid syntax node is formatted. In the above-mentioned examples,

  1. population - infantCount gets mapped to FunctionDefinitionNode as MISSING[function]population MISSING[(]- MISSING[]infantCount MISSING[)] MISSING[{] MISSING[}]

  2. age > 18 ? "Adult" : "Child" gets mapped to ModuleVariableDeclarationNode as MISSING[map] MISSING[<]age > MISSING[] MISSING[=]18 ? "Adult" : "Child" MISSING[;].

And formatting works as expected with the erroneous code snippets. And the fix is not possible from the Formatter side.

@AzeemMuzammil
Copy link
Member

Actually, this can be done, we can use NodeParser to achieve the result. @madushajg

@github-actions
Copy link

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/DevTools Ballerina Developer Tooling ( CLI, Test FW, Package Management, OpenAPI, APIDocs ) Type/Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants