You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!
E.g. semicolons: true to use semicolons at the end of statements (default), and semicolons: false to not use semicolons.
Reacted by Pierre Krafft, Dallin Osmun, Cade Ward, Keith Smith, Cary Landholt, Aaron Shafovaloff, Tim Whitbeck, Rogelio Guzman, Arek Mytych, Pierre-Yves Gérardy and 137 more
Reacted by Justin Makeig, Brenton Simpson, Kevin Gibbons, Chris Adams, Thibault Derousseaux, Matt Mastracci, Ryan Tsao, Yavuz Ege Özcan, Rafael Hengles, Blaine Kasten and 6 more
Reacted by Tao, Richard Lindhout and Chrıs Seelus
Reacted by Christoph Werner, Tung Nguyen, Drew Hamlett, Daniel Coffman, Florent Cailhol, James Gillmore, Bill Sourour, XGHeaven, Jesús Darío, Richard Lindhout and 1 more
Reacted by Tom Robinson
Reacted by Tung Nguyen, Kyle Kelley, Eric, Daniel Coffman, Florent Cailhol, James Gillmore and Bill Sourour
@jlongster If you are both accepting PRs and want this feature, I would be more than happy to help with a PR for this one.
Reacted by Wout Mertens, Kyle Mathews, Alan Clarke, Leon, David Mamane, Jun, Kristoffer Dorph, Irakli Gozalishvili, Daniel Coffman, Cory Robinson and 3 more
I'm open to it, but it gets problematic fast. When you don't use semicolons, you run into things like this where you are forced to put a semicolon:
varx=5;[1,2,3].forEach(...)
The first time this would be parsed correctly, but we would output:
varx=5[1,2,3].forEach(...)
which is invalid JS. (at least, not what you want.) This means that in order to support semicolon-less JS we need to code in all the ASI rules so we can see where semicolons are important. I'm not sure I'm willing to take on that complexity just yet.
Feel free to play around with it. Code is powerful and you might convince me. My preference for evolving projects is to take it slowly though, and it's hard to remove things later than to add them, so let's play with it over time and see what we can do. I'd like to keep the number of options low, but this is such a divisive issue that it could be worthwhile.
Reacted by Gael Ollivier, Tobias Andersen, Leon, Dave Methvin, Dave Lesage, Matthew McClure, Artem Sapegin, Davis Clark, Carl Vitullo, Tom Robinson and 6 more
how about auto-detecting depending on the existing code ? If it has semi-colons, output semi-colons, if not, do not output them ?
Reacted by Charlike Mike Reagent, Gustavo Rodrigues, Jamon Holmgren, Artem Yavorsky, Tim, Rude, ingf, Caleb Eby, David Thompson, Alex Wilson and 1 more
Reacted by Emil Sågfors, Irakli Gozalishvili, Alfonso Embid-Desmet and Hen Greville
I use standard.js, which is a popular no-configuration style guide & linter. They insist on a semicolon-free style, and the only rule needed to make this work is to never start a line with (, [, or `.
I would love to see standard.js and prettier be compatible one day.
Reacted by Jesper Ek, Josh Duff, Kent C. Dodds, Seb Insua, Leon, Charlike Mike Reagent, gavrilyak, Mateo Murphy, Trevor Gerhardt, Gustavo Rodrigues and 71 more
Reacted by Atanas Minev, Yavuz Ege Özcan, Rafael Hengles, Blaine Kasten, Steve Heffernan, Fabricio C Zuardi, Tom Robinson, Cody Hatch and Fernando Montoya
Reacted by Christoph Werner, Stefan Maric, Irakli Gozalishvili, Cory Robinson, Christopher Bradshaw and Zach Dahl
It's worth mentioning that "the only rule needed to make this work" will get progressively more complex as the language evolves. For example, under the popular public fields proposals these two classes differ:
classA{setfoo(x){}// setter for 'foo'}classB{set;// uninitialized field named 'set'foo(x){}// method named 'foo'}
So, keep in mind that the complexity cost comes not just now but also in the future. (I don't think this is well understood by people using this style.)
Reacted by Atanas Minev, Yavuz Ege Özcan, Rafael Hengles, Carl Vitullo, Steve Heffernan, Danny Martini, Rory O’Kane, Nikola Kovacs, Timon van Spronsen, Martijn Senden and 7 more
Huh. I found cool thing. Because I'm moving to Atom and just using ESLint instead of Standard, i just love the combo of Linter, Linter-ESLint + eslintrc, and atom prettier :D
It is just a whole show, because I had semi: [2, always], but atom linter can autofix (on save) the fixable errors, so I'm still no writing semicolons. Between that phase prettier prittifies and changes single quotes to double quotes (eslint warns me for a milliseconds there is doublequotes) and Atom Linter (because eslintrc) converts them back to singlequotes and insert the semicolons.
There has a bit of delay between them and it can be seen what does what.
Cool. I'm moving back to semicolons because the AtomLinter.
As I know SublimeLinter don't have support for autofix.
edit: So in short. I also wanted that option, but it seems AtomLinter comes to the rescue and can be easily fixed if you use ESLint, not some "standards" or "semistandards" :)
@bakkot Yes, indeed, in this case the semicolon injection needs to happen after the keywords set and get in classes if used as class field names. Indeed, this is extra maintenance. But is it a lot of maintenance? Will there be a lot of cases like this? Personally I'm skeptical.
Seems as simple as looking that there's a linebreak/whitespace there
However, that goes against the rules of JavaScript. A JavaScript engine will parse it as "thing"[1] no matter what. I don’t think a code formatter should treat "thing" [1] as "thing";[1] which alters the meaning of the code.
P.S. I think the implications of using a semicolon-free style has already been well studied and there are already linter rules to avoid making mistakes in both styles. I would suggest to focus the discussion more on the complexity incurred and implementation effort required.
Reacted by Kent C. Dodds, tsemerad, Rory O’Kane, Mael, Gabriel Knoy and Gregory Desfour
Omg. "with tabs". I can't understand why complexing the tools (not talking only specifically for prettier) when there always are workarounds with other tools and existing workflow? But yea, our different styles in that community kills us.
Reacted by Kent C. Dodds, Hawken Rives, Thai Pangsakulyanont, Shubham Kanodia, Hen Greville and Federico Vázquez
Reacted by Kent C. Dodds, Hawken Rives, Cody Hatch and Shubham Kanodia
I personally believe that tabs are the correct way to indent code
I won't compromise for a workaround. I want it as a first-class option.
I know I can't change what the majority of the community uses, but I cannot and will not adapt into it simply because it is what the majority uses, but only if someone manages to convince me it is a technically better option.
locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!
Activity
rogeliog commentedon Jan 10, 2017
@jlongster If you are both accepting PRs and want this feature, I would be more than happy to help with a PR for this one.
jlongster commentedon Jan 10, 2017
I'm open to it, but it gets problematic fast. When you don't use semicolons, you run into things like this where you are forced to put a semicolon:
The first time this would be parsed correctly, but we would output:
which is invalid JS. (at least, not what you want.) This means that in order to support semicolon-less JS we need to code in all the ASI rules so we can see where semicolons are important. I'm not sure I'm willing to take on that complexity just yet.
Feel free to play around with it. Code is powerful and you might convince me. My preference for evolving projects is to take it slowly though, and it's hard to remove things later than to add them, so let's play with it over time and see what we can do. I'd like to keep the number of options low, but this is such a divisive issue that it could be worthwhile.
gaelollivier commentedon Jan 10, 2017
Have two suggestions:
swansontec commentedon Jan 10, 2017
I use standard.js, which is a popular no-configuration style guide & linter. They insist on a semicolon-free style, and the only rule needed to make this work is to never start a line with
(,[, or `.I would love to see standard.js and prettier be compatible one day.
K-Leon commentedon Jan 10, 2017
I would love seeing this integrated - is currently the only show stopper for me.
// Edit: Standard Packe had 200k+ Downloads last Month - i think it's something that matters for a lot of people in the JS Community
bakkot commentedon Jan 11, 2017
It's worth mentioning that "the only rule needed to make this work" will get progressively more complex as the language evolves. For example, under the popular public fields proposals these two classes differ:
(Note that babylon currently gets these edge cases wrong in a number of exciting ways.)
Presumably a no-semi style would have you writing
So, keep in mind that the complexity cost comes not just now but also in the future. (I don't think this is well understood by people using this style.)
tunnckoCore commentedon Jan 11, 2017
Huh. I found cool thing. Because I'm moving to Atom and just using ESLint instead of Standard, i just love the combo of Linter, Linter-ESLint + eslintrc, and atom prettier :D
It is just a whole show, because I had
semi: [2, always], but atom linter can autofix (on save) the fixable errors, so I'm still no writing semicolons. Between that phase prettier prittifies and changes single quotes to double quotes (eslint warns me for a milliseconds there is doublequotes) and Atom Linter (because eslintrc) converts them back to singlequotes and insert the semicolons.There has a bit of delay between them and it can be seen what does what.
Cool. I'm moving back to semicolons because the AtomLinter.
As I know SublimeLinter don't have support for autofix.
edit: So in short. I also wanted that option, but it seems AtomLinter comes to the rescue and can be easily fixed if you use ESLint, not some "standards" or "semistandards" :)
MoOx commentedon Jan 11, 2017
Just have a simple question.
If people write
how do you know the person wanted to write
and not
My point is "how do we know?" because if we know, we can add or prepend a semicolon, so same thing right?
dtinth commentedon Jan 11, 2017
I tried piping the result of
prettierintostandard --fixand the result is quite promising: prettier-standard-formatter.If the user doesn’t include a semicolon in front, these two lines gets squashed into the same line, clearing any ambiguity.
wmertens commentedon Jan 11, 2017
@MoOx There is only one way that your example will be parsed (so one canonical AST), and only two ways that prettier should output it:
with semi:
without semi:
The rule is simply: remove semi at end of line, and insert semi at beginning of line, before array literal, parens block, or template string.
MoOx commentedon Jan 11, 2017
I know that. My idea is "what if people write this by mistake". I guess the response is "pebkac".
wmertens commentedon Jan 11, 2017
@bakkot Yes, indeed, in this case the semicolon injection needs to happen after the keywords
setandgetin classes if used as class field names. Indeed, this is extra maintenance. But is it a lot of maintenance? Will there be a lot of cases like this? Personally I'm skeptical.timdorr commentedon Jan 11, 2017
@MoOx
Seems as simple as looking that there's a linebreak/whitespace there and assuming they intended to have those two tokens be separate. Basically:
dtinth commentedon Jan 11, 2017
@timdorr
However, that goes against the rules of JavaScript. A JavaScript engine will parse it as
"thing"[1]no matter what. I don’t think a code formatter should treat"thing" [1]as"thing";[1]which alters the meaning of the code.@MoOx
The no-unexpected-multiline ESLint rule will warn people about this 😃.
P.S. I think the implications of using a semicolon-free style has already been well studied and there are already linter rules to avoid making mistakes in both styles. I would suggest to focus the discussion more on the complexity incurred and implementation effort required.
23 remaining items
tunnckoCore commentedon Jan 20, 2017
Omg. "with tabs". I can't understand why complexing the tools (not talking only specifically for prettier) when there always are workarounds with other tools and existing workflow? But yea, our different styles in that community kills us.
rhengles commentedon Jan 20, 2017
@tunnckoCore
For a few reasons:
I know I can't change what the majority of the community uses, but I cannot and will not adapt into it simply because it is what the majority uses, but only if someone manages to convince me it is a technically better option.
sheerun commentedon Mar 16, 2017
I'm pasting the link to my package I've created specifically to fix this issue, as this thread is the first on google when you search for "prettier semicolons": https://github.com/sheerun/prettier-standard
I hope prettier will support no-semi rule soon enough, though!
MadelineRitchie commentedon May 3, 2017
For anyone finding this via Google, note that prettier supports this option now, per this PR:
#1129
alexgvozden commentedon Jul 6, 2017
eslint.autoFixOnSave is a great option to autofix your code
j-f1 commentedon Jan 12, 2018
@vjeux Should this be unlocked? The option has been added.
j-f1 commentedon Jan 12, 2018
This has been added in #1129.