-
Couldn't load subscription status.
- Fork 4
Add noNewlineBetweenVar option #14
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
base: master
Are you sure you want to change the base?
Conversation
When true only add a blank line after a run of var statements.
|
This seems reasonable. In fact, it seems so reasonable that I think it should be the default behavior and we can exclude the option to turn it off. I love that you added it as an option and included tests! I'm also surprised that I didn't ignore the vim files earlier. First a bit of discussion: What do you think about this being the default for all people and we just skip the option to disable it? One thing your patch points out is that we lose the context of previous statements. Perhaps a better way to solve this problem in general is to track the context for all fragments, but I view that as adding unnecessary overhead when this condition would rarely be checked. Typically when checking things like this I would inspect tokens, preferring to look backwards in the stream. Since the newlines are added at the point of the semicolon, perhaps it would be easier to look forward. One could modify This would require minor changes to Alternately, we could update The last idea I had was to store the context on the semicolon tokens, but that initially seems like more work and more consumed memory and we'd only utilize this extra information in rare circumstances. In the end I'm leaning strongly towards modifying |
|
On 18 Jun 2015, at 14:18, Tyler Akins [email protected] wrote:
I certainly don’t mind you discarding the work :) Not sure if I have any useful input on the best way to proceed - your problem seems that there’s more than one way to do it - I’d just pick one. Given the quality of your test coverage any misfeatures would be easy enough to refactor in the future. You got me thinking about code formatters in general though. I suspect if I was writing one from scratch I’d build a structure that’d be a cross between an AST and a DOM (which are not necessarily that different to start with). I’d want to be able to do things like balancing array literals (to make them square if they contain suitable number of elements) and horizontally aligning various vertical runs of punctuation - the ‘=‘ signs in a sequence of var foo = require(“…”) for example. But that’s not the question you asked :) Andy Armstrong, Hexten |
Hi there,
Thanks for your excellent code!
I tend to have runs of var statements so it's useful for me to be able to suppress the blank lines between them. I've added a new option to do that: noNewlineBetweenVar (and a corresponding command switch "no-newline-between-var").
I hope it's OK.
Thanks!