Skip to content

Commit 5b85dc4

Browse files
committed
fix: sourceCode.getScope?.()
1 parent 458b751 commit 5b85dc4

12 files changed

+16
-17
lines changed

lib/rules/fixer-return.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ module.exports = {
8181
return false;
8282
}
8383
const scope =
84-
(context.sourceCode || context.getSourceCode())?.getScope(node) ||
84+
(context.sourceCode || context.getSourceCode()).getScope?.(node) ||
8585
context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0
8686
const staticValue = getStaticValue(node, scope);
8787
if (!staticValue) {

lib/rules/no-missing-message-ids.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module.exports = {
4848
},
4949

5050
CallExpression(node) {
51+
const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0
5152
// Check for messageId properties used in known calls to context.report();
5253
if (
5354
node.callee.type === 'MemberExpression' &&
@@ -80,7 +81,7 @@ module.exports = {
8081
val.value,
8182
ruleInfo,
8283
scopeManager,
83-
sourceCode.getScope(node)
84+
scope
8485
)
8586
)
8687
// Couldn't find this messageId in `meta.messages`.

lib/rules/no-missing-placeholders.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = {
4848
contextIdentifiers = utils.getContextIdentifiers(scopeManager, ast);
4949
},
5050
CallExpression(node) {
51-
const scope = sourceCode.getScope(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0
51+
const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0
5252
if (
5353
node.callee.type === 'MemberExpression' &&
5454
contextIdentifiers.has(node.callee.object) &&

lib/rules/no-unused-message-ids.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module.exports = {
5757
return;
5858
}
5959

60-
const scope = sourceCode.getScope(ast);
60+
const scope = sourceCode.getScope?.(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0
6161

6262
const messageIdNodesUnused = messageIdNodes.filter(
6363
(node) => !messageIdsUsed.has(utils.getKeyName(node, scope))

lib/rules/no-unused-placeholders.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ module.exports = {
4747
contextIdentifiers = utils.getContextIdentifiers(scopeManager, ast);
4848
},
4949
CallExpression(node) {
50+
const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0
5051
if (
5152
node.callee.type === 'MemberExpression' &&
5253
contextIdentifiers.has(node.callee.object) &&
@@ -74,7 +75,7 @@ module.exports = {
7475
obj.messageId.value,
7576
ruleInfo,
7677
scopeManager,
77-
sourceCode.getScope(node)
78+
scope
7879
);
7980
if (correspondingMessage) {
8081
obj.message = correspondingMessage.value;
@@ -86,10 +87,7 @@ module.exports = {
8687
for (const { message, data } of reportMessagesAndDataArray.filter(
8788
(obj) => obj.message
8889
)) {
89-
const messageStaticValue = getStaticValue(
90-
message,
91-
sourceCode.getScope(node)
92-
);
90+
const messageStaticValue = getStaticValue(message, scope);
9391
if (
9492
((message.type === 'Literal' &&
9593
typeof message.value === 'string') ||

lib/rules/prefer-message-ids.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = {
4343

4444
return {
4545
Program(ast) {
46-
const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
46+
const scope = sourceCode.getScope?.(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
4747
contextIdentifiers = utils.getContextIdentifiers(
4848
sourceCode.scopeManager,
4949
ast

lib/rules/report-message-format.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module.exports = {
6969

7070
return {
7171
Program(ast) {
72-
const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
72+
const scope = sourceCode.getScope?.(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
7373
contextIdentifiers = utils.getContextIdentifiers(
7474
sourceCode.scopeManager,
7575
ast
@@ -97,7 +97,7 @@ module.exports = {
9797
.forEach((it) => processMessageNode(it, scope));
9898
},
9999
CallExpression(node) {
100-
const scope = sourceCode.getScope(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
100+
const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
101101
if (
102102
node.callee.type === 'MemberExpression' &&
103103
contextIdentifiers.has(node.callee.object) &&

lib/rules/require-meta-docs-description.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module.exports = {
5353

5454
return {
5555
Program(ast) {
56-
const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
56+
const scope = sourceCode.getScope?.(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
5757
const { scopeManager } = sourceCode;
5858

5959
const pattern =

lib/rules/require-meta-docs-url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ module.exports = {
8484

8585
return {
8686
Program(ast) {
87-
const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
87+
const scope = sourceCode.getScope?.(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
8888
const { scopeManager } = sourceCode;
8989

9090
const metaNode = ruleInfo.meta;

lib/rules/require-meta-fixable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module.exports = {
7979
}
8080
},
8181
'Program:exit'(ast) {
82-
const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
82+
const scope = sourceCode.getScope?.(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
8383
const metaFixableProp =
8484
ruleInfo &&
8585
utils

lib/rules/require-meta-has-suggestions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports = {
4444
* @returns {boolean} whether this property should be considered to contain suggestions
4545
*/
4646
function doesPropertyContainSuggestions(node) {
47-
const scope = sourceCode.getScope(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
47+
const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
4848
const staticValue = getStaticValue(node.value, scope);
4949
if (
5050
!staticValue ||

lib/rules/require-meta-type.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module.exports = {
4646

4747
return {
4848
Program(node) {
49-
const scope = sourceCode.getScope(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
49+
const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
5050
const { scopeManager } = sourceCode;
5151

5252
const metaNode = ruleInfo.meta;

0 commit comments

Comments
 (0)