Skip to content

flat config eslint 9.x.x working #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions lib/util/Components.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Components.prototype.length = function () {
return length;
};

function componentRule(rule, context) {
function componentRule(rule, context, _node) {
const sourceCode = context.getSourceCode();
const components = new Components();

Expand Down Expand Up @@ -165,11 +165,11 @@ function componentRule(rule, context) {
*
* @returns {ASTNode} component node, null if we are not in a component
*/
getParentComponent: function () {
getParentComponent: function (_n) {
return (
utils.getParentES6Component()
|| utils.getParentES5Component()
|| utils.getParentStatelessComponent()
utils.getParentES6Component(_n)
|| utils.getParentES5Component(_n)
|| utils.getParentStatelessComponent(_n)
);
},

Expand All @@ -178,9 +178,9 @@ function componentRule(rule, context) {
*
* @returns {ASTNode} component node, null if we are not in a component
*/
getParentES5Component: function () {
getParentES5Component: function (_n) {
// eslint-disable-next-line react/destructuring-assignment
let scope = context.getScope();
let scope = (context.sourceCode || context).getScope(_n);
while (scope) {
const node = scope.block && scope.block.parent && scope.block.parent.parent;
if (node && utils.isES5Component(node)) {
Expand All @@ -196,8 +196,8 @@ function componentRule(rule, context) {
*
* @returns {ASTNode} component node, null if we are not in a component
*/
getParentES6Component: function () {
let scope = context.getScope();
getParentES6Component: function (_n) {
let scope = (context.sourceCode || context).getScope(_n);
while (scope && scope.type !== 'class') {
scope = scope.upper;
}
Expand All @@ -213,9 +213,9 @@ function componentRule(rule, context) {
*
* @returns {ASTNode} component node, null if we are not in a component
*/
getParentStatelessComponent: function () {
getParentStatelessComponent: function (_n) {
// eslint-disable-next-line react/destructuring-assignment
let scope = context.getScope();
let scope = (context.sourceCode || context).getScope(_n);
while (scope) {
const node = scope.block;
// Ignore non functions
Expand Down Expand Up @@ -263,7 +263,7 @@ function componentRule(rule, context) {
return null;
}
let variableInScope;
const { variables } = context.getScope();
const { variables } = (context.sourceCode || context).getScope(_node);
for (i = 0, j = variables.length; i < j; i++) { // eslint-disable-line no-plusplus
if (variables[i].name === variableName) {
variableInScope = variables[i];
Expand Down Expand Up @@ -323,8 +323,8 @@ function componentRule(rule, context) {
components.add(node, 2);
},

ClassProperty: function () {
const node = utils.getParentComponent();
ClassProperty: function (_n) {
const node = utils.getParentComponent(_n);
if (!node) {
return;
}
Expand All @@ -338,24 +338,24 @@ function componentRule(rule, context) {
components.add(node, 2);
},

FunctionExpression: function () {
const node = utils.getParentComponent();
FunctionExpression: function (_n) {
const node = utils.getParentComponent(_n);
if (!node) {
return;
}
components.add(node, 1);
},

FunctionDeclaration: function () {
const node = utils.getParentComponent();
FunctionDeclaration: function (_n) {
const node = utils.getParentComponent(_n);
if (!node) {
return;
}
components.add(node, 1);
},

ArrowFunctionExpression: function () {
const node = utils.getParentComponent();
ArrowFunctionExpression: function (_n) {
const node = utils.getParentComponent(_n);
if (!node) {
return;
}
Expand All @@ -366,8 +366,8 @@ function componentRule(rule, context) {
}
},

ThisExpression: function () {
const node = utils.getParentComponent();
ThisExpression: function (_n) {
const node = utils.getParentComponent(_n);
if (!node || !/Function/.test(node.type)) {
return;
}
Expand All @@ -379,7 +379,7 @@ function componentRule(rule, context) {
if (!utils.isReturningJSX(node)) {
return;
}
const parentNode = utils.getParentComponent();
const parentNode = utils.getParentComponent(node);
if (!parentNode) {
return;
}
Expand Down
15 changes: 11 additions & 4 deletions lib/util/variable.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* @param {String} name The name of the variable to mark as used.
* @returns {Boolean} True if the variable was found and marked as used, false if not.
*/
function markVariableAsUsed(context, name) {
let scope = context.getScope();
function markVariableAsUsed(context, name, _node) {
let scope = (context.sourceCode || context).getScope(_node);
let variables;
let i;
let len;
Expand Down Expand Up @@ -58,6 +58,13 @@ function findVariable(variables, name) {
return false;
}

function getScope(context, node) {
if (context.sourceCode && context.sourceCode.getScope) {
return context.sourceCode.getScope(node);
}
return context.getScope();
}

/**
* List all variable in a given scope
*
Expand All @@ -67,8 +74,8 @@ function findVariable(variables, name) {
* @param {Array} name The name of the variable to search.
* @returns {Boolean} True if the variable was found, false if not.
*/
function variablesInScope(context) {
let scope = context.getScope();
function variablesInScope(context, _n) {
let scope = getScope(context, _n);
let { variables } = scope;

while (scope.type !== 'global') {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"typescript": "^5.2.2"
},
"peerDependencies": {
"eslint": "^3.17.0 || ^4 || ^5 || ^6 || ^7 || ^8"
"eslint": "^3.17.0 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9"
},
"keywords": [
"eslint",
Expand Down