From 81241b83cf3a95c1560d4080c39bf8b57381656f Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 26 Mar 2016 23:11:23 -0700 Subject: [PATCH] [eslint config] [breaking] add `no-useless-escape` rule. --- README.md | 14 ++++++++++++++ .../eslint-config-airbnb/rules/best-practices.js | 3 +++ 2 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 8233e491..664b2492 100644 --- a/README.md +++ b/README.md @@ -547,6 +547,20 @@ Other Style Guides - [6.5](#strings--eval) Never use `eval()` on a string, it opens too many vulnerabilities. + + - [6.6](#strings--escaping) Do not unnecessarily escape characters in strings. eslint: [`no-useless-escape`](http://eslint.org/docs/rules/no-useless-escape) + + > Why? Backslashes harm readability, thus they should only be present when necessary. + + ```javascript + // bad + const foo = '\'this\' \i\s \"quoted\"'; + + // good + const foo = '\'this\' is "quoted"'; + const foo = `'this' is "quoted"`; + ``` + **[⬆ back to top](#table-of-contents)** diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index ff782a5b..e9a00265 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -113,6 +113,9 @@ module.exports = { 'no-unused-labels': 2, // disallow unnecessary .call() and .apply() 'no-useless-call': 0, + // disallow unnecessary string escaping + // http://eslint.org/docs/rules/no-useless-escape + 'no-useless-escape': 2, // disallow use of void operator 'no-void': 0, // disallow usage of configurable warning terms in comments: e.g. todo