Skip to content

Commit

Permalink
Fix eslint v9 compatibility issues (#532)
Browse files Browse the repository at this point in the history
* Fix deprecated API usage for eslint v9 compatibility

* Fix linting

* Ignore coverage for code paths not traversed by modern eslint
  • Loading branch information
LucasHill authored Aug 16, 2024
1 parent a74e161 commit 02b4c8e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
11 changes: 9 additions & 2 deletions lib/rules/no-assert-equal.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,17 @@ module.exports = {
testStack.pop();
}
},
Program: function () {
Program: function (node) {
// Gather all calls to global `equal()`.
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
const sourceCode =
context.sourceCode ?? context.getSourceCode();
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
const scope = sourceCode.getScope
? sourceCode.getScope(node)
: context.getScope();

const tracker = new ReferenceTracker(context.getScope());
const tracker = new ReferenceTracker(scope);
const traceMap = { equal: { [ReferenceTracker.CALL]: true } };

for (const { node } of tracker.iterateGlobalReferences(
Expand Down
12 changes: 10 additions & 2 deletions lib/rules/no-global-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@ module.exports = {

create: function (context) {
return {
Program: function () {
const tracker = new ReferenceTracker(context.getScope());
Program: function (node) {
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
const sourceCode =
context.sourceCode ?? context.getSourceCode();
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
const scope = sourceCode.getScope
? sourceCode.getScope(node)
: context.getScope();

const tracker = new ReferenceTracker(scope);
const traceMap = {};
for (const assertionName of getAssertionNames()) {
traceMap[assertionName] = { [ReferenceTracker.CALL]: true };
Expand Down
12 changes: 10 additions & 2 deletions lib/rules/no-global-expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ module.exports = {

create: function (context) {
return {
Program: function () {
const tracker = new ReferenceTracker(context.getScope());
Program: function (node) {
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
const sourceCode =
context.sourceCode ?? context.getSourceCode();
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
const scope = sourceCode.getScope
? sourceCode.getScope(node)
: context.getScope();

const tracker = new ReferenceTracker(scope);
const traceMap = { expect: { [ReferenceTracker.CALL]: true } };

for (const { node } of tracker.iterateGlobalReferences(
Expand Down
12 changes: 10 additions & 2 deletions lib/rules/no-global-module-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ module.exports = {

create: function (context) {
return {
Program: function () {
const tracker = new ReferenceTracker(context.getScope());
Program: function (node) {
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
const sourceCode =
context.sourceCode ?? context.getSourceCode();
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
const scope = sourceCode.getScope
? sourceCode.getScope(node)
: context.getScope();

const tracker = new ReferenceTracker(scope);
const traceMap = {
asyncTest: { [ReferenceTracker.CALL]: true },
module: { [ReferenceTracker.CALL]: true },
Expand Down
12 changes: 10 additions & 2 deletions lib/rules/no-global-stop-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@ module.exports = {
//--------------------------------------------------------------------------

return {
Program: function () {
const tracker = new ReferenceTracker(context.getScope());
Program: function (node) {
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
const sourceCode =
context.sourceCode ?? context.getSourceCode();
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
const scope = sourceCode.getScope
? sourceCode.getScope(node)
: context.getScope();

const tracker = new ReferenceTracker(scope);
const traceMap = {
start: { [ReferenceTracker.CALL]: true },
stop: { [ReferenceTracker.CALL]: true },
Expand Down

0 comments on commit 02b4c8e

Please sign in to comment.