Skip to content

Commit 9931668

Browse files
authored
Replace usage of deprecated apis (#442)
1 parent 4f00db0 commit 9931668

7 files changed

+25
-14
lines changed

.changeset/wet-buckets-accept.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/eslint-plugin': minor
3+
---
4+
5+
Replace usage of deprecated APIs that will be removed in ESLint v9

packages/eslint-plugin/lib/rules/binary-assignment-parens.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ module.exports = {
3030
const shouldHaveParens = config === 'always';
3131

3232
function hasParens(node) {
33-
const beforeToken = context.getTokenBefore(node);
33+
const beforeToken = context.sourceCode.getTokenBefore(node);
3434
const hasBeforeParen =
3535
beforeToken &&
3636
beforeToken.type === 'Punctuator' &&
3737
beforeToken.value === '(';
38-
const afterToken = context.getTokenAfter(node);
38+
const afterToken = context.sourceCode.getTokenAfter(node);
3939
const hasAfterParen =
4040
afterToken &&
4141
afterToken.type === 'Punctuator' &&

packages/eslint-plugin/lib/rules/class-property-semi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525
}
2626

2727
function checkClassProperty(node) {
28-
const lastToken = context.getLastToken(node);
28+
const lastToken = context.sourceCode.getLastToken(node);
2929
const hasSemicolon = isSemicolon(lastToken);
3030

3131
if (always && !hasSemicolon) {

packages/eslint-plugin/lib/rules/jsx-no-hardcoded-content.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,14 @@ module.exports = {
149149
},
150150
};
151151

152-
function getImportDetailsForJSX({openingElement}, context) {
152+
function getImportDetailsForJSX(node, context) {
153+
const openingElement = node.openingElement;
153154
const isMemberExpression = openingElement.name.type === 'JSXMemberExpression';
154155
const searchForName = isMemberExpression
155156
? openingElement.name.object.name
156157
: openingElement.name.name;
157158

158-
const importDetails = getImportDetailsForName(searchForName, context);
159+
const importDetails = getImportDetailsForName(searchForName, context, node);
159160

160161
if (importDetails == null) {
161162
return null;

packages/eslint-plugin/lib/rules/prefer-module-scope-constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = {
3434
return;
3535
}
3636

37-
const scope = context.getScope();
37+
const scope = context.sourceCode.getScope(node);
3838
if (!['module', 'global'].includes(scope.type)) {
3939
context.report(
4040
node,

packages/eslint-plugin/lib/rules/react-hooks-strict-return.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ module.exports = {
5555
if (
5656
!exceedsMaxReturnProperties(
5757
node,
58-
context.getScope(),
58+
context.sourceCode.getScope(node),
5959
MAX_RETURN_ELEMENTS,
6060
)
6161
) {

packages/eslint-plugin/lib/utilities/index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ function getName(node) {
3535
const DEFAULT_IMPORT = Symbol('default');
3636
const NAMESPACE_IMPORT = Symbol('namespace');
3737

38-
function getImportDetailsForName(name, context) {
39-
const definition = findDefinition(name, context);
38+
function getImportDetailsForName(name, context, node) {
39+
const definition = findDefinition(name, context, node);
4040
if (definition == null || definition.type !== 'ImportBinding') {
4141
return null;
4242
}
@@ -100,9 +100,9 @@ function normalizeSource(source, context) {
100100
return normalized;
101101
}
102102

103-
function findDefinition(name, context) {
103+
function findDefinition(name, context, node) {
104104
let definition = null;
105-
let currentScope = context.getScope();
105+
let currentScope = context.sourceCode.getScope(node);
106106

107107
while (currentScope && !definition) {
108108
if (currentScope.set.has(name)) {
@@ -116,11 +116,16 @@ function findDefinition(name, context) {
116116
return definition;
117117
}
118118

119-
function polarisComponentFromJSX({openingElement}, context) {
119+
function polarisComponentFromJSX(node, context) {
120+
const openingElement = node.openingElement;
120121
const isMemberExpression = openingElement.name.type === 'JSXMemberExpression';
121122
const importDetails = isMemberExpression
122-
? getImportDetailsForName(getRootObject(openingElement.name).name, context)
123-
: getImportDetailsForName(openingElement.name.name, context);
123+
? getImportDetailsForName(
124+
getRootObject(openingElement.name).name,
125+
context,
126+
node,
127+
)
128+
: getImportDetailsForName(openingElement.name.name, context, node);
124129

125130
if (importDetails == null || importDetails.source !== '@shopify/polaris') {
126131
return false;

0 commit comments

Comments
 (0)