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

Viewed 28304

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.

13 Answers

For IntelliJ Idea 2018, follow the steps below:

  • Open Settings: Ctrl+Alt+S
  • Editor>Code Style>JavaScript
  • Select Tab > Punctuation
  • In dropdown, select "Use/Use always" semicolon to terminate statements
  • Apply and OK

This will add extra semicolon in JS.

You can automatically have webstorm or phpstorm add the semi-colon for you.

This is how for webstorm:

Preferencess --> Editor --> Code Style --> Javascript --> Punctuation

In the semi-colon to terminate statements, select always.

Then anytime you format your code, with a shortcut OPTION+CMD+L it will add the semi-colon

You can also configure reformat to be automatic when you save. That way semi-colon will always get added.

You can use eslint:

set the "semi" rule to "error" or 2

in the file that you'd like to add semi-colons right click and then select Fix ESLint Problems near the bottom of the menu

right click menu

In the latest 2020.3 you can find this here:

enter image description here

For Webstorm 2019.1

1 Select File/Settings... menu.
2 Select Editor/Code Style/JavaScript in the left sidebar of the Settings dialog.

enter image description here

3 Select the Punctuation tab and make sure that the "semicolon to terminate statements" option is "always".

enter image description here

4 Select Code/Reformat from the menu.

Related