Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
140 views
in Technique[技术] by (71.8m points)

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?

question from:https://stackoverflow.com/questions/65944649/how-to-stop-intellij-idea-splitting-strings-in-javascript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...