Repository: ember-cli/eslint-plugin-ember
Pull request #858 (2020-06-17 20:48:30)

Rename `getParent` util function to `getAncestor`


Patch:
diff --git a/lib/utils/utils.js b/lib/utils/utils.js
index b9783f7d..c4c263b4 100644
--- a/lib/utils/utils.js
+++ b/lib/utils/utils.js
@@ -13,7 +13,7 @@ module.exports = {
   collectObjectPatternBindings,
   findNodes,
   findUnorderedProperty,
-  getParent,
+  getAncestor,
   getPropertyValue,
   getSize,
   isEmptyMethod,
@@ -202,12 +202,12 @@ function isEmptyMethod(node) {
  * Travels up the ancestors of a given node, if the predicate function returns
  * truthy for a given node or ancestor, return that node, otherwise return null
  *
- * @name getParent
+ * @name getAncestor
  * @param {Object} node The child node to start at
  * @param {Function} predicate Function that should return a boolean for a given value
  * @returns {Object|null} The first node that matches predicate, otherwise null
  */
-function getParent(node, predicate) {
+function getAncestor(node, predicate) {
   let currentNode = node;
   while (currentNode) {
     if (predicate(currentNode)) {


Test patch:
diff --git a/lib/rules/no-ember-testing-in-module-scope.js b/lib/rules/no-ember-testing-in-module-scope.js
index 827b5ff6..ef3fd5e2 100644
--- a/lib/rules/no-ember-testing-in-module-scope.js
+++ b/lib/rules/no-ember-testing-in-module-scope.js
@@ -60,11 +60,11 @@ module.exports = {
 
       'Property[key.name="testing"]'(node) {
         if (
-          utils.getParent(
+          utils.getAncestor(
             node,
-            (parentNode) =>
-              parentNode.type === 'VariableDeclarator' &&
-              parentNode.init.name === emberImportAliasName
+            (ancestorNode) =>
+              ancestorNode.type === 'VariableDeclarator' &&
+              ancestorNode.init.name === emberImportAliasName
           )
         ) {
           context.report(node.parent.parent.parent, ERROR_MESSAGES[2]);
diff --git a/lib/rules/no-invalid-test-waiters.js b/lib/rules/no-invalid-test-waiters.js
index 765c9bbf..270ba569 100644
--- a/lib/rules/no-invalid-test-waiters.js
+++ b/lib/rules/no-invalid-test-waiters.js
@@ -8,12 +8,12 @@ const DIRECT_ASSIGNMENT_ERROR_MESSAGE =
   'The result of the `buildWaiter` function must be a direct assignment to a module scoped variable';
 
 function isInModuleScope(node) {
-  const parentVariableDeclaration = utils.getParent(
+  const ancestorVariableDeclaration = utils.getAncestor(
     node,
-    (current) => current.type === 'VariableDeclaration'
+    (ancestor) => ancestor.type === 'VariableDeclaration'
   );
 
-  return parentVariableDeclaration.parent.type === 'Program';
+  return ancestorVariableDeclaration.parent.type === 'Program';
 }
 
 function isDirectVariableDeclaration(node) {
diff --git a/lib/rules/no-restricted-resolver-tests.js b/lib/rules/no-restricted-resolver-tests.js
index c740b9cb..eaed1a9b 100644
--- a/lib/rules/no-restricted-resolver-tests.js
+++ b/lib/rules/no-restricted-resolver-tests.js
@@ -24,8 +24,8 @@ function getNoPOJOWithoutIntegrationTrueMessage(fn) {
 }
 
 function hasOnlyStringArgument(node) {
-  const parentMethodCall = getParentCallExpression(node);
-  const args = parentMethodCall.arguments;
+  const ancestorMethodCall = getAncestorCallExpression(node);
+  const args = ancestorMethodCall.arguments;
 
   return args.length === 1 && types.isLiteral(args[0]);
 }
@@ -48,13 +48,16 @@ function hasIntegrationTrue(node) {
   );
 }
 
-function getParentCallExpression(node) {
-  return utils.getParent(node, (parent) => parent.type === 'CallExpression');
+function getAncestorCallExpression(node) {
+  return utils.getAncestor(node, (ancestor) => ancestor.type === 'CallExpression');
 }
 
 function getLastArgument(node) {
-  const parentMethodCall = utils.getParent(node, (parent) => parent.type === 'CallExpression');
-  const args = parentMethodCall.arguments;
+  const ancestorMethodCall = utils.getAncestor(
+    node,
+    (ancestor) => ancestor.type === 'CallExpression'
+  );
+  const args = ancestorMethodCall.arguments;
   const lastArgument = args[args.length - 1];
 
   return lastArgument;
diff --git a/tests/helpers/faux-context.js b/tests/helpers/faux-context.js
index 5fb6f5af..c0a63db6 100644
--- a/tests/helpers/faux-context.js
+++ b/tests/helpers/faux-context.js
@@ -16,7 +16,7 @@ class FauxContext {
   }
 
   /**
-   * Does not build the full tree of "parents" for the identifier, but
+   * Does not build the full tree of "ancestors" for the identifier, but
    * we only care about the first one; the Program node
    */
   getAncestors() {