Repository: eslint/eslint
Pull request #11116 (2018-11-22 06:46:50)

Chore: Move ignored-paths, report-translator to lib/util (refs #10559)
<!--
    ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).
-->

**What is the purpose of this pull request? (put an "X" next to item)**

[ ] Documentation update
[ ] Bug fix ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/bug-report.md))
[ ] New rule ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/rule-proposal.md))
[ ] Changes an existing rule ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/rule-change-proposal.md))
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[x] Other, please explain: Moving files that are not part of public Node.js API to lib/util folder

Refs #10559.

<!--
    If the item you've checked above has a template, please paste the template questions below and answer them. (If this pull request is addressing an issue, you can just paste a link to the issue here instead.)
-->

<!--
    Please ensure your pull request is ready:

    - Read the pull request guide (https://eslint.org/docs/developer-guide/contributing/pull-requests)
    - Include tests for this change
    - Update documentation for this change (if appropriate)
-->

<!--
    The following is required for all pull requests:
-->

**What changes did you make? (Give an overview)**

Moved lib/ignored-paths to lib/util/ignored-paths, and lib/report-translator to lib/util/report-translator.

**Is there anything you'd like reviewers to focus on?**

Not really.



Patch:
diff --git a/README.md b/README.md
index 572cd8a07..65ee43400 100644
--- a/README.md
+++ b/README.md
@@ -38,7 +38,7 @@ If you want to include ESLint as part of your project's build system, we recomme
 $ npm install eslint --save-dev
 ```
 
-You should then setup a configuration file:
+You should then set up a configuration file:
 
 ```
 $ ./node_modules/.bin/eslint --init
@@ -60,7 +60,7 @@ If you want to make ESLint available to tools that run across all of your projec
 $ npm install -g eslint
 ```
 
-You should then setup a configuration file:
+You should then set up a configuration file:
 
 ```
 $ eslint --init
diff --git a/lib/cli-engine.js b/lib/cli-engine.js
index 652d68b59..ce9fe289b 100644
--- a/lib/cli-engine.js
+++ b/lib/cli-engine.js
@@ -20,7 +20,7 @@ const fs = require("fs"),
     defaultOptions = require("../conf/default-cli-options"),
     Linter = require("./linter"),
     lodash = require("lodash"),
-    IgnoredPaths = require("./ignored-paths"),
+    IgnoredPaths = require("./util/ignored-paths"),
     Config = require("./config"),
     ConfigOps = require("./config/config-ops"),
     LintResultCache = require("./util/lint-result-cache"),
diff --git a/lib/linter.js b/lib/linter.js
index 84a53784a..f37842d76 100644
--- a/lib/linter.js
+++ b/lib/linter.js
@@ -21,7 +21,7 @@ const eslintScope = require("eslint-scope"),
     NodeEventGenerator = require("./util/node-event-generator"),
     SourceCode = require("./util/source-code"),
     Traverser = require("./util/traverser"),
-    createReportTranslator = require("./report-translator"),
+    createReportTranslator = require("./util/report-translator"),
     Rules = require("./rules"),
     timing = require("./util/timing"),
     ConfigCommentParser = require("./util/config-comment-parser"),
diff --git a/lib/rules/camelcase.js b/lib/rules/camelcase.js
index 8aeb4b5bd..6fb8760f1 100644
--- a/lib/rules/camelcase.js
+++ b/lib/rules/camelcase.js
@@ -132,9 +132,10 @@ module.exports = {
 
                 /*
                  * Leading and trailing underscores are commonly used to flag
-                 * private/protected identifiers, strip them
+                 * private/protected identifiers, strip them before checking if underscored
                  */
-                const name = node.name.replace(/^_+|_+$/g, ""),
+                const name = node.name,
+                    nameIsUnderscored = isUnderscored(name.replace(/^_+|_+$/g, "")),
                     effectiveParent = (node.parent.type === "MemberExpression") ? node.parent.parent : node.parent;
 
                 // First, we ignore the node if it match the ignore list
@@ -151,11 +152,11 @@ module.exports = {
                     }
 
                     // Always report underscored object names
-                    if (node.parent.object.type === "Identifier" && node.parent.object.name === node.name && isUnderscored(name)) {
+                    if (node.parent.object.type === "Identifier" && node.parent.object.name === node.name && nameIsUnderscored) {
                         report(node);
 
                     // Report AssignmentExpressions only if they are the left side of the assignment
-                    } else if (effectiveParent.type === "AssignmentExpression" && isUnderscored(name) && (effectiveParent.right.type !== "MemberExpression" || effectiveParent.left.type === "MemberExpression" && effectiveParent.left.property.name === node.name)) {
+                    } else if (effectiveParent.type === "AssignmentExpression" && nameIsUnderscored && (effectiveParent.right.type !== "MemberExpression" || effectiveParent.left.type === "MemberExpression" && effectiveParent.left.property.name === node.name)) {
                         report(node);
                     }
 
@@ -167,7 +168,7 @@ module.exports = {
                 } else if (node.parent.type === "Property" || node.parent.type === "AssignmentPattern") {
 
                     if (node.parent.parent && node.parent.parent.type === "ObjectPattern") {
-                        if (node.parent.shorthand && node.parent.value.left && isUnderscored(name)) {
+                        if (node.parent.shorthand && node.parent.value.left && nameIsUnderscored) {
 
                             report(node);
                         }
@@ -179,7 +180,7 @@ module.exports = {
                             return;
                         }
 
-                        const valueIsUnderscored = node.parent.value.name && isUnderscored(name);
+                        const valueIsUnderscored = node.parent.value.name && nameIsUnderscored;
 
                         // ignore destructuring if the option is set, unless a new identifier is created
                         if (valueIsUnderscored && !(assignmentKeyEqualsValue && ignoreDestructuring)) {
@@ -193,7 +194,7 @@ module.exports = {
                     }
 
                     // don't check right hand side of AssignmentExpression to prevent duplicate warnings
-                    if (isUnderscored(name) && !ALLOWED_PARENT_TYPES.has(effectiveParent.type) && !(node.parent.right === node)) {
+                    if (nameIsUnderscored && !ALLOWED_PARENT_TYPES.has(effectiveParent.type) && !(node.parent.right === node)) {
                         report(node);
                     }
 
@@ -201,12 +202,12 @@ module.exports = {
                 } else if (["ImportSpecifier", "ImportNamespaceSpecifier", "ImportDefaultSpecifier"].indexOf(node.parent.type) >= 0) {
 
                     // Report only if the local imported identifier is underscored
-                    if (node.parent.local && node.parent.local.name === node.name && isUnderscored(name)) {
+                    if (node.parent.local && node.parent.local.name === node.name && nameIsUnderscored) {
                         report(node);
                     }
 
                 // Report anything that is underscored that isn't a CallExpression
-                } else if (isUnderscored(name) && !ALLOWED_PARENT_TYPES.has(effectiveParent.type)) {
+                } else if (nameIsUnderscored && !ALLOWED_PARENT_TYPES.has(effectiveParent.type)) {
                     report(node);
                 }
             }
diff --git a/lib/util/glob-utils.js b/lib/util/glob-utils.js
index a2be0f042..fd4cfa008 100644
--- a/lib/util/glob-utils.js
+++ b/lib/util/glob-utils.js
@@ -14,7 +14,7 @@ const lodash = require("lodash"),
     GlobSync = require("./glob"),
 
     pathUtils = require("./path-utils"),
-    IgnoredPaths = require("../ignored-paths");
+    IgnoredPaths = require("./ignored-paths");
 
 const debug = require("debug")("eslint:glob-utils");
 
diff --git a/lib/ignored-paths.js b/lib/util/ignored-paths.js
similarity index 99%
rename from lib/ignored-paths.js
rename to lib/util/ignored-paths.js
index 8520090af..34b5f5213 100644
--- a/lib/ignored-paths.js
+++ b/lib/util/ignored-paths.js
@@ -12,7 +12,7 @@
 const fs = require("fs"),
     path = require("path"),
     ignore = require("ignore"),
-    pathUtils = require("./util/path-utils");
+    pathUtils = require("./path-utils");
 
 const debug = require("debug")("eslint:ignored-paths");
 
diff --git a/lib/report-translator.js b/lib/util/report-translator.js
similarity index 99%
rename from lib/report-translator.js
rename to lib/util/report-translator.js
index f82830586..3dfdca0e4 100644
--- a/lib/report-translator.js
+++ b/lib/util/report-translator.js
@@ -10,8 +10,8 @@
 //------------------------------------------------------------------------------
 
 const assert = require("assert");
-const ruleFixer = require("./util/rule-fixer");
-const interpolate = require("./util/interpolate");
+const ruleFixer = require("./rule-fixer");
+const interpolate = require("./interpolate");
 
 //------------------------------------------------------------------------------
 // Typedefs


Test patch:
diff --git a/tests/lib/rules/camelcase.js b/tests/lib/rules/camelcase.js
index 3d2b7516c..d1ce3b3fd 100644
--- a/tests/lib/rules/camelcase.js
+++ b/tests/lib/rules/camelcase.js
@@ -193,6 +193,10 @@ ruleTester.run("camelcase", rule, {
         {
             code: "user_id = 0;",
             options: [{ allow: ["_id$"] }]
+        },
+        {
+            code: "__option_foo__ = 0;",
+            options: [{ allow: ["__option_foo__"] }]
         }
     ],
     invalid: [
diff --git a/tests/lib/ignored-paths.js b/tests/lib/util/ignored-paths.js
similarity index 99%
rename from tests/lib/ignored-paths.js
rename to tests/lib/util/ignored-paths.js
index b03314e61..7f3ff4387 100644
--- a/tests/lib/ignored-paths.js
+++ b/tests/lib/util/ignored-paths.js
@@ -12,7 +12,7 @@
 const assert = require("chai").assert,
     path = require("path"),
     os = require("os"),
-    IgnoredPaths = require("../../lib/ignored-paths.js"),
+    IgnoredPaths = require("../../../lib/util/ignored-paths.js"),
     sinon = require("sinon"),
     fs = require("fs"),
     includes = require("lodash").includes;
diff --git a/tests/lib/report-translator.js b/tests/lib/util/report-translator.js
similarity index 99%
rename from tests/lib/report-translator.js
rename to tests/lib/util/report-translator.js
index e009e4e82..cd600934d 100644
--- a/tests/lib/report-translator.js
+++ b/tests/lib/util/report-translator.js
@@ -9,9 +9,9 @@
 //------------------------------------------------------------------------------
 
 const assert = require("chai").assert;
-const SourceCode = require("../../lib/util/source-code");
+const SourceCode = require("../../../lib/util/source-code");
 const espree = require("espree");
-const createReportTranslator = require("../../lib/report-translator");
+const createReportTranslator = require("../../../lib/util/report-translator");
 
 //------------------------------------------------------------------------------
 // Tests