News for hackers. Stuff that matters.
Re:Alternative code styles by emodendroket on Monday October 15, 2018 @09:51AM (#18219610)
There are some limits to what you can automate but stuff like spacing should definitely be enforced by a tool.
Re:Alternative code styles by jeremy_wiebe on Monday October 15, 2018 @01:00PM (#18221442)
I feel like Prettier does a really good job with JavaScript.

What situations have you found where automated formatting doesn’t suffice or has these limits?

Re:Alternative code styles by paulddraper on Monday October 15, 2018 @01:25PM (#18221666)
Ordering code.

Some tools order/deduplicate imports. Prettier does not. [1]

And no tool that I've seen orders fields/constructor/method, etc.

[1] https://github.com/prettier/prettier/issues/949

Re:Alternative code styles by jeremy_wiebe on Monday October 15, 2018 @01:31PM (#18221714)
Interesting, yeah, that’s definitely missing. ESLint has rules for ordering, feels like it’d be a relatively simple addition to prettier.
Re:Alternative code styles by eropple on Monday October 15, 2018 @01:34PM (#18221750)
In JavaScript, imports sometimes (too often, really) have side effects. I don't know if it makes sense for prettier to do that, at least by default.
Re:Alternative code styles by michaelmior on Monday October 15, 2018 @04:06PM (#18223204)
I don't have a problem with anything that discourages imports with side effects. You can always ignore[0] any cases where this happens.

[0] https://prettier.io/docs/en/ignore.html

Re:Alternative code styles by paulddraper on Monday October 15, 2018 @02:13PM (#18222137)
In my experience, side-effecting imports are fairly uncommon.

But in any cases, all formatters allow you to selectively disable it for certain liners.

Re:Alternative code styles by dvlsg on Monday October 15, 2018 @05:01PM (#18223713)
Hopefully uncommon, anyways. Imports with side effects sounds like a nightmare to debug.
Re:Alternative code styles by paulddraper on Monday October 15, 2018 @02:14PM (#18222151)
> it’d be a relatively simple addition to prettier.

It would be, but as you can see in the linked issue, it was closed for being a non-goal. So, it's not likely to change.

(Prettier generally keeps the AST identical; i.e. whitespace and parentheses changes only.)

Re:Alternative code styles by chrisweekly on Monday October 15, 2018 @02:02PM (#18222037)
eslint and prettier are not mutually exclusive
Re:Alternative code styles by jeremy_wiebe on Monday October 15, 2018 @08:06PM (#18225277)
I didn’t mean to imply that. In fact we use eslint + prettier where I work.
Re:Alternative code styles by eberkund on Monday October 15, 2018 @04:08PM (#18223218)
I don't know if it supports JavaScript but Resharper does this for .Net
Re:Alternative code styles by reitanqild on Monday October 15, 2018 @05:37PM (#18224028)
I think all three major Java IDEs do this as well.
Re:Alternative code styles by edflsafoiewq on Monday October 15, 2018 @07:11PM (#18224876)
Humans format with rules that take into account semantic information, symmetry, and aesthetics. They know that a function call that gives the entries of a matrix is formatted as a grid for a reason even when the auto-formatter could fit it on one line. They know that that arm of the match that would be formatted weird if it were on its own is actually formatted well because it exhibits that case's consistency with the other cases in the match. Probably the most important formatting decision they make is to, rather than format a long line, break it into intermediate results and store them in local variables given human-meaningful names.