Replies: 1 comment
-
Sadly, not at the moment. I'm fine with just having linting for now. I was thinking of using the AST then outputting a formatted version too. Seems like a custom AST implementation or partial compiler rewrite (enough to get the missing information) are the best options after all. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
@colinkiama
Are you interested in continuing the work with the formatter? I tried several things, here I write them together as some sort of head start:
Using the AST and then writing the AST back in a formatted version.
Pro: It worked really well, and it was easy to write.
Contra: Too much information was missing: E.g. is it
var a = 4 + 5
orvar b = (4 + 5)
Tokenize and build an AST myself
Pro: It would have worked probably really, really good.
Contra: An enormous effort, that requires too much testing and so on
Try to format line-by-line
Pro: ?
Contra: Ugly code, as seen e.g. here
One thing I haven't tried, but was mentioned similarly somewhere in the issue in the upstream repo:
Build the AST, load the entire file into memory (This won't cause issues as such files are rarely bigger than 1MB). Traverse the AST. At each thing look into the file, whether there is e.g. a space between an operator and then add it, if not.
After each edit I would reload the AST, as otherwise all sourcerefs are pointing somewhere else. (Or maybe try traversing in reverse, starting at the last line, to avoid reparsing)
Beta Was this translation helpful? Give feedback.
All reactions