rdio / jsfmt

For formatting, searching, and rewriting JavaScript.
http://rdio.github.io/jsfmt/
Other
1.69k stars 71 forks source link

Fix common mistakes like gofmt. #132

Open djcas9 opened 9 years ago

djcas9 commented 9 years ago

I just wanted to open a ticket to get a conversation started on this concept.

Example, if i goofed and wrote:

if typeof word === function {
  console.log("cool")
}

could it fix that by wrapping the expression in ( ) like gofmt does.

if (word) {
}; // remove the `;`

If this is a direction people would interested in what would be the cleanest way to start adding this type of functionality.

jimfleming commented 9 years ago

Yah, I often use 2-3 languages a day (backend, frontend, etc.) and mistakes like you illustrate above are very common. Adding in missing semi-colons or extraneous symbols sounds doable as part of the formatting (probably with an option). It might make sense as an esformatter plugin that we bundle by default.

The difficulty on our end will be that we use Esprima which is not very resilient to syntax errors. In Go's case, both syntaxes are valid (with or without parens). There's a "tolerant" mode in Esprima that's in progress but I'm not sure how far along it is.

lukescott commented 9 years ago

This is related to issue #2. As you can see by the 2nd comment, it takes some patching. But then again that issue is 1 year old.