From fc8442fef7130a0a50afdd61cd6f854e6ed62bec Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Thu, 4 Aug 2016 09:32:55 -0700 Subject: [PATCH] Reverse rule on string concatenation for long lines Broken and concatenated long strings are painful to work with and produce less readable and searchable code. I think we should reverse this rule. Unfortunately, the max-len rule currently does not allow for this, but there is currently a proposal to add an option to ESLint's max-len rule that would allow for strings to be ignored. https://github.com/eslint/eslint/issues/5805 There have also been discussions around performance of string concatenation (https://github.com/airbnb/javascript/issues/40), but I don't think that is very relevant here so I removed the links to them. --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 353486ccb6..895d621a55 100644 --- a/README.md +++ b/README.md @@ -480,25 +480,24 @@ Other Style Guides ``` - - [6.2](#strings--line-length) Strings that cause the line to go over 100 characters should be written across multiple lines using string concatenation. + - [6.2](#strings--line-length) Strings that cause the line to go over 100 characters should not be written across multiple lines using string concatenation. - - - [6.3](#strings--concat-perf) Note: If overused, long strings with concatenation could impact performance. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40). + > Why? Broken strings are painful to work with and make code less searchable. ```javascript - // 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.'; - // 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 + // 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 + 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.'; ```