Search code examples
javascriptintellij-ideaintellij-2020

How to stop IntelliJ IDEA splitting strings in Javascript?


I am trying to write some SQL code as a string within Node.js (Javascript) and each time I press the enter key IntelliJ is splitting the string like such:

This:

db.query('SELECT insertRecord($id, $name, $location, $title)');

Becomes this:

db.query('SELECT insertRecord(' +
'$id,' +
'$name,' +
'$location,' + 
'$title)');

Which is insanely annoying to the point of being unworkable. I just want it to do this:

db.query('SELECT insertRecord(
  $id, 
  $name, 
  $location, 
  $title)'
);

This is not SQL string splitting which can be turned on/off in File > Settings > Editor > Smart Keys > SQL. This seems to be Javascript string splitting for which I can't find an on/off option. Is there a way to stop this behaviour?


Solution

  • JavaScript doesn't allow line breaks in string literals (in double/single quotes), the IDE adds concatenation to keep your code valid. If you need adding line breaks to your strings for better readability, turn your string literals into template literals by changing quotes to backticks. This can be done using intention available on Alt+Enter:

    enter image description here