Bug 1455112 - 2. Add eslint rules to enforce debug/warn usage; r=esawin
authorJim Chen <nchen@mozilla.com>
Thu, 19 Apr 2018 14:41:24 -0400
changeset 468046 345d021363fb1449e5925316dea75e381f1c82bd
parent 468045 2cd06fff80fe7f57efda98eeac6ae09beea767bc
child 468047 9c43c32dc98e6bedc61e2d30369d72c59b3810f8
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1455112
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1455112 - 2. Add eslint rules to enforce debug/warn usage; r=esawin Add some eslint rules to prevent mistakes and help correct debug/warn usage. * Make sure debug/warn are used with template literals. * Make sure debug/warn are used with single template literal instead of concatenated expressions. * Make sure debug/warn literals don't include unnecessary JSON.stringify calls. MozReview-Commit-ID: LOLYbwIxGuf
mobile/android/.eslintrc.js
--- a/mobile/android/.eslintrc.js
+++ b/mobile/android/.eslintrc.js
@@ -30,10 +30,41 @@ module.exports = {
       "modules/WebsiteMetadata.jsm",
       // Bug 1425051.
       "tests/browser/robocop/**",
     ],
     rules: {
       "no-unused-vars": "off",
       "no-undef": "off",
     }
+  }, {
+    files: [
+      "chrome/geckoview/**",
+      "components/geckoview/**",
+      "modules/geckoview/**",
+    ],
+    rules: {
+      "no-restricted-syntax": [
+        "error",
+        {
+            "selector": `CallExpression > \
+                         Identifier.callee[name = /^debug$|^warn$/]`,
+            "message": "Use debug and warn with template literals, e.g. debug `foo`;",
+        },
+        {
+            "selector": `BinaryExpression[operator = '+'] > \
+                         TaggedTemplateExpression.left > \
+                         Identifier.tag[name = /^debug$|^warn$/]`,
+            "message": "Use only one template literal with debug/warn instead of concatenating multiple expressions,\n" +
+                       "    e.g. (debug `foo ${42} bar`) instead of (debug `foo` + 42 + `bar`)",
+        },
+        {
+            "selector": `TaggedTemplateExpression[tag.type = 'Identifier'][tag.name = /^debug$|^warn$/] > \
+                         TemplateLiteral.quasi CallExpression > \
+                         MemberExpression.callee[object.type = 'Identifier'][object.name = 'JSON'] > \
+                         Identifier.property[name = 'stringify']`,
+            "message": "Don't call JSON.stringify within debug/warn literals,\n" +
+                       "    e.g. (debug `foo=${foo}`) instead of (debug `foo=${JSON.stringify(foo)}`)",
+        },
+      ],
+    },
   }],
 };