Skip to content

Commit

Permalink
feat: support eslint 9
Browse files Browse the repository at this point in the history
 Also increased major version
  • Loading branch information
Smrtnyk committed Dec 22, 2024
1 parent f9036ca commit c3ddcd9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
50 changes: 43 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ module.exports = {

// handle "unused" mode
if (!noneUnusedMode) {
let scope = context.getScope();
let sourceCode = getSourceCode(context);
let scope = getScope(context,sourceCode,node);
let checkParamNames = checkParamIds.map(function getName(paramId){
return paramId.name;
});
Expand Down Expand Up @@ -301,7 +302,9 @@ module.exports = {
return;
}

var globalArrow = currentlyInGlobalScope(context.parserOptions,context.getScope());
var sourceCode = getSourceCode(context);
var scope = getScope(context,sourceCode,node);
var globalArrow = currentlyInGlobalScope(context.parserOptions,scope);
var globalArrowDeclaration = (
globalArrow &&
node.parent.type == "VariableDeclarator"
Expand Down Expand Up @@ -414,12 +417,13 @@ module.exports = {
var sequenceMode = defaultsOnly || !("sequence" in extraOptions) || extraOptions.sequence === true;
var ignoreTrivial = !(extraOptions && extraOptions.trivial === true);

var sourceCode = context.getSourceCode();
var sourceCode = getSourceCode(context);
var ternaryBodyStack = new Map();

return {
"ConditionalExpression:exit": function exit(node) {
var parentArrow = getParentArrowFunction(context.getAncestors(),/*onlyFromBody=*/true);
var ancestors = getAncestors(context,sourceCode,node);
var parentArrow = getParentArrowFunction(ancestors,/*onlyFromBody=*/true);
if (parentArrow) {
if (!ternaryBodyStack.has(parentArrow)) {
ternaryBodyStack.set(parentArrow,[]);
Expand Down Expand Up @@ -562,7 +566,9 @@ module.exports = {

return {
"ThisExpression": function enter(node) {
var parentArrow = getParentArrowFunction(context.getAncestors());
var sourceCode = getSourceCode(context);
var ancestors = getAncestors(context, sourceCode,node);
var parentArrow = getParentArrowFunction(ancestors);
thisFoundIn.add(parentArrow);
},
"ArrowFunctionExpression:exit": function exit(node) {
Expand All @@ -571,7 +577,9 @@ module.exports = {
return;
}

var globalArrow = currentlyInGlobalScope(context.parserOptions,context.getScope());
var sourceCode = getSourceCode(context);
var scope = getScope(context, sourceCode, node);
var globalArrow = currentlyInGlobalScope(context.parserOptions,scope);
var foundThis = thisFoundIn.has(node);

// `this` found in arrow function?
Expand Down Expand Up @@ -605,7 +613,8 @@ module.exports = {

// need to track nested `this`?
if (nestedThis || neverGlobalThis) {
let parentArrow = getParentArrowFunction(context.getAncestors());
let ancestors = getAncestors(context, sourceCode,node);
let parentArrow = getParentArrowFunction(ancestors);
if (parentArrow) {
thisFoundIn.add(parentArrow);
}
Expand Down Expand Up @@ -801,3 +810,30 @@ function currentlyInGlobalScope(parserOptions,scope) {
)
);
}

var getSourceCode = context => {
getSourceCode = (
context.sourceCode ?
context => context.sourceCode :
context => context.getSourceCode()
);
return getSourceCode(context);
};

var getScope = (context, sourceCode, node) => {
getScope = (
sourceCode.getScope ?
(context, sourceCode, node) => sourceCode.getScope(node) :
(context, sourceCode, node) => context.getScope()
);
return getScope(context, sourceCode, node);
};

var getAncestors = (context, sourceCode, node) => {
getAncestors = (
sourceCode.getAncestors ?
(context, sourceCode, node) => sourceCode.getAncestors(node) :
(context, sourceCode, node) => context.getAncestors()
);
return getAncestors(context, sourceCode, node);
};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@getify/eslint-plugin-proper-arrows",
"version": "11.0.3",
"version": "12.0.0",
"description": "ESLint rules to ensure proper arrow function definitions",
"main": "./lib/index.js",
"scripts": {
Expand All @@ -18,12 +18,12 @@
},
"devDependencies": {
"coveralls": "~3.1.0",
"eslint": "~7.25.0",
"eslint": "~9.17.0",
"qunit": "~2.15.0",
"terser": "~5.7.0"
},
"peerDependencies": {
"eslint": ">= 7.25.0"
"eslint": ">= 9.17.0"
},
"repository": "getify/eslint-plugin-proper-arrows",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion scripts/node-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
var path = require("path");

var Linter = require("eslint").Linter;
var eslinter = global.eslinter = new Linter();
var eslinter = global.eslinter = new Linter({ configType: "eslintrc"});
var properArrows;

/* istanbul ignore next */
Expand Down

0 comments on commit c3ddcd9

Please sign in to comment.