Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I setup webstorm to automatically add semi-colons to javascript functions, methods, etc

When I write Javascript, I use semi-colons. However when I write in webstorm/phpstorm, it auto completes braces and brackets, but doesn't auto-add a semicolon. I know that isn't required per the standards, etc., but that's the way that I code - and I'm not alone, many people code this way.

Example:

var data = $.ajax({}); 

Normally, webstorm/phpstorm will do this, and leave the cursor inside the curly braces:

var data = $.ajax({}) 

All in the world that I want is to not have to add the semicolon manually and have it just auto-complete as I noted in my first example.

like image 616
tvpmb Avatar asked Aug 04 '12 01:08

tvpmb


People also ask

Do you need to put semi colon in JavaScript?

JavaScript does not require semicolons (other than the one exception you saw earlier). This is because JavaScript is clever and it can add the semicolons where needed automatically. This happens behind the scenes and you will not notice it. This process is called Automatic Semicolon Insertion (ASI).

What is the purpose of semi colons (;) in JavaScript?

The JavaScript parser will automatically add a semicolon when, during the parsing of the source code, it finds these particular situations: when the next line starts with code that breaks the current one (code can spawn on multiple lines) when the next line starts with a } , closing the current block.


1 Answers

There is no way to insert it automatically, you need to use the Complete Statement action (Ctrl+Shift+Enter).

You also need to check that Settings (Preferences on macOS) | Editor | Code Style | JavaScript | Punctuation | Use semicolon to terminate statements option is enabled.

like image 171
CrazyCoder Avatar answered Sep 22 '22 08:09

CrazyCoder