Bug 1358050: Add no-implied-eval rule to eslint config r=florian,r?standard8 draft
authorFrederik Braun <fbraun+gh@mozilla.com>
Thu, 20 Apr 2017 10:33:22 +0200
changeset 566220 a67b80725e891a608197376b228b523baf015922
parent 565531 20dff607fb88ee69135a280bbb7f32df75a86237
child 625251 1eb2b9d153f295555c5731deaab727842e699b88
push id55148
push userbmo:fbraun@mozilla.com
push dateFri, 21 Apr 2017 07:12:14 +0000
reviewersflorian, standard8
bugs1358050
milestone55.0a1
Bug 1358050: Add no-implied-eval rule to eslint config r=florian,r?standard8 MozReview-Commit-ID: KdmpXq2rg1q
.eslintrc.js
browser/components/preferences/languages.js
devtools/.eslintrc.js
toolkit/components/places/tests/browser/399606-history.go-0.html
toolkit/components/places/tests/browser/399606-location.reload.html
toolkit/components/places/tests/browser/399606-location.replace.html
toolkit/components/places/tests/browser/399606-window.location.href.html
toolkit/components/places/tests/browser/399606-window.location.html
tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
tools/lint/eslint/eslint-plugin-mozilla/package.json
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -13,16 +13,18 @@ module.exports = {
     "mozilla/no-import-into-var-and-global": "error",
     "mozilla/no-useless-parameters": "error",
     "mozilla/no-useless-removeEventListener": "error",
     "mozilla/use-default-preference-values": "error",
     "mozilla/use-ownerGlobal": "error",
 
     // No (!foo in bar) or (!object instanceof Class)
     "no-unsafe-negation": "error",
+    // No eval() and no strings in the first param of setTimeout or setInterval
+    "no-implied-eval": "error",
   },
   "env": {
     "es6": true
   },
   "parserOptions": {
     "ecmaVersion": 8,
   },
 };
--- a/browser/components/preferences/languages.js
+++ b/browser/components/preferences/languages.js
@@ -14,17 +14,19 @@ var gLanguagesDialog = {
     if (!this._availableLanguagesList.length)
       this._loadAvailableLanguages();
   },
 
   // Ugly hack used to trigger extra reflow in order to work around XUL bug 1194844;
   // see bug 1194346.
   forceReflow() {
     this._activeLanguages.style.fontKerning = "none";
-    setTimeout("gLanguagesDialog._activeLanguages.style.removeProperty('font-kerning')", 0);
+    setTimeout(() => {
+      this._activeLanguages.style.removeProperty("font-kerning")
+    }, 0);
   },
 
   get _activeLanguages() {
     return document.getElementById("activeLanguages");
   },
 
   get _availableLanguages() {
     return document.getElementById("availableLanguages");
--- a/devtools/.eslintrc.js
+++ b/devtools/.eslintrc.js
@@ -228,16 +228,18 @@ module.exports = {
     // Disallow unnecessary semicolons.
     "no-extra-semi": "error",
     // Deprecated, will be removed in 1.0.
     "no-extra-strict": "off",
     // Disallow fallthrough of case statements, except if there is a comment.
     "no-fallthrough": "error",
     // Allow the use of leading or trailing decimal points in numeric literals.
     "no-floating-decimal": "off",
+    // disallow use of eval()-like methods
+    "no-implied-eval": "error",
     // Allow comments inline after code.
     "no-inline-comments": "off",
     // Disallow if as the only statement in an else block.
     "no-lonely-if": "error",
     // Allow mixing regular variable and require declarations (not a node env).
     "no-mixed-requires": "off",
     // Disallow mixed spaces and tabs for indentation.
     "no-mixed-spaces-and-tabs": "error",
@@ -422,18 +424,16 @@ module.exports = {
     // allow/disallow an empty newline after var statement
     "newline-after-var": "off",
     // disallow the use of alert, confirm, and prompt
     "no-alert": "off",
     // disallow comparisons to null without a type-checking operator
     "no-eq-null": "off",
     // disallow overwriting functions written as function declarations
     "no-func-assign": "off",
-    // disallow use of eval()-like methods
-    "no-implied-eval": "off",
     // disallow function or variable declarations in nested blocks
     "no-inner-declarations": "off",
     // disallow invalid regular expression strings in the RegExp constructor
     "no-invalid-regexp": "off",
     // disallow irregular whitespace outside of strings and comments
     "no-irregular-whitespace": "off",
     // disallow usage of __iterator__ property
     "no-iterator": "off",
--- a/toolkit/components/places/tests/browser/399606-history.go-0.html
+++ b/toolkit/components/places/tests/browser/399606-history.go-0.html
@@ -1,11 +1,13 @@
 <html>
 <head>
 <title>history.go(0)</title>
 <script>
-setTimeout("history.go(0)", 1000);
+setTimeout(function() {
+  history.go(0)
+}, 1000);
 </script>
 </head>
 <body>
 Testing history.go(0)
 </body>
 </html>
--- a/toolkit/components/places/tests/browser/399606-location.reload.html
+++ b/toolkit/components/places/tests/browser/399606-location.reload.html
@@ -1,11 +1,13 @@
 <html>
 <head>
 <title>location.reload()</title>
 <script>
-setTimeout("location.reload();", 100);
+setTimeout(function() {
+  location.reload();
+}, 100);
 </script>
 </head>
 <body>
 Testing location.reload();
 </body>
 </html>
--- a/toolkit/components/places/tests/browser/399606-location.replace.html
+++ b/toolkit/components/places/tests/browser/399606-location.replace.html
@@ -1,11 +1,13 @@
 <html>
 <head>
 <title>location.replace</title>
 <script>
-setTimeout("location.replace(window.location.href)", 1000);
+setTimeout(function() {
+  location.replace(window.location.href)
+}, 1000);
 </script>
 </head>
 <body>
 Testing location.replace
 </body>
 </html>
--- a/toolkit/components/places/tests/browser/399606-window.location.href.html
+++ b/toolkit/components/places/tests/browser/399606-window.location.href.html
@@ -1,11 +1,13 @@
 <html>
 <head>
 <title>window.location.href</title>
 <script>
-setTimeout("window.location.href = window.location.href", 1000);
+setTimeout(function() {
+  window.location.href = window.location.href
+}, 1000);
 </script>
 </head>
 <body>
 Testing window.location.href
 </body>
 </html>
--- a/toolkit/components/places/tests/browser/399606-window.location.html
+++ b/toolkit/components/places/tests/browser/399606-window.location.html
@@ -1,11 +1,13 @@
 <html>
 <head>
 <title>window.location</title>
 <script>
-setTimeout("window.location = window.location", 1000);
+setTimeout(function() {
+  window.location = window.location
+}, 1000);
 </script>
 </head>
 <body>
 Testing window.location
 </body>
 </html>
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
@@ -109,16 +109,19 @@ module.exports = {
     "no-dupe-keys": "error",
 
     // No duplicate cases in switch statements
     "no-duplicate-case": "error",
 
     // Disallow unnecessary calls to .bind()
     "no-extra-bind": "error",
 
+    // Disallow eval and setInteral/setTimeout with strings
+    "no-implied-eval": "error",
+
     // No labels
     "no-labels": "error",
 
     // Disallow unnecessary nested blocks
     "no-lone-blocks": "error",
 
     // If an if block ends with a return no need for an else block
     "no-else-return": "error",
--- a/tools/lint/eslint/eslint-plugin-mozilla/package.json
+++ b/tools/lint/eslint/eslint-plugin-mozilla/package.json
@@ -1,11 +1,11 @@
 {
   "name": "eslint-plugin-mozilla",
-  "version": "0.2.41",
+  "version": "0.2.42",
   "description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
   "keywords": [
     "eslint",
     "eslintplugin",
     "eslint-plugin",
     "mozilla",
     "firefox"
   ],