Skip to content

Commit 171962a

Browse files
Chore: remove internal Linter#getAncestors helper (refs #9161) (#9222)
1 parent a567499 commit 171962a

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

lib/linter.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ class Linter {
900900
Object.assign(
901901
Object.create(BASE_TRAVERSAL_CONTEXT),
902902
{
903-
getAncestors: this.getAncestors.bind(this),
903+
getAncestors: () => this.traverser.parents(),
904904
getDeclaredVariables: this.getDeclaredVariables.bind(this),
905905
getFilename: this.getFilename.bind(this),
906906
getScope: this.getScope.bind(this),
@@ -1050,14 +1050,6 @@ class Linter {
10501050
return this.sourceCode;
10511051
}
10521052

1053-
/**
1054-
* Gets nodes that are ancestors of current node.
1055-
* @returns {ASTNode[]} Array of objects representing ancestors.
1056-
*/
1057-
getAncestors() {
1058-
return this.traverser.parents();
1059-
}
1060-
10611053
/**
10621054
* Gets the scope for the current node.
10631055
* @returns {Object} An object representing the current node's scope.

tests/lib/linter.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -302,36 +302,43 @@ describe("Linter", () => {
302302

303303
});
304304

305-
describe("when calling getAncestors", () => {
305+
describe("when calling context.getAncestors", () => {
306306
const code = TEST_CODE;
307307

308308
it("should retrieve all ancestors when used", () => {
309309

310310
const config = { rules: { checker: "error" } };
311-
const spy = sandbox.spy(() => {
312-
const ancestors = linter.getAncestors();
311+
let spy;
313312

314-
assert.equal(ancestors.length, 3);
315-
});
313+
linter.defineRule("checker", context => {
314+
spy = sandbox.spy(() => {
315+
const ancestors = context.getAncestors();
316316

317-
linter.defineRule("checker", () => ({ BinaryExpression: spy }));
317+
assert.equal(ancestors.length, 3);
318+
});
319+
return { BinaryExpression: spy };
320+
});
318321

319322
linter.verify(code, config, filename, true);
320-
assert(spy.calledOnce);
323+
assert(spy && spy.calledOnce);
321324
});
322325

323326
it("should retrieve empty ancestors for root node", () => {
324327
const config = { rules: { checker: "error" } };
325-
const spy = sandbox.spy(() => {
326-
const ancestors = linter.getAncestors();
328+
let spy;
327329

328-
assert.equal(ancestors.length, 0);
329-
});
330+
linter.defineRule("checker", context => {
331+
spy = sandbox.spy(() => {
332+
const ancestors = context.getAncestors();
330333

331-
linter.defineRule("checker", () => ({ Program: spy }));
334+
assert.equal(ancestors.length, 0);
335+
});
336+
337+
return { Program: spy };
338+
});
332339

333340
linter.verify(code, config);
334-
assert(spy.calledOnce);
341+
assert(spy && spy.calledOnce);
335342
});
336343
});
337344

0 commit comments

Comments
 (0)