Skip to content

Commit

Permalink
fix: sourceCode.getScope?.()
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Dec 8, 2023
1 parent 6d3eb81 commit 48edece
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/rules/fixer-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = {
return false;
}
const scope =
(context.sourceCode || context.getSourceCode())?.getScope(node) ||
(context.sourceCode || context.getSourceCode()).getScope?.(node) ||
context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0
const staticValue = getStaticValue(node, scope);
if (!staticValue) {
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-missing-message-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = {
},

CallExpression(node) {
const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0
// Check for messageId properties used in known calls to context.report();
if (
node.callee.type === 'MemberExpression' &&
Expand Down Expand Up @@ -80,7 +81,7 @@ module.exports = {
val.value,
ruleInfo,
scopeManager,
sourceCode.getScope(node)
scope
)
)
// Couldn't find this messageId in `meta.messages`.
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-missing-placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = {
contextIdentifiers = utils.getContextIdentifiers(scopeManager, ast);
},
CallExpression(node) {
const scope = sourceCode.getScope(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0
const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0
if (
node.callee.type === 'MemberExpression' &&
contextIdentifiers.has(node.callee.object) &&
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-unused-message-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = {
return;
}

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

const messageIdNodesUnused = messageIdNodes.filter(
(node) => !messageIdsUsed.has(utils.getKeyName(node, scope))
Expand Down
8 changes: 3 additions & 5 deletions lib/rules/no-unused-placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module.exports = {
contextIdentifiers = utils.getContextIdentifiers(scopeManager, ast);
},
CallExpression(node) {
const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0
if (
node.callee.type === 'MemberExpression' &&
contextIdentifiers.has(node.callee.object) &&
Expand Down Expand Up @@ -74,7 +75,7 @@ module.exports = {
obj.messageId.value,
ruleInfo,
scopeManager,
sourceCode.getScope(node)
scope
);
if (correspondingMessage) {
obj.message = correspondingMessage.value;
Expand All @@ -86,10 +87,7 @@ module.exports = {
for (const { message, data } of reportMessagesAndDataArray.filter(
(obj) => obj.message
)) {
const messageStaticValue = getStaticValue(
message,
sourceCode.getScope(node)
);
const messageStaticValue = getStaticValue(message, scope);
if (
((message.type === 'Literal' &&
typeof message.value === 'string') ||
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-message-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {

return {
Program(ast) {
const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
const scope = sourceCode.getScope?.(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
contextIdentifiers = utils.getContextIdentifiers(
sourceCode.scopeManager,
ast
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/report-message-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = {

return {
Program(ast) {
const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
const scope = sourceCode.getScope?.(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
contextIdentifiers = utils.getContextIdentifiers(
sourceCode.scopeManager,
ast
Expand Down Expand Up @@ -97,7 +97,7 @@ module.exports = {
.forEach((it) => processMessageNode(it, scope));
},
CallExpression(node) {
const scope = sourceCode.getScope(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
if (
node.callee.type === 'MemberExpression' &&
contextIdentifiers.has(node.callee.object) &&
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-meta-docs-description.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = {

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

const pattern =
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-meta-docs-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module.exports = {

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

const metaNode = ruleInfo.meta;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-meta-fixable.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module.exports = {
}
},
'Program:exit'(ast) {
const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
const scope = sourceCode.getScope?.(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
const metaFixableProp =
ruleInfo &&
utils
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-meta-has-suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = {
* @returns {boolean} whether this property should be considered to contain suggestions
*/
function doesPropertyContainSuggestions(node) {
const scope = sourceCode.getScope(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0
const staticValue = getStaticValue(node.value, scope);
if (
!staticValue ||
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-meta-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = {

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

const metaNode = ruleInfo.meta;
Expand Down

0 comments on commit 48edece

Please sign in to comment.