Danny
Danny

Reputation: 21

Putting Curly braces into javascript if's without curly braces?

What I want: Transforming this: if(a == b) //statement into: if(a == b) { //statement } Simply put: I want my single line if's to have their braces once again, and I need some program or plugin or some code, that would run over my code, and transform it to one with braces on every if.

How?

Thanks in advance, Danny.

Upvotes: 2

Views: 688

Answers (1)

DVK
DVK

Reputation: 129413

In general, doing this yourself (as code) is a pretty tough task - basically, you would need to correctly parse JavaScript's grammar.

You may be able to write some regexes to do it in very specifically formatted cases (e.g. when your statement is 100% on the same line as the if or 100% on the line followwing the if; and the if itself is the first non-whitespace in the line.

Upvotes: 1

Related Questions