Skip to content

Commit 3d1bf82

Browse files
authored
chore: add eslint-plugin-eslint-plugin (#91)
1 parent 352a088 commit 3d1bf82

16 files changed

+88
-46
lines changed

.eslintrc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
{
22
"extends": [
33
"eslint:recommended",
4-
"prettier"
4+
"prettier",
5+
"plugin:eslint-plugin/recommended"
56
],
67
"parserOptions": {
78
"ecmaVersion": "latest"
89
},
910
"env": {
1011
"node": true,
1112
"es2020": true
13+
},
14+
"rules": {
15+
"eslint-plugin/prefer-message-ids": "off", // TODO: enable
16+
"eslint-plugin/require-meta-docs-url": [
17+
"error",
18+
{
19+
"pattern":
20+
"https://github.com/nodesecurity/eslint-plugin-security#{{name}}",
21+
},
22+
],
23+
"eslint-plugin/require-meta-schema": "off", // TODO: enable
24+
"eslint-plugin/require-meta-type": "off"// TODO: enable
1225
}
1326
}

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"eslint": "^8.11.0",
4747
"eslint-config-nodesecurity": "^1.3.1",
4848
"eslint-config-prettier": "^8.5.0",
49+
"eslint-plugin-eslint-plugin": "^5.0.2",
4950
"lint-staged": "^12.3.7",
5051
"mocha": "^9.2.2",
5152
"prettier": "^2.6.2",

rules/detect-buffer-noassert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module.exports = {
7272
}
7373

7474
if (index && node.parent && node.parent.arguments && node.parent.arguments[index] && node.parent.arguments[index].value) {
75-
return context.report(node, `Found Buffer.${node.property.name} with noAssert flag set true`);
75+
return context.report({ node: node, message: `Found Buffer.${node.property.name} with noAssert flag set true` });
7676
}
7777
},
7878
};

rules/detect-child-process.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
description: 'Detect instances of "child_process" & non-literal "exec()" calls.',
2222
category: 'Possible Security Vulnerability',
2323
recommended: true,
24-
url: 'https://github.com/nodesecurity/eslint-plugin-security/blob/main/docs/avoid-command-injection-node.md',
24+
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-child-process',
2525
},
2626
},
2727
create: function (context) {
@@ -35,14 +35,14 @@ module.exports = {
3535
} else if (node.parent.type === 'AssignmentExpression' && node.parent.operator === '=') {
3636
names.push(node.parent.left.name);
3737
}
38-
return context.report(node, 'Found require("child_process")');
38+
return context.report({ node: node, message: 'Found require("child_process")' });
3939
}
4040
}
4141
},
4242
MemberExpression: function (node) {
4343
if (node.property.name === 'exec' && names.indexOf(node.object.name) > -1) {
4444
if (node.parent && node.parent.arguments.length && node.parent.arguments[0].type !== 'Literal') {
45-
return context.report(node, 'Found child_process.exec() with non Literal first argument');
45+
return context.report({ node: node, message: 'Found child_process.exec() with non Literal first argument' });
4646
}
4747
}
4848
},

rules/detect-disable-mustache-escape.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ module.exports = {
77
description: 'Detects "object.escapeMarkup = false", which can be used with some template engines to disable escaping of HTML entities.',
88
category: 'Possible Security Vulnerability',
99
recommended: true,
10-
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-disable-mustache-escape'
11-
}
10+
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-disable-mustache-escape',
11+
},
1212
},
1313
create: function (context) {
1414
return {
@@ -17,12 +17,12 @@ module.exports = {
1717
if (node.left.property) {
1818
if (node.left.property.name === 'escapeMarkup') {
1919
if (node.right.value === false) {
20-
context.report(node, 'Markup escaping disabled.');
20+
context.report({ node: node, message: 'Markup escaping disabled.' });
2121
}
2222
}
2323
}
2424
}
25-
}
25+
},
2626
};
27-
}
27+
},
2828
};

rules/detect-eval-with-expression.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ module.exports = {
1616
description: 'Detects "eval(variable)" which can allow an attacker to run arbitrary code inside your process.',
1717
category: 'Possible Security Vulnerability',
1818
recommended: true,
19-
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-eval-with-expression'
20-
}
19+
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-eval-with-expression',
20+
},
2121
},
2222
create: function (context) {
2323
return {
2424
CallExpression: function (node) {
2525
if (node.callee.name === 'eval' && node.arguments[0].type !== 'Literal') {
26-
context.report(node, `eval with argument of type ${node.arguments[0].type}`);
26+
context.report({ node: node, message: `eval with argument of type ${node.arguments[0].type}` });
2727
}
28-
}
28+
},
2929
};
30-
}
30+
},
3131
};

rules/detect-new-buffer.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ module.exports = {
77
description: 'Detect instances of new Buffer(argument) where argument is any non-literal value.',
88
category: 'Possible Security Vulnerability',
99
recommended: true,
10-
url: 'https://github.com/nodesecurity/eslint-plugin-security/blob/main/README.md'
11-
}
10+
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-new-buffer',
11+
},
1212
},
1313
create: function (context) {
1414
return {
1515
NewExpression: function (node) {
1616
if (node.callee.name === 'Buffer' && node.arguments[0] && node.arguments[0].type !== 'Literal') {
17-
return context.report(node, 'Found new Buffer');
17+
return context.report({ node: node, message: 'Found new Buffer' });
1818
}
19-
}
19+
},
2020
};
21-
}
21+
},
2222
};

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ module.exports = {
1616
description: 'Detects Express "csrf" middleware setup before "method-override" middleware.',
1717
category: 'Possible Security Vulnerability',
1818
recommended: true,
19-
url: 'https://github.com/nodesecurity/eslint-plugin-security/blob/main/docs/bypass-connect-csrf-protection-by-abusing.md',
19+
url: 'https://github.com/nodesecurity/eslint-plugin-security#detect-no-csrf-before-method-override',
2020
},
2121
},
2222
create: function (context) {
2323
let csrf = false;
2424

2525
return {
2626
CallExpression: function (node) {
27-
const token = context.getTokens(node)[0];
27+
const token = context.getSourceCode().getTokens(node)[0];
2828
const nodeValue = token.value;
2929

3030
if (nodeValue === 'express') {
@@ -33,7 +33,7 @@ module.exports = {
3333
}
3434

3535
if (node.callee.property.name === 'methodOverride' && csrf) {
36-
context.report(node, 'express.csrf() middleware found before express.methodOverride()');
36+
context.report({ node: node, message: 'express.csrf() middleware found before express.methodOverride()' });
3737
}
3838
if (node.callee.property.name === 'csrf') {
3939
// Keep track of found CSRF

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = {
3939
}
4040

4141
if (result.length > 0) {
42-
return context.report(node, `Found fs.${node.property.name} with non literal argument at index ${result.join(',')}`);
42+
return context.report({ node: node, message: `Found fs.${node.property.name} with non literal argument at index ${result.join(',')}` });
4343
}
4444

4545
/*

0 commit comments

Comments
 (0)