Skip to content
This repository was archived by the owner on Jan 20, 2022. It is now read-only.

Commit 5280e51

Browse files
committed
use a linter
We have more people contributing to this library now, so adding some automated consistency is looking more and more important. Also, this found a few unused variables, which highlighted a bug, albeit a harmless one: a timer string was being created, but then no timer being attached to Shrinkwrap loading. (That's why the reify snapshot is updated.) Some other light refactoring was done in a few places to get eslint to produce a reasonably readable output, and I think mostly for the improvement of readability. I don't 100% agree with every choice the linter is making here. Specifically, I prefer using {} around single-line blocks in some cases, especially loops, but they are omitted most of the time, so that's the way I set the config. Consistency is good though, and this will help us maintain it. Linting is set up as a posttest operation, so we can catch things without having it stubbornly refuse to even run tests until it's all sparkling.
1 parent da93ff1 commit 5280e51

30 files changed

+5015
-2255
lines changed

.eslintrc.json

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 2020,
4+
"ecmaFeatures": {
5+
"jsx": true
6+
},
7+
"sourceType": "module"
8+
},
9+
10+
"env": {
11+
"es6": true,
12+
"node": true
13+
},
14+
15+
"plugins": [
16+
"import",
17+
"node",
18+
"promise",
19+
"standard"
20+
],
21+
22+
"globals": {
23+
"document": "readonly",
24+
"navigator": "readonly",
25+
"window": "readonly"
26+
},
27+
28+
"rules": {
29+
"accessor-pairs": "error",
30+
"array-bracket-spacing": ["error", "never"],
31+
"arrow-spacing": ["error", { "before": true, "after": true }],
32+
"block-spacing": ["error", "always"],
33+
"brace-style": ["error", "1tbs", { "allowSingleLine": false }],
34+
"camelcase": ["error", { "properties": "never" }],
35+
"comma-dangle": ["error", {
36+
"arrays": "always-multiline",
37+
"objects": "always-multiline",
38+
"imports": "always-multiline",
39+
"exports": "always-multiline",
40+
"functions": "never"
41+
}],
42+
"comma-spacing": ["error", { "before": false, "after": true }],
43+
"comma-style": ["error", "last"],
44+
"computed-property-spacing": ["error", "never"],
45+
"constructor-super": "error",
46+
"curly": ["error", "multi-or-nest"],
47+
"dot-location": ["error", "property"],
48+
"dot-notation": ["error", { "allowKeywords": true }],
49+
"eol-last": "error",
50+
"eqeqeq": ["error", "always", { "null": "ignore" }],
51+
"func-call-spacing": ["error", "never"],
52+
"generator-star-spacing": ["error", { "before": true, "after": true }],
53+
"handle-callback-err": ["error", "^(err|error)$" ],
54+
"indent": ["error", 2, {
55+
"SwitchCase": 1,
56+
"VariableDeclarator": 1,
57+
"outerIIFEBody": 1,
58+
"MemberExpression": 1,
59+
"FunctionDeclaration": { "parameters": 1, "body": 1 },
60+
"FunctionExpression": { "parameters": 1, "body": 1 },
61+
"CallExpression": { "arguments": 1 },
62+
"ArrayExpression": 1,
63+
"ObjectExpression": 1,
64+
"ImportDeclaration": 1,
65+
"flatTernaryExpressions": true,
66+
"ignoreComments": false,
67+
"ignoredNodes": ["TemplateLiteral *"]
68+
}],
69+
"key-spacing": ["error", { "beforeColon": false, "afterColon": true }],
70+
"keyword-spacing": ["error", { "before": true, "after": true }],
71+
"lines-between-class-members": ["error", "always", { "exceptAfterSingleLine": true }],
72+
"new-cap": ["error", { "newIsCap": true, "capIsNew": false, "properties": true }],
73+
"new-parens": "error",
74+
"no-array-constructor": "error",
75+
"no-async-promise-executor": "error",
76+
"no-caller": "error",
77+
"no-case-declarations": "error",
78+
"no-class-assign": "error",
79+
"no-compare-neg-zero": "error",
80+
"no-cond-assign": "off",
81+
"no-const-assign": "error",
82+
"no-constant-condition": ["error", { "checkLoops": false }],
83+
"no-control-regex": "error",
84+
"no-debugger": "error",
85+
"no-delete-var": "error",
86+
"no-dupe-args": "error",
87+
"no-dupe-class-members": "error",
88+
"no-dupe-keys": "error",
89+
"no-duplicate-case": "error",
90+
"no-empty-character-class": "error",
91+
"no-empty-pattern": "error",
92+
"no-eval": "error",
93+
"no-ex-assign": "error",
94+
"no-extend-native": "error",
95+
"no-extra-bind": "error",
96+
"no-extra-boolean-cast": "error",
97+
"no-extra-parens": ["error", "functions"],
98+
"no-fallthrough": "error",
99+
"no-floating-decimal": "error",
100+
"no-func-assign": "error",
101+
"no-global-assign": "error",
102+
"no-implied-eval": "error",
103+
"no-inner-declarations": ["error", "functions"],
104+
"no-invalid-regexp": "error",
105+
"no-irregular-whitespace": "error",
106+
"no-iterator": "error",
107+
"no-labels": ["error", { "allowLoop": false, "allowSwitch": false }],
108+
"no-lone-blocks": "error",
109+
"no-misleading-character-class": "error",
110+
"no-prototype-builtins": "error",
111+
"no-useless-catch": "error",
112+
"no-mixed-operators": "off",
113+
"no-mixed-spaces-and-tabs": "error",
114+
"no-multi-spaces": "error",
115+
"no-multi-str": "error",
116+
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 0 }],
117+
"no-negated-in-lhs": "error",
118+
"no-new": "off",
119+
"no-new-func": "error",
120+
"no-new-object": "error",
121+
"no-new-require": "error",
122+
"no-new-symbol": "error",
123+
"no-new-wrappers": "error",
124+
"no-obj-calls": "error",
125+
"no-octal": "error",
126+
"no-octal-escape": "error",
127+
"no-path-concat": "error",
128+
"no-proto": "error",
129+
"no-redeclare": ["error", { "builtinGlobals": false }],
130+
"no-regex-spaces": "error",
131+
"no-return-assign": "off",
132+
"no-self-assign": "off",
133+
"no-self-compare": "error",
134+
"no-sequences": "error",
135+
"no-shadow-restricted-names": "error",
136+
"no-sparse-arrays": "error",
137+
"no-tabs": "error",
138+
"no-template-curly-in-string": "error",
139+
"no-this-before-super": "error",
140+
"no-throw-literal": "off",
141+
"no-trailing-spaces": "error",
142+
"no-undef": "error",
143+
"no-undef-init": "error",
144+
"no-unexpected-multiline": "error",
145+
"no-unmodified-loop-condition": "error",
146+
"no-unneeded-ternary": ["error", { "defaultAssignment": false }],
147+
"no-unreachable": "error",
148+
"no-unsafe-finally": 0,
149+
"no-unsafe-negation": "error",
150+
"no-unused-expressions": ["error", { "allowShortCircuit": true, "allowTernary": true, "allowTaggedTemplates": true }],
151+
"no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": true }],
152+
"no-use-before-define": ["error", { "functions": false, "classes": false, "variables": false }],
153+
"no-useless-call": "error",
154+
"no-useless-computed-key": "error",
155+
"no-useless-constructor": "error",
156+
"no-useless-escape": "error",
157+
"no-useless-rename": "error",
158+
"no-useless-return": "error",
159+
"no-void": "error",
160+
"no-whitespace-before-property": "error",
161+
"no-with": "error",
162+
"object-curly-newline": "off",
163+
"object-curly-spacing": "off",
164+
"object-property-newline": ["error", { "allowMultiplePropertiesPerLine": true }],
165+
"one-var": ["error", { "initialized": "never" }],
166+
"operator-linebreak": "off",
167+
"padded-blocks": ["error", { "blocks": "never", "switches": "never", "classes": "never" }],
168+
"prefer-const": ["error", {"destructuring": "all"}],
169+
"prefer-promise-reject-errors": "error",
170+
"quote-props": ["error", "as-needed"],
171+
"quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
172+
"rest-spread-spacing": ["error", "never"],
173+
"semi": ["error", "never"],
174+
"semi-spacing": ["error", { "before": false, "after": true }],
175+
"space-before-blocks": ["error", "always"],
176+
"space-before-function-paren": ["error", "always"],
177+
"space-in-parens": ["error", "never"],
178+
"space-infix-ops": "error",
179+
"space-unary-ops": ["error", { "words": true, "nonwords": false }],
180+
"spaced-comment": ["error", "always", {
181+
"line": { "markers": ["*package", "!", "/", ",", "="] },
182+
"block": { "balanced": true, "markers": ["*package", "!", ",", ":", "::", "flow-include"], "exceptions": ["*"] }
183+
}],
184+
"symbol-description": "error",
185+
"template-curly-spacing": ["error", "never"],
186+
"template-tag-spacing": ["error", "never"],
187+
"unicode-bom": ["error", "never"],
188+
"use-isnan": "error",
189+
"valid-typeof": ["error", { "requireStringLiterals": true }],
190+
"wrap-iife": ["error", "any", { "functionPrototypeMethods": true }],
191+
"yield-star-spacing": ["error", "both"],
192+
"yoda": ["error", "never"],
193+
194+
"import/export": "error",
195+
"import/first": "error",
196+
"import/no-absolute-path": ["error", { "esmodule": true, "commonjs": true, "amd": false }],
197+
"import/no-duplicates": "error",
198+
"import/no-named-default": "error",
199+
"import/no-webpack-loader-syntax": "error",
200+
201+
"node/no-deprecated-api": "error",
202+
"node/process-exit-as-throw": "error",
203+
204+
"promise/param-names": "off",
205+
206+
"standard/no-callback-literal": "error"
207+
}
208+
}

lib/add-rm-pkg-deps.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,22 @@ const removeFromOthers = (name, type, pkg) => {
2626
break
2727
}
2828

29-
for (const other of others) {
29+
for (const other of others)
3030
deleteSubKey(pkg, other, name)
31-
}
3231
}
3332

3433
const add = ({pkg, add, saveBundle, saveType}) => {
35-
for (const spec of add) {
34+
for (const spec of add)
3635
addSingle({pkg, spec, saveBundle, saveType})
37-
}
36+
3837
return pkg
3938
}
4039

4140
const addSingle = ({pkg, spec, saveBundle, saveType}) => {
4241
if (!saveType)
4342
saveType = getSaveType(pkg, spec)
4443

45-
const {name, rawSpec, type: specType, fetchSpec } = spec
44+
const { name, rawSpec } = spec
4645
removeFromOthers(name, saveType, pkg)
4746
const type = saveType === 'prod' ? 'dependencies'
4847
: saveType === 'dev' ? 'devDependencies'
@@ -51,9 +50,8 @@ const addSingle = ({pkg, spec, saveBundle, saveType}) => {
5150
: /* istanbul ignore next */ null
5251

5352
pkg[type] = pkg[type] || {}
54-
if (rawSpec !== '' || pkg[type][name] === undefined) {
53+
if (rawSpec !== '' || pkg[type][name] === undefined)
5554
pkg[type][name] = rawSpec || '*'
56-
}
5755

5856
if (saveType === 'peer' || saveType === 'peerOptional') {
5957
const pdm = pkg.peerDependenciesMeta || {}
@@ -78,7 +76,6 @@ const getSaveType = (pkg, spec) => {
7876
const {name} = spec
7977
const {
8078
// these names are so lonnnnngggg
81-
dependencies: deps,
8279
devDependencies: devDeps,
8380
optionalDependencies: optDeps,
8481
peerDependencies: peerDeps,
@@ -114,9 +111,8 @@ const rm = (pkg, rm) => {
114111
'peerDependenciesMeta',
115112
'devDependencies',
116113
]) {
117-
for (const name of rm) {
114+
for (const name of rm)
118115
deleteSubKey(pkg, type, name)
119-
}
120116
}
121117
if (pkg.bundleDependencies) {
122118
pkg.bundleDependencies = pkg.bundleDependencies

lib/arborist/audit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// mixin implementing the audit method
22

3-
const Reifier = require('./reify.js')
43
const AuditReport = require('../audit-report.js')
54

65
// shared with reify
@@ -9,11 +8,12 @@ const _global = Symbol.for('global')
98
module.exports = cls => class Auditor extends cls {
109
async audit (options = {}) {
1110
this.addTracker('audit')
12-
if (this[_global])
11+
if (this[_global]) {
1312
throw Object.assign(
1413
new Error('`npm audit` does not support testing globals'),
1514
{ code: 'EAUDITGLOBAL' }
1615
)
16+
}
1717

1818
// allow the user to set options on the ctor as well.
1919
// XXX: deprecate separate method options objects.

0 commit comments

Comments
 (0)