Skip to content

Commit 032e96a

Browse files
flat config eslint 9.x.x working (#336)
* trying to support eslint 9 * Fix lint * Add eslint9 to peerDeps --------- Co-authored-by: Hugo Rune <[email protected]>
1 parent aaefa10 commit 032e96a

File tree

4 files changed

+36
-29
lines changed

4 files changed

+36
-29
lines changed

lib/util/Components.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Components.prototype.length = function () {
9999
return length;
100100
};
101101

102-
function componentRule(rule, context) {
102+
function componentRule(rule, context, _node) {
103103
const sourceCode = context.getSourceCode();
104104
const components = new Components();
105105

@@ -165,11 +165,11 @@ function componentRule(rule, context) {
165165
*
166166
* @returns {ASTNode} component node, null if we are not in a component
167167
*/
168-
getParentComponent: function () {
168+
getParentComponent: function (_n) {
169169
return (
170-
utils.getParentES6Component()
171-
|| utils.getParentES5Component()
172-
|| utils.getParentStatelessComponent()
170+
utils.getParentES6Component(_n)
171+
|| utils.getParentES5Component(_n)
172+
|| utils.getParentStatelessComponent(_n)
173173
);
174174
},
175175

@@ -178,9 +178,9 @@ function componentRule(rule, context) {
178178
*
179179
* @returns {ASTNode} component node, null if we are not in a component
180180
*/
181-
getParentES5Component: function () {
181+
getParentES5Component: function (_n) {
182182
// eslint-disable-next-line react/destructuring-assignment
183-
let scope = context.getScope();
183+
let scope = (context.sourceCode || context).getScope(_n);
184184
while (scope) {
185185
const node = scope.block && scope.block.parent && scope.block.parent.parent;
186186
if (node && utils.isES5Component(node)) {
@@ -196,8 +196,8 @@ function componentRule(rule, context) {
196196
*
197197
* @returns {ASTNode} component node, null if we are not in a component
198198
*/
199-
getParentES6Component: function () {
200-
let scope = context.getScope();
199+
getParentES6Component: function (_n) {
200+
let scope = (context.sourceCode || context).getScope(_n);
201201
while (scope && scope.type !== 'class') {
202202
scope = scope.upper;
203203
}
@@ -213,9 +213,9 @@ function componentRule(rule, context) {
213213
*
214214
* @returns {ASTNode} component node, null if we are not in a component
215215
*/
216-
getParentStatelessComponent: function () {
216+
getParentStatelessComponent: function (_n) {
217217
// eslint-disable-next-line react/destructuring-assignment
218-
let scope = context.getScope();
218+
let scope = (context.sourceCode || context).getScope(_n);
219219
while (scope) {
220220
const node = scope.block;
221221
// Ignore non functions
@@ -263,7 +263,7 @@ function componentRule(rule, context) {
263263
return null;
264264
}
265265
let variableInScope;
266-
const { variables } = context.getScope();
266+
const { variables } = (context.sourceCode || context).getScope(_node);
267267
for (i = 0, j = variables.length; i < j; i++) { // eslint-disable-line no-plusplus
268268
if (variables[i].name === variableName) {
269269
variableInScope = variables[i];
@@ -323,8 +323,8 @@ function componentRule(rule, context) {
323323
components.add(node, 2);
324324
},
325325

326-
ClassProperty: function () {
327-
const node = utils.getParentComponent();
326+
ClassProperty: function (_n) {
327+
const node = utils.getParentComponent(_n);
328328
if (!node) {
329329
return;
330330
}
@@ -338,24 +338,24 @@ function componentRule(rule, context) {
338338
components.add(node, 2);
339339
},
340340

341-
FunctionExpression: function () {
342-
const node = utils.getParentComponent();
341+
FunctionExpression: function (_n) {
342+
const node = utils.getParentComponent(_n);
343343
if (!node) {
344344
return;
345345
}
346346
components.add(node, 1);
347347
},
348348

349-
FunctionDeclaration: function () {
350-
const node = utils.getParentComponent();
349+
FunctionDeclaration: function (_n) {
350+
const node = utils.getParentComponent(_n);
351351
if (!node) {
352352
return;
353353
}
354354
components.add(node, 1);
355355
},
356356

357-
ArrowFunctionExpression: function () {
358-
const node = utils.getParentComponent();
357+
ArrowFunctionExpression: function (_n) {
358+
const node = utils.getParentComponent(_n);
359359
if (!node) {
360360
return;
361361
}
@@ -366,8 +366,8 @@ function componentRule(rule, context) {
366366
}
367367
},
368368

369-
ThisExpression: function () {
370-
const node = utils.getParentComponent();
369+
ThisExpression: function (_n) {
370+
const node = utils.getParentComponent(_n);
371371
if (!node || !/Function/.test(node.type)) {
372372
return;
373373
}
@@ -379,7 +379,7 @@ function componentRule(rule, context) {
379379
if (!utils.isReturningJSX(node)) {
380380
return;
381381
}
382-
const parentNode = utils.getParentComponent();
382+
const parentNode = utils.getParentComponent(node);
383383
if (!parentNode) {
384384
return;
385385
}

lib/util/variable.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
* @param {String} name The name of the variable to mark as used.
1212
* @returns {Boolean} True if the variable was found and marked as used, false if not.
1313
*/
14-
function markVariableAsUsed(context, name) {
15-
let scope = context.getScope();
14+
function markVariableAsUsed(context, name, _node) {
15+
let scope = (context.sourceCode || context).getScope(_node);
1616
let variables;
1717
let i;
1818
let len;
@@ -58,6 +58,13 @@ function findVariable(variables, name) {
5858
return false;
5959
}
6060

61+
function getScope(context, node) {
62+
if (context.sourceCode && context.sourceCode.getScope) {
63+
return context.sourceCode.getScope(node);
64+
}
65+
return context.getScope();
66+
}
67+
6168
/**
6269
* List all variable in a given scope
6370
*
@@ -67,8 +74,8 @@ function findVariable(variables, name) {
6774
* @param {Array} name The name of the variable to search.
6875
* @returns {Boolean} True if the variable was found, false if not.
6976
*/
70-
function variablesInScope(context) {
71-
let scope = context.getScope();
77+
function variablesInScope(context, _n) {
78+
let scope = getScope(context, _n);
7279
let { variables } = scope;
7380

7481
while (scope.type !== 'global') {

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"typescript": "^5.2.2"
3737
},
3838
"peerDependencies": {
39-
"eslint": "^3.17.0 || ^4 || ^5 || ^6 || ^7 || ^8"
39+
"eslint": "^3.17.0 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9"
4040
},
4141
"keywords": [
4242
"eslint",

0 commit comments

Comments
 (0)