Skip to content

Commit 1ad8593

Browse files
committed
feat: add config recommended-legacy
it also moves rule tests to `./test/rules`, and adds a test for the configs. fixes #131 Signed-off-by: 唯然 <[email protected]>
1 parent 27cd160 commit 1ad8593

18 files changed

+56
-18
lines changed

.eslint-doc-generatorrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const prettierRC = require('./.prettierrc.json');
33

44
/** @type {import('eslint-doc-generator').GenerateOptions} */
55
const config = {
6+
ignoreConfig: ['recommended-legacy'],
67
postprocess: (doc) => format(doc, { ...prettierRC, parser: 'markdown' }),
78
};
89

README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ yarn add --dev eslint-plugin-security
2020

2121
## Usage
2222

23+
### Flat config (requires eslint >= v8.23.0)
24+
2325
Add the following to your `eslint.config.js` file:
2426

2527
```js
@@ -28,6 +30,17 @@ const pluginSecurity = require('eslint-plugin-security');
2830
module.exports = [pluginSecurity.configs.recommended];
2931
```
3032

33+
### eslintrc config (deprecated)
34+
35+
Add the following to your `.eslintrc` file:
36+
37+
````js
38+
module.exports = {
39+
"extends": [
40+
"plugin:security/recommended-legacy"
41+
]
42+
}
43+
3144
## Developer guide
3245

3346
- Use [GitHub pull requests](https://help.github.com/articles/using-pull-requests).
@@ -37,7 +50,7 @@ module.exports = [pluginSecurity.configs.recommended];
3750

3851
```sh
3952
npm run-script cont-int
40-
```
53+
````
4154
4255
## Tests
4356

index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ const recommended = {
6666
},
6767
};
6868

69-
Object.assign(plugin.configs, { recommended });
69+
const recommendedLegacy = {
70+
plugins: ['security'],
71+
rules: recommended.rules,
72+
};
73+
74+
Object.assign(plugin.configs, {
75+
recommended,
76+
'recommended-legacy': recommendedLegacy
77+
});
7078

7179
module.exports = plugin;

test/configs/index.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
const plugin = require('../../index.js');
3+
const assert = require('assert').strict;
4+
5+
describe('export plugin object', () => {
6+
it('should export rules', () => {
7+
assert(plugin.rules);
8+
assert(typeof plugin.rules['detect-unsafe-regex'] === 'object');
9+
});
10+
11+
it('should export configs', () => {
12+
assert(plugin.configs);
13+
assert(plugin.configs['recommended']);
14+
assert(plugin.configs['recommended-legacy']);
15+
});
16+
});

test/detect-bidi-characters.js test/rules/detect-bidi-characters.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const RuleTester = require('eslint').RuleTester;
44
const tester = new RuleTester();
55

66
const ruleName = 'detect-bidi-characters';
7-
const Rule = require(`../rules/${ruleName}`);
7+
const Rule = require(`../../rules/${ruleName}`);
88

99
tester.run(ruleName, Rule, {
1010
valid: [
@@ -54,7 +54,7 @@ tester.run(`${ruleName} in comment-line`, Rule, {
5454
console.log("You are an admin.");
5555
/* end admins only ‮
5656
⁦*/
57-
/* end admins only ‮
57+
/* end admins only ‮
5858
{ ⁦*/
5959
`,
6060
errors: [

test/detect-buffer-noassert.js test/rules/detect-buffer-noassert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const RuleTester = require('eslint').RuleTester;
44
const tester = new RuleTester();
55

66
const ruleName = 'detect-buffer-noassert';
7-
const rule = require(`../rules/${ruleName}`);
7+
const rule = require(`../../rules/${ruleName}`);
88

99
const allMethodNames = [...rule.meta.__methodsToCheck.read, ...rule.meta.__methodsToCheck.write];
1010

test/detect-child-process.js test/rules/detect-child-process.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const tester = new RuleTester({
99
});
1010

1111
const ruleName = 'detect-child-process';
12-
const rule = require(`../rules/${ruleName}`);
12+
const rule = require(`../../rules/${ruleName}`);
1313

1414
tester.run(ruleName, rule, {
1515
valid: [

test/detect-disable-mustache-escape.js test/rules/detect-disable-mustache-escape.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const tester = new RuleTester();
55

66
const ruleName = 'detect-disable-mustache-escape';
77

8-
tester.run(ruleName, require(`../rules/${ruleName}`), {
8+
tester.run(ruleName, require(`../../rules/${ruleName}`), {
99
valid: [{ code: 'escapeMarkup = false' }],
1010
invalid: [
1111
{

test/detect-eval-with-expression.js test/rules/detect-eval-with-expression.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const tester = new RuleTester();
55

66
const ruleName = 'detect-eval-with-expression';
77

8-
tester.run(ruleName, require(`../rules/${ruleName}`), {
8+
tester.run(ruleName, require(`../../rules/${ruleName}`), {
99
valid: [{ code: "eval('alert()')" }],
1010
invalid: [
1111
{

test/detect-new-buffer.js test/rules/detect-new-buffer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const tester = new RuleTester();
66
const ruleName = 'detect-new-buffer';
77
const invalid = 'var a = new Buffer(c)';
88

9-
tester.run(ruleName, require(`../rules/${ruleName}`), {
9+
tester.run(ruleName, require(`../../rules/${ruleName}`), {
1010
valid: [{ code: "var a = new Buffer('test')" }],
1111
invalid: [
1212
{

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const tester = new RuleTester();
55

66
const ruleName = 'detect-no-csrf-before-method-override';
77

8-
tester.run(ruleName, require(`../rules/${ruleName}`), {
8+
tester.run(ruleName, require(`../../rules/${ruleName}`), {
99
valid: [{ code: 'express.methodOverride();express.csrf()' }],
1010
invalid: [
1111
{

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const tester = new RuleTester({
1010

1111
const ruleName = 'detect-non-literal-fs-filename';
1212

13-
tester.run(ruleName, require(`../rules/${ruleName}`), {
13+
tester.run(ruleName, require(`../../rules/${ruleName}`), {
1414
valid: [
1515
{
1616
code: `var fs = require('fs');
@@ -29,7 +29,7 @@ tester.run(ruleName, require(`../rules/${ruleName}`), {
2929
import { promises as fsp } from 'fs';
3030
import fs from 'fs';
3131
import path from 'path';
32-
32+
3333
const index = await fsp.readFile(path.resolve(__dirname, './index.html'), 'utf-8');
3434
const key = fs.readFileSync(path.join(__dirname, './ssl.key'));
3535
await fsp.writeFile(path.resolve(__dirname, './sitemap.xml'), sitemap);`,

test/detect-non-literal-regexp.js test/rules/detect-non-literal-regexp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const tester = new RuleTester();
66
const ruleName = 'detect-non-literal-regexp';
77
const invalid = "var a = new RegExp(c, 'i')";
88

9-
tester.run(ruleName, require(`../rules/${ruleName}`), {
9+
tester.run(ruleName, require(`../../rules/${ruleName}`), {
1010
valid: [
1111
{ code: "var a = new RegExp('ab+c', 'i')" },
1212
{

test/detect-non-literal-require.js test/rules/detect-non-literal-require.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const tester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
66

77
const ruleName = 'detect-non-literal-require';
88

9-
tester.run(ruleName, require(`../rules/${ruleName}`), {
9+
tester.run(ruleName, require(`../../rules/${ruleName}`), {
1010
valid: [
1111
{ code: "var a = require('b')" },
1212
{ code: 'var a = require(`b`)' },

test/detect-object-injection.js test/rules/detect-object-injection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const tester = new RuleTester();
55

66
const ruleName = 'detect-object-injection';
77

8-
const Rule = require(`../rules/${ruleName}`);
8+
const Rule = require(`../../rules/${ruleName}`);
99

1010
const valid = 'var a = {};';
1111
// const invalidVariable = "TODO";

test/detect-possible-timing-attacks.js test/rules/detect-possible-timing-attacks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const RuleTester = require('eslint').RuleTester;
44
const tester = new RuleTester();
55

66
const ruleName = 'detect-possible-timing-attacks';
7-
const Rule = require(`../rules/${ruleName}`);
7+
const Rule = require(`../../rules/${ruleName}`);
88

99
const valid = 'if (age === 5) {}';
1010
const invalidLeft = "if (password === 'mypass') {}";

test/detect-pseudoRandomBytes.js test/rules/detect-pseudoRandomBytes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const tester = new RuleTester();
66
const ruleName = 'detect-pseudoRandomBytes';
77
const invalid = 'crypto.pseudoRandomBytes';
88

9-
tester.run(ruleName, require(`../rules/${ruleName}`), {
9+
tester.run(ruleName, require(`../../rules/${ruleName}`), {
1010
valid: [{ code: 'crypto.randomBytes' }],
1111
invalid: [
1212
{

test/detect-unsafe-regexp.js test/rules/detect-unsafe-regexp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const RuleTester = require('eslint').RuleTester;
44
const tester = new RuleTester();
55

66
const ruleName = 'detect-unsafe-regex';
7-
const Rule = require(`../rules/${ruleName}`);
7+
const Rule = require(`../../rules/${ruleName}`);
88

99
tester.run(ruleName, Rule, {
1010
valid: [{ code: '/^d+1337d+$/' }],

0 commit comments

Comments
 (0)