Skip to content

Commit 55cd064

Browse files
authored
Fix API deprecations blocking eslint v9 compatibility (#2153)
* Fix API deprecations blocking eslint v9 compatibility * Remove unused property * Make accessing ancestors compatible with older eslint versions. * Fix getScope eslint v9 deprecation
1 parent 91657d4 commit 55cd064

8 files changed

+67
-22
lines changed

lib/rules/jquery-ember-run.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ module.exports = {
119119
}
120120
},
121121

122-
'Program:exit'() {
123-
const scope = context.getScope();
122+
'Program:exit'(node) {
123+
const sourceCode = context.sourceCode ?? context.getSourceCode();
124+
const scope = sourceCode.getScope ? sourceCode.getScope(node) : context.getScope();
125+
124126
const tracker = new ReferenceTracker(scope);
125127

126128
/**

lib/rules/no-ember-testing-in-module-scope.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ module.exports = {
4545
node.parent.type === 'MemberExpression' &&
4646
node.parent.object.name === emberImportAliasName
4747
) {
48-
if (context.getScope().variableScope.type === 'module') {
48+
const sourceCode = context.sourceCode ?? context.getSourceCode();
49+
const scope = sourceCode.getScope ? sourceCode.getScope(node) : context.getScope();
50+
51+
if (scope.variableScope.type === 'module') {
4952
context.report({ node: node.parent, message: ERROR_MESSAGES[0] });
5053
}
5154
const nodeGrandParent = utils.getPropertyValue(node, 'parent.parent.type');

lib/rules/no-global-jquery.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ module.exports = {
2727

2828
create(context) {
2929
return {
30-
Program() {
31-
const tracker = new ReferenceTracker(context.getScope());
30+
Program(node) {
31+
const sourceCode = context.sourceCode ?? context.getSourceCode();
32+
const scope = sourceCode.getScope ? sourceCode.getScope(node) : context.getScope();
33+
34+
const tracker = new ReferenceTracker(scope);
3235

3336
for (const { node } of tracker.iterateGlobalReferences(globalMap)) {
3437
context.report({ node, message: ERROR_MESSAGE });

lib/rules/no-jquery.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ module.exports = {
4848
/**
4949
* Report references of jQuery
5050
*/
51-
Program() {
52-
const scope = context.getScope();
51+
Program(node) {
52+
const sourceCode = context.sourceCode ?? context.getSourceCode();
53+
const scope = sourceCode.getScope ? sourceCode.getScope(node) : context.getScope();
54+
5355
const tracker = new ReferenceTracker(scope);
5456

5557
/**

lib/rules/prefer-ember-test-helpers.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ module.exports = {
3434
};
3535

3636
return {
37-
Program() {
38-
const tracker = new ReferenceTracker(context.getScope());
37+
Program(node) {
38+
const sourceCode = context.sourceCode ?? context.getSourceCode();
39+
const scope = sourceCode.getScope ? sourceCode.getScope(node) : context.getScope();
40+
41+
const tracker = new ReferenceTracker(scope);
3942
const traceMap = {
4043
blur: { [ReferenceTracker.CALL]: true },
4144
find: { [ReferenceTracker.CALL]: true },

lib/rules/require-fetch-import.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ module.exports = {
2222

2323
create(context) {
2424
return {
25-
'Program:exit'() {
26-
const tracker = new ReferenceTracker(context.getScope());
25+
'Program:exit'(node) {
26+
const sourceCode = context.sourceCode ?? context.getSourceCode();
27+
const scope = sourceCode.getScope ? sourceCode.getScope(node) : context.getScope();
28+
29+
const tracker = new ReferenceTracker(scope);
2730

2831
const traceMap = {
2932
fetch: { [ReferenceTracker.CALL]: true },

lib/rules/require-return-from-computed.js

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ const { getImportIdentifier } = require('../utils/import');
77
// General rule - Always return a value from computed properties
88
//------------------------------------------------------------------------------
99

10-
function isReachable(segment) {
11-
return segment.reachable;
10+
function isAnySegmentReachable(segments) {
11+
for (const segment of segments) {
12+
if (segment.reachable) {
13+
return true;
14+
}
15+
}
16+
17+
return false;
1218
}
1319

1420
const ERROR_MESSAGE = 'Always return a value from computed properties';
@@ -39,17 +45,17 @@ module.exports = {
3945
codePath: null,
4046
shouldCheck: false,
4147
node: null,
48+
currentSegments: [],
4249
};
4350

4451
function checkLastSegment(node) {
45-
if (funcInfo.shouldCheck && funcInfo.codePath.currentSegments.some(isReachable)) {
52+
if (funcInfo.shouldCheck && isAnySegmentReachable(funcInfo.currentSegments)) {
4653
report(node);
4754
}
4855
}
4956

5057
let importedEmberName;
5158
let importedComputedName;
52-
5359
return {
5460
ImportDeclaration(node) {
5561
if (node.source.value === 'ember') {
@@ -61,22 +67,43 @@ module.exports = {
6167
}
6268
},
6369

64-
onCodePathStart(codePath) {
70+
onCodePathStart(codePath, node) {
71+
const sourceCode = context.sourceCode ?? context.getSourceCode();
72+
const ancestors = sourceCode.getAncestors
73+
? sourceCode.getAncestors(node)
74+
: context.getAncestors();
75+
6576
funcInfo = {
6677
upper: funcInfo,
6778
codePath,
6879
shouldCheck:
69-
context
70-
.getAncestors()
71-
.findIndex((node) =>
72-
ember.isComputedProp(node, importedEmberName, importedComputedName)
73-
) > -1,
80+
ancestors.findIndex((node) =>
81+
ember.isComputedProp(node, importedEmberName, importedComputedName)
82+
) > -1,
83+
node,
84+
currentSegments: new Set(),
7485
};
7586
},
7687

88+
// Pops this function's information.
7789
onCodePathEnd() {
7890
funcInfo = funcInfo.upper;
7991
},
92+
onUnreachableCodePathSegmentStart(segment) {
93+
funcInfo.currentSegments.add(segment);
94+
},
95+
96+
onUnreachableCodePathSegmentEnd(segment) {
97+
funcInfo.currentSegments.delete(segment);
98+
},
99+
100+
onCodePathSegmentStart(segment) {
101+
funcInfo.currentSegments.add(segment);
102+
},
103+
104+
onCodePathSegmentEnd(segment) {
105+
funcInfo.currentSegments.delete(segment);
106+
},
80107

81108
'FunctionExpression:exit'(node) {
82109
if (node.parent.parent.parent === null) {

lib/rules/use-ember-get-and-set.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ module.exports = {
9898

9999
VariableDeclarator(node) {
100100
const isEmberImported = Boolean(emberImportAliasName);
101-
const isModuleScope = context.getScope().type === 'module';
101+
const sourceCode = context.sourceCode ?? context.getSourceCode();
102+
const scope = sourceCode.getScope ? sourceCode.getScope(node) : context.getScope();
103+
const isModuleScope = scope.type === 'module';
102104
if (isEmberImported && isModuleScope) {
103105
// Populate localModulesPresent as a mapping of (avoided method -> local module alias)
104106
for (const methodName of avoidedMethods) {

0 commit comments

Comments
 (0)