Skip to content

Commit ac50ab4

Browse files
nzakasaladdin-add
andauthored
fix: Ensure everything works with ESLint v9 (#145)
Co-authored-by: 唯然 <[email protected]>
1 parent df1b606 commit ac50ab4

20 files changed

+486
-439
lines changed

package-lock.json

Lines changed: 386 additions & 371 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@
4646
"safe-regex": "^2.1.1"
4747
},
4848
"devDependencies": {
49-
"@eslint/js": "^8.51.0",
49+
"@eslint/js": "^9.0.0",
5050
"changelog": "1.3.0",
51-
"eslint": "^8.51.0",
51+
"eslint": "^9.0.0",
5252
"eslint-config-nodesecurity": "^1.3.1",
5353
"eslint-config-prettier": "^8.5.0",
5454
"eslint-doc-generator": "^1.7.0",
55-
"eslint-plugin-eslint-plugin": "^5.1.1",
55+
"eslint-plugin-eslint-plugin": "^5.5.1",
5656
"lint-staged": "^12.3.7",
5757
"markdownlint-cli": "^0.32.2",
5858
"mocha": "^9.2.2",

rules/detect-bidi-characters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ module.exports = {
7878
url: 'https://github.com/eslint-community/eslint-plugin-security/blob/main/docs/rules/detect-bidi-characters.md',
7979
},
8080
},
81-
create: function (context) {
81+
create(context) {
8282
return {
8383
Program: function (node) {
8484
report({

rules/detect-buffer-noassert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ module.exports = {
6161
write,
6262
},
6363
},
64-
create: function (context) {
64+
create(context) {
6565
return {
6666
MemberExpression: function (node) {
6767
let index;

rules/detect-child-process.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ module.exports = {
2323
url: 'https://github.com/eslint-community/eslint-plugin-security/blob/main/docs/rules/detect-child-process.md',
2424
},
2525
},
26-
create: function (context) {
26+
create(context) {
27+
const sourceCode = context.sourceCode || context.getSourceCode();
2728
return {
2829
CallExpression: function (node) {
2930
if (node.callee.name === 'require') {
@@ -41,19 +42,21 @@ module.exports = {
4142
return;
4243
}
4344

45+
const scope = sourceCode.getScope ? sourceCode.getScope(node) : context.getScope();
46+
4447
// Reports non-literal `exec()` calls.
4548
if (
4649
!node.arguments.length ||
4750
isStaticExpression({
4851
node: node.arguments[0],
49-
scope: context.getScope(),
52+
scope,
5053
})
5154
) {
5255
return;
5356
}
5457
const pathInfo = getImportAccessPath({
5558
node: node.callee,
56-
scope: context.getScope(),
59+
scope,
5760
packageNames: childProcessPackageNames,
5861
});
5962
const fnName = pathInfo && pathInfo.path.length === 1 && pathInfo.path[0];

rules/detect-disable-mustache-escape.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
url: 'https://github.com/eslint-community/eslint-plugin-security/blob/main/docs/rules/detect-disable-mustache-escape.md',
1111
},
1212
},
13-
create: function (context) {
13+
create(context) {
1414
return {
1515
AssignmentExpression: function (node) {
1616
if (node.operator === '=') {

rules/detect-new-buffer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
url: 'https://github.com/eslint-community/eslint-plugin-security/blob/main/docs/rules/detect-new-buffer.md',
1111
},
1212
},
13-
create: function (context) {
13+
create(context) {
1414
return {
1515
NewExpression: function (node) {
1616
if (node.callee.name === 'Buffer' && node.arguments[0] && node.arguments[0].type !== 'Literal') {

rules/detect-no-csrf-before-method-override.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = {
1919
url: 'https://github.com/eslint-community/eslint-plugin-security/blob/main/docs/rules/detect-no-csrf-before-method-override.md',
2020
},
2121
},
22-
create: function (context) {
22+
create(context) {
2323
let csrf = false;
2424

2525
return {

rules/detect-non-literal-fs-filename.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ module.exports = {
2626
url: 'https://github.com/eslint-community/eslint-plugin-security/blob/main/docs/rules/detect-non-literal-fs-filename.md',
2727
},
2828
},
29-
create: function (context) {
29+
create(context) {
30+
const sourceCode = context.sourceCode || context.getSourceCode();
3031
return {
31-
CallExpression: function (node) {
32+
CallExpression(node) {
3233
// don't check require. If all arguments are Literals, it's surely safe!
3334
if ((node.callee.type === 'Identifier' && node.callee.name === 'require') || node.arguments.every((argument) => argument.type === 'Literal')) {
3435
return;
3536
}
3637

38+
const scope = sourceCode.getScope ? sourceCode.getScope(node) : context.getScope();
3739
const pathInfo = getImportAccessPath({
3840
node: node.callee,
39-
scope: context.getScope(),
41+
scope,
4042
packageNames: fsPackageNames,
4143
});
4244
if (!pathInfo) {
@@ -79,7 +81,8 @@ module.exports = {
7981
continue;
8082
}
8183
const argument = node.arguments[index];
82-
if (isStaticExpression({ node: argument, scope: context.getScope() })) {
84+
85+
if (isStaticExpression({ node: argument, scope })) {
8386
continue;
8487
}
8588
indices.push(index);

rules/detect-non-literal-regexp.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@ module.exports = {
2121
url: 'https://github.com/eslint-community/eslint-plugin-security/blob/main/docs/rules/detect-non-literal-regexp.md',
2222
},
2323
},
24-
create: function (context) {
24+
create(context) {
25+
const sourceCode = context.sourceCode || context.getSourceCode();
26+
2527
return {
26-
NewExpression: function (node) {
28+
NewExpression(node) {
2729
if (node.callee.name === 'RegExp') {
2830
const args = node.arguments;
31+
const scope = sourceCode.getScope ? sourceCode.getScope(node) : context.getScope();
32+
2933
if (
3034
args &&
3135
args.length > 0 &&
3236
!isStaticExpression({
3337
node: args[0],
34-
scope: context.getScope(),
38+
scope,
3539
})
3640
) {
3741
return context.report({ node: node, message: 'Found non-literal argument to RegExp Constructor' });

0 commit comments

Comments
 (0)