6.2Strings / Line Length

長い文字列の連結

100文字を超える長い文字列は、文字列連結で複数行に分割しないでください。分割された文字列は扱いにくく、コードの検索性を低下させます。

文字列を `+` 演算子で連結して複数行に分けると、可読性が低下し、検索(例:「Batman had anything」で検索したい場合)も困難になります。一行が長くなっても、文字列リテラルは分割しない方が、結果としてメンテナンスしやすくなります。

❌ Bad
// bad
const errorMessage = 'This is a super long error that was thrown because ' +
  'of Batman. When you stop to think about how Batman had anything to do ' +
  'with this, you would get nowhere fast.';
✅ Good
// good
const errorMessage = 'This is a super long error that was thrown because of Batman. When you stop to think about how Batman had anything to do with this, you would get nowhere fast.';