Skip to content

Commit b71e842

Browse files
author
David Bradshaw
committed
Add security rules
1 parent 3d0202a commit b71e842

File tree

8 files changed

+81
-60
lines changed

8 files changed

+81
-60
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ The following esLint plugins are always loaded in this configuration:
6262

6363
These plugins will be loaded in based on your project `dependencies` in `package.json`. If a supported library is part of your project then it's related esLint plugins will be loaded. The following packages are supported:
6464

65-
- [eslint-plugin-fsa](https://github.com/joseph-galindo/eslint-plugin-fsa) - Flux Standard Action
65+
- [eslint-plugin-fsa](https://github.com/joseph-galindo/eslint-plugin-fsa)
6666
- [eslint-plugin-lodash](https://github.com/wix/eslint-plugin-lodash)
6767
- [eslint-plugin-lodash-fp](https://github.com/jfmengels/eslint-plugin-lodash-fp)
6868
- [eslint-plugin-ramda](https://github.com/ramda/eslint-plugin-ramda)
@@ -83,6 +83,7 @@ The prettier configs for different eslint plugins are also automatically include
8383
These plugins add code security rules to esLint.
8484

8585
- [eslint-plugin-no-secrets](https://github.com/nickdeis/eslint-plugin-no-secrets)
86+
- [eslint-plugin-no-unsanitized](https://github.com/mozilla/eslint-plugin-no-unsanitized)
8687
- [eslint-plugin-scanjs-rules](https://github.com/mozfreddyb/eslint-plugin-scanjs-rules)
8788
- [eslint-plugin-security](https://github.com/nodesecurity/eslint-plugin-security)
8889
- [eslint-plugin-sonarjs](https://github.com/SonarSource/eslint-plugin-sonarjs)

index.js

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,8 @@
11
const checkMissing = require('./lib/missing')
22
const showLoaded = require('./lib/loaded')
3-
const { hasAnyDep } = require('./lib/utils')
3+
const { rules, extraInstallPackage } = require('./packages')
44

5-
// Base rules
6-
const rules = [
7-
'array-func',
8-
'eslint-comments',
9-
'html',
10-
'json-format',
11-
'markdown',
12-
'no-constructor-bind',
13-
'no-use-extend-native',
14-
'optimize-regex',
15-
'promise',
16-
'simple-import-sort',
17-
'switch-case',
18-
'unicorn',
19-
20-
// Security Rules
21-
'no-secrets@0.5.4',
22-
'scanjs-rules',
23-
'security',
24-
'sonarjs',
25-
]
26-
27-
// Optionals rules besed on project dependencies
28-
const depRules = [
29-
'lodash',
30-
['lodash', 'lodash-fp'],
31-
'ramda',
32-
'react-redux',
33-
['redux', 'fsa'],
34-
'redux-saga',
35-
36-
// Test tools
37-
'ava',
38-
['chai', 'chai-expect'],
39-
['chai', 'chai-friendly'],
40-
'jasmine',
41-
'jest',
42-
['jest', 'jest-async'],
43-
'mocha',
44-
['mocha', 'mocha-cleanup'],
45-
'qunit',
46-
['grunt-contrib-qunit', 'qunit'],
47-
'cypress',
48-
'prettier',
49-
]
50-
51-
depRules.forEach((depRule) => {
52-
const rule = typeof depRule === 'string' ? [depRule, depRule] : depRule
53-
if (hasAnyDep(rule[0])) rules.push(rule[1])
54-
})
55-
56-
// Extra required optional packages
57-
const extraInstallPkg = [['prettier', 'eslint-config-prettier']]
58-
59-
checkMissing(rules, extraInstallPkg)
5+
checkMissing(rules, extraInstallPackage)
606
showLoaded(rules, [])
617

628
// Disable some rules in unit tests

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"read-pkg-up": "^7.0.1"
3333
},
3434
"devDependencies": {
35+
"@typescript-eslint/eslint-plugin": "^3.1.0",
3536
"ava": "^3.8.2",
3637
"babel-eslint": "^10.1.0",
3738
"chai": "^4.2.0",
@@ -64,6 +65,7 @@
6465
"eslint-plugin-mocha-cleanup": "^1.8.0",
6566
"eslint-plugin-no-constructor-bind": "^2.0.0",
6667
"eslint-plugin-no-secrets": "^0.5.4",
68+
"eslint-plugin-no-unsanitized": "^3.1.1",
6769
"eslint-plugin-no-use-extend-native": "^0.5.0",
6870
"eslint-plugin-only-error": "^1.0.2",
6971
"eslint-plugin-optimize-regex": "^1.2.0",

packages.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const { hasAnyDep } = require('./lib/utils')
2+
3+
// Base rules
4+
const rules = [
5+
'array-func',
6+
'eslint-comments',
7+
'html',
8+
'json-format',
9+
'markdown',
10+
'no-constructor-bind',
11+
'no-use-extend-native',
12+
'optimize-regex',
13+
'promise',
14+
'simple-import-sort',
15+
'switch-case',
16+
'unicorn',
17+
18+
// Security Rules
19+
'no-secrets@0.5.4',
20+
'no-unsanitized',
21+
'scanjs-rules',
22+
'security',
23+
'sonarjs',
24+
]
25+
26+
// Optionals rules besed on project dependencies
27+
const depRules = [
28+
['redux', 'fsa'],
29+
'lodash',
30+
['lodash', 'lodash-fp'],
31+
'ramda',
32+
'react-redux',
33+
'redux-saga',
34+
35+
// Test tools
36+
'ava',
37+
['chai', 'chai-expect'],
38+
['chai', 'chai-friendly'],
39+
'jasmine',
40+
'jest',
41+
['jest', 'jest-async'],
42+
'mocha',
43+
['mocha', 'mocha-cleanup'],
44+
'qunit',
45+
['grunt-contrib-qunit', 'qunit'],
46+
'cypress',
47+
'prettier',
48+
]
49+
50+
depRules.forEach((depRule) => {
51+
const rule = typeof depRule === 'string' ? [depRule, depRule] : depRule
52+
if (hasAnyDep(rule[0])) rules.push(rule[1])
53+
})
54+
55+
// Extra required optional packages
56+
const extraInstallPackage = [['prettier', 'eslint-config-prettier']]
57+
58+
module.exports = { rules, extraInstallPackage }

rules/markdown.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = {
22
plugins: ['markdown'],
33
overrides: [
44
{
5-
files: ['**/*.md'],
5+
files: ['*.md', '**/*.md'],
66
parserOptions: {
77
ecmacFeatures: {
88
impliedStrict: true,
@@ -17,7 +17,6 @@ module.exports = {
1717
'no-unused-vars': 'off',
1818
'prefer-reflect': 'off',
1919
strict: 'off',
20-
'unicorn/filename-case': 'off',
2120
},
2221
},
2322
],

rules/no-unsanitized.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
plugins: ['no-unsanitized'],
3+
rules: {
4+
'no-unsanitized/method': 'error',
5+
'no-unsanitized/property': 'error',
6+
},
7+
}

rules/security.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ module.exports = {
33
extends: ['plugin:security/recommended'],
44
rules: {
55
'security/detect-object-injection': 0,
6-
}
6+
},
77
}

rules/unicorn.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
module.exports = {
22
extends: ['plugin:unicorn/recommended'],
3+
overrides: [
4+
{
5+
files: ['*.md', '**/*.md'],
6+
rules: {
7+
'unicorn/filename-case': 'off',
8+
},
9+
},
10+
],
311
rules: {
412
'unicorn/prefer-exponentiation-operator': 0,
513
'unicorn/regex-shorthand': 0,

0 commit comments

Comments
 (0)