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

Nested Code Fixes #144

Closed
YangchenYe323 opened this issue Mar 7, 2023 · 4 comments
Closed

Nested Code Fixes #144

YangchenYe323 opened this issue Mar 7, 2023 · 4 comments
Labels
A-linter Area - Linter C-enhancement Category - New feature or request

Comments

@YangchenYe323
Copy link
Contributor

I wonder if it's possible for us to implement nested code fixes. For example, the following expression:
1 & 2 ^ 3 | 4
should be changed to ((1 & 2) ^ 3) | 4, which involves first changing the span 1 & 2 to be (1 & 2) and then changing (1 & 2) ^ 3 to be ((1 & 2) ^ 3).

I noticed our current fixer seems to assume its fix spans are disjoint intervals. Could this be done with our current approach, i.e., manipulating source text directly rather than changing the AST?

@Boshen
Copy link
Member

Boshen commented Mar 7, 2023

cc @jason89521

Unfortunately we are not going to do AST manipulation, it's way too complicated and impedes our development.

But I have two ideas:

  • constructor a small AST, print the snippet, and use the fixer to replace text.
  • write some good utils to construct the snippet

@YangchenYe323
Copy link
Contributor Author

  • write some good utils to construct the snippet

Thanks for your input. I was thinking about the same thing, probably keeping track of how span in the original source changed through all the fixes.

@jason89521
Copy link
Contributor

For mixed operators, I wonder how should we fix this rule. For example, a + b * c can be fixed as (a + b) * c or a + (b * c).

@YangchenYe323
Copy link
Contributor Author

For mixed operators, I wonder how should we fix this rule. For example, a + b * c can be fixed as (a + b) * c or a + (b * c).

The latter is correct in this case because of the precedence. In the AST the multiple node is a parent of the add node, and the fix is parenthesizing the child node.

@Boshen Boshen added C-enhancement Category - New feature or request A-linter Area - Linter labels Mar 29, 2023
@Boshen Boshen closed this as not planned Won't fix, can't repro, duplicate, stale Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter C-enhancement Category - New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants