News for hackers. Stuff that matters.
Re:Jsfmt – Like Gofmt, but for JavaScript by mwsherman on Friday May 09, 2014 @04:51PM (#7723198)
The key here is adoption. Go’s adoption of gofmt is that it was there from the start and the community has adopted it.

It’d be great to have it on the JS side too. It’s a question of everyone agreeing that it’s the right one and achieving critical mass.

Re:Jsfmt – Like Gofmt, but for JavaScript by sambeau on Friday May 09, 2014 @06:44PM (#7723644)
I think you might be missing the point here. gofmt doesn't only enforce a style guide, it has allowed the Go team to change Go's syntax and automatically update everyone's code.

This tool, to me, looks really useful for updating old javascript codebases - removing old library calls and polyfills — bringing in new native techniques.

Re:Jsfmt – Like Gofmt, but for JavaScript by secoif on Saturday May 10, 2014 @11:04AM (#7725630)
Nope, the point about adoption is spot on since you can already do this with esprima and other tools (e.g. substack's falafel/burrito or grasp) which already have a community. Outside of api flavour, they do the same thing. The differentiating factor is primarily which one will have stronger better community support.

My prediction is that since this is "go-flavoured", it will face some (unwarranted) adoption resistance amongst influential JS devs. This tool might attract new devs into the code manipulation space and they'll eventually converge on to the tool with strongest community support.

Re:Jsfmt – Like Gofmt, but for JavaScript by myg204 on Saturday May 10, 2014 @11:37AM (#7725758)
Well it's both really. The formatting fixes offered by gofmt are definitely a popular success. You always hear/read about how great it is to have completely removed the code formatting debates (and it is).
Re:Jsfmt – Like Gofmt, but for JavaScript by ihsw on Friday May 09, 2014 @07:45PM (#7723889)
> it has allowed the Go team to change Go's syntax and automatically update everyone's code

That's go fix.

Re:Jsfmt – Like Gofmt, but for JavaScript by dsymonds on Friday May 09, 2014 @08:11PM (#7723942)
Gofix does the work, but it is only feasible because gofmt exists.
Re:Jsfmt – Like Gofmt, but for JavaScript by stusmall on Friday May 09, 2014 @05:06PM (#7723266)
I think its more that the language enforces some formatting to a degree. Other languages are very free form in how you can structure your style and where to place your curly brace. In go it is a compiler error to deviate from their style.
Re:Jsfmt – Like Gofmt, but for JavaScript by Smerity on Friday May 09, 2014 @05:25PM (#7723331)
It actually isn't a compiler error in Go to deviate from gofmt's specification* but it is a widely enforced rule in the community. Most major Go projects use gofmt and any Go code, such as the built-in libraries, are gofmt'ed. You're fighting against the tide if you format otherwise.

Given that, jsfmt doesn't need 100% adoption: using it in a single project or library would still be useful. Stating new contributions must be jsfmt'ed would be less trouble than most standard pull request requirements (pass + update any relevant testing code, ...).

I personally love these formatting tools and am looking forward to more of them, such as ClangFormat[1].

* You might be thinking of unused variables or imports resulting in compiler errors, which isn't the same as not compiling due to formatting?

[1]: http://clang.llvm.org/docs/ClangFormat.html

Re:Jsfmt – Like Gofmt, but for JavaScript by stusmall on Friday May 09, 2014 @11:02PM (#7724318)
What I was referring to is curly brace placement.

func main() { }

vs

func main() { }

which produces the error "prog.go:4: syntax error: unexpected semicolon or newline before {". As I understand it this is because of the rules of where it will insert semicolons. It isn't enforcing everything about the format which is why I said "to a degree" but it is still one of the most opinionated compilers on format that I know of.

Either way, I'm glad they did it. The "where should the curly brace go" is one of the most annoying bike-sheds.

Re:Jsfmt – Like Gofmt, but for JavaScript by achal on Saturday May 10, 2014 @01:21AM (#7724599)
In case anyone else thinks they're insane, the two are the same. The second one should have been

    func main()
    {
    }
Re:Jsfmt – Like Gofmt, but for JavaScript by stusmall on Saturday May 10, 2014 @09:38AM (#7725341)
Oh thanks! Not sure how it got trashed.
Re:Jsfmt – Like Gofmt, but for JavaScript by jzelinskie on Friday May 09, 2014 @10:11PM (#7724219)
How automatic semi-colon insertion works causes braces to be on the same line as a function signatures/ifs/switches/etc.

This program won't compile: http://play.golang.org/p/8DSev4ZjWZ