Skip to content

Commit 47640eb

Browse files
committed
update lint rules to match @npmcli/arborist
1 parent b737ee9 commit 47640eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+1118
-1195
lines changed

.eslintrc.json

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
22
"parserOptions": {
3-
"ecmaVersion": 2020,
4-
"ecmaFeatures": {
5-
"jsx": true
6-
},
7-
"sourceType": "module"
3+
"ecmaVersion": 2018,
4+
"ecmaFeatures": {},
5+
"sourceType": "script"
86
},
97

108
"env": {
@@ -30,20 +28,20 @@
3028
"array-bracket-spacing": ["error", "never"],
3129
"arrow-spacing": ["error", { "before": true, "after": true }],
3230
"block-spacing": ["error", "always"],
33-
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
31+
"brace-style": ["error", "1tbs", { "allowSingleLine": false }],
3432
"camelcase": ["error", { "properties": "never" }],
3533
"comma-dangle": ["error", {
36-
"arrays": "never",
37-
"objects": "never",
38-
"imports": "never",
39-
"exports": "never",
34+
"arrays": "always-multiline",
35+
"objects": "always-multiline",
36+
"imports": "always-multiline",
37+
"exports": "always-multiline",
4038
"functions": "never"
4139
}],
4240
"comma-spacing": ["error", { "before": false, "after": true }],
4341
"comma-style": ["error", "last"],
4442
"computed-property-spacing": ["error", "never"],
4543
"constructor-super": "error",
46-
"curly": ["error", "multi-line"],
44+
"curly": ["error", "multi-or-nest"],
4745
"dot-location": ["error", "property"],
4846
"dot-notation": ["error", { "allowKeywords": true }],
4947
"eol-last": "error",
@@ -77,7 +75,7 @@
7775
"no-case-declarations": "error",
7876
"no-class-assign": "error",
7977
"no-compare-neg-zero": "error",
80-
"no-cond-assign": "error",
78+
"no-cond-assign": "off",
8179
"no-const-assign": "error",
8280
"no-constant-condition": ["error", { "checkLoops": false }],
8381
"no-control-regex": "error",
@@ -104,25 +102,18 @@
104102
"no-invalid-regexp": "error",
105103
"no-irregular-whitespace": "error",
106104
"no-iterator": "error",
107-
"no-labels": ["error", { "allowLoop": false, "allowSwitch": false }],
105+
"no-labels": ["error", { "allowLoop": true, "allowSwitch": false }],
108106
"no-lone-blocks": "error",
109107
"no-misleading-character-class": "error",
110108
"no-prototype-builtins": "error",
111109
"no-useless-catch": "error",
112-
"no-mixed-operators": ["error", {
113-
"groups": [
114-
["==", "!=", "===", "!==", ">", ">=", "<", "<="],
115-
["&&", "||"],
116-
["in", "instanceof"]
117-
],
118-
"allowSamePrecedence": true
119-
}],
110+
"no-mixed-operators": "off",
120111
"no-mixed-spaces-and-tabs": "error",
121112
"no-multi-spaces": "error",
122113
"no-multi-str": "error",
123114
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 0 }],
124115
"no-negated-in-lhs": "error",
125-
"no-new": "error",
116+
"no-new": "off",
126117
"no-new-func": "error",
127118
"no-new-object": "error",
128119
"no-new-require": "error",
@@ -135,8 +126,8 @@
135126
"no-proto": "error",
136127
"no-redeclare": ["error", { "builtinGlobals": false }],
137128
"no-regex-spaces": "error",
138-
"no-return-assign": ["error", "except-parens"],
139-
"no-self-assign": ["error", { "props": true }],
129+
"no-return-assign": "off",
130+
"no-self-assign": "off",
140131
"no-self-compare": "error",
141132
"no-sequences": "error",
142133
"no-shadow-restricted-names": "error",
@@ -166,16 +157,17 @@
166157
"no-void": "error",
167158
"no-whitespace-before-property": "error",
168159
"no-with": "error",
169-
"object-curly-newline": ["error", { "multiline": true, "consistent": true }],
170-
"object-curly-spacing": ["error", "always"],
160+
"nonblock-statement-body-position": [2, "below"],
161+
"object-curly-newline": "off",
162+
"object-curly-spacing": "off",
171163
"object-property-newline": ["error", { "allowMultiplePropertiesPerLine": true }],
172164
"one-var": ["error", { "initialized": "never" }],
173-
"operator-linebreak": ["error", "after", { "overrides": { "?": "before", ":": "before", "|>": "before" } }],
165+
"operator-linebreak": "off",
174166
"padded-blocks": ["error", { "blocks": "never", "switches": "never", "classes": "never" }],
175167
"prefer-const": ["error", {"destructuring": "all"}],
176168
"prefer-promise-reject-errors": "error",
177169
"quote-props": ["error", "as-needed"],
178-
"quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": false }],
170+
"quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
179171
"rest-spread-spacing": ["error", "never"],
180172
"semi": ["error", "never"],
181173
"semi-spacing": ["error", { "before": false, "after": true }],

lib/access.js

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ const subcommands = [
3434
'ls-collaborators',
3535
'edit',
3636
'2fa-required',
37-
'2fa-not-required'
37+
'2fa-not-required',
3838
]
3939

4040
const UsageError = (msg) =>
4141
Object.assign(new Error(`\nUsage: ${msg}\n\n` + usage), {
42-
code: 'EUSAGE'
42+
code: 'EUSAGE',
4343
})
4444

4545
const cmd = (args, cb) =>
@@ -53,30 +53,27 @@ const cmd = (args, cb) =>
5353
const access = async ([cmd, ...args], cb) => {
5454
const fn = subcommands.includes(cmd) && access[cmd]
5555

56-
if (!cmd) {
56+
if (!cmd)
5757
throw UsageError('Subcommand is required.')
58-
}
5958

60-
if (!fn) {
59+
if (!fn)
6160
throw UsageError(`${cmd} is not a recognized subcommand.`)
62-
}
6361

6462
return fn(args, { ...npm.flatOptions })
6563
}
6664

6765
const completion = function (opts, cb) {
6866
var argv = opts.conf.argv.remain
69-
if (argv.length === 2) {
67+
if (argv.length === 2)
7068
return cb(null, subcommands)
71-
}
7269

7370
switch (argv[2]) {
7471
case 'grant':
75-
if (argv.length === 3) {
72+
if (argv.length === 3)
7673
return cb(null, ['read-only', 'read-write'])
77-
} else {
74+
else
7875
return cb(null, [])
79-
}
76+
8077
case 'public':
8178
case 'restricted':
8279
case 'ls-packages':
@@ -98,13 +95,11 @@ access.restricted = ([pkg], opts) =>
9895
modifyPackage(pkg, opts, libaccess.restricted)
9996

10097
access.grant = async ([perms, scopeteam, pkg], opts) => {
101-
if (!perms || (perms !== 'read-only' && perms !== 'read-write')) {
98+
if (!perms || (perms !== 'read-only' && perms !== 'read-write'))
10299
throw UsageError('First argument must be either `read-only` or `read-write`.')
103-
}
104100

105-
if (!scopeteam) {
101+
if (!scopeteam)
106102
throw UsageError('`<scope:team>` argument is required.')
107-
}
108103

109104
const [, scope, team] = scopeteam.match(/^@?([^:]+):(.*)$/) || []
110105

@@ -120,9 +115,8 @@ access.grant = async ([perms, scopeteam, pkg], opts) => {
120115
}
121116

122117
access.revoke = async ([scopeteam, pkg], opts) => {
123-
if (!scopeteam) {
118+
if (!scopeteam)
124119
throw UsageError('`<scope:team>` argument is required.')
125-
}
126120

127121
const [, scope, team] = scopeteam.match(/^@?([^:]+):(.*)$/) || []
128122

@@ -144,9 +138,8 @@ access['2fa-not-required'] = access.tfaNotRequired = ([pkg], opts) =>
144138
modifyPackage(pkg, opts, libaccess.tfaNotRequired, false)
145139

146140
access['ls-packages'] = access.lsPackages = async ([owner], opts) => {
147-
if (!owner) {
141+
if (!owner)
148142
owner = await getIdentity(opts)
149-
}
150143

151144
const pkgs = await libaccess.lsPackages(owner, opts)
152145

@@ -170,9 +163,9 @@ const modifyPackage = (pkg, opts, fn, requireScope = true) =>
170163
.then(pkgName => otplease(opts, opts => fn(pkgName, opts)))
171164

172165
const getPackage = async (name, requireScope) => {
173-
if (name && name.trim()) {
166+
if (name && name.trim())
174167
return name.trim()
175-
} else {
168+
else {
176169
try {
177170
const pkg = await readPackageJson(path.resolve(prefix, 'package.json'))
178171
name = pkg.name
@@ -181,16 +174,14 @@ const getPackage = async (name, requireScope) => {
181174
throw new Error(
182175
'no package name passed to command and no package.json found'
183176
)
184-
} else {
177+
} else
185178
throw err
186-
}
187179
}
188180

189-
if (requireScope && !name.match(/^@[^/]+\/.*$/)) {
181+
if (requireScope && !name.match(/^@[^/]+\/.*$/))
190182
throw UsageError('This command is only available for scoped packages.')
191-
} else {
183+
else
192184
return name
193-
}
194185
}
195186
}
196187

lib/adduser.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const authTypes = {
88
legacy: require('./auth/legacy.js'),
99
oauth: require('./auth/oauth.js'),
1010
saml: require('./auth/saml.js'),
11-
sso: require('./auth/sso.js')
11+
sso: require('./auth/sso.js'),
1212
}
1313

1414
const usage = usageUtil(
@@ -24,29 +24,26 @@ const getRegistry = ({ scope, registry }) => {
2424
if (scope) {
2525
const scopedRegistry = npm.config.get(`${scope}:registry`)
2626
const cliRegistry = npm.config.get('registry', 'cli')
27-
if (scopedRegistry && !cliRegistry) {
27+
if (scopedRegistry && !cliRegistry)
2828
return scopedRegistry
29-
}
3029
}
3130
return registry
3231
}
3332

3433
const getAuthType = ({ authType }) => {
3534
const type = authTypes[authType]
3635

37-
if (!type) {
36+
if (!type)
3837
throw new Error('no such auth module')
39-
}
4038

4139
return type
4240
}
4341

4442
const updateConfig = async ({ newCreds, registry, scope }) => {
4543
npm.config.delete('_token', 'user') // prevent legacy pollution
4644

47-
if (scope) {
45+
if (scope)
4846
npm.config.set(scope + ':registry', registry, 'user')
49-
}
5047

5148
npm.config.setCredentialsByURI(registry, newCreds)
5249
await npm.config.save('user')
@@ -63,13 +60,13 @@ const adduser = async (args) => {
6360
const { message, newCreds } = await auth({
6461
creds,
6562
registry,
66-
scope
63+
scope,
6764
})
6865

6966
await updateConfig({
7067
newCreds,
7168
registry,
72-
scope
69+
scope,
7370
})
7471

7572
output(message)

lib/audit.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ const audit = async args => {
99
const arb = new Arborist({
1010
...npm.flatOptions,
1111
audit: true,
12-
path: npm.prefix
12+
path: npm.prefix,
1313
})
1414
const fix = args[0] === 'fix'
1515
await arb.audit({ fix })
16-
if (fix) {
16+
if (fix)
1717
reifyOutput(arb)
18-
} else {
18+
else {
1919
// will throw if there's an error, because this is an audit command
2020
auditError(arb.auditReport)
2121
const reporter = npm.flatOptions.json ? 'json' : 'detail'
2222
const result = auditReport(arb.auditReport, {
2323
...npm.flatOptions,
24-
reporter
24+
reporter,
2525
})
2626
process.exitCode = process.exitCode || result.exitCode
2727
output(result.report)
@@ -41,9 +41,8 @@ const usage = usageUtil(
4141
const completion = (opts, cb) => {
4242
const argv = opts.conf.argv.remain
4343

44-
if (argv.length === 2) {
44+
if (argv.length === 2)
4545
return cb(null, ['fix'])
46-
}
4746

4847
switch (argv[2]) {
4948
case 'fix':

lib/auth/legacy.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ const login = async (opts) => {
4747
opts
4848
)
4949
} catch (err) {
50-
if (err.code === 'EOTP') {
50+
if (err.code === 'EOTP')
5151
newUser = await requestOTP()
52-
} else {
52+
else
5353
throw err
54-
}
5554
}
5655

5756
return newUser
@@ -65,20 +64,20 @@ const login = async (opts) => {
6564
opts.creds.username &&
6665
opts.creds.password &&
6766
opts.creds.email)
68-
if (err.code === 'EOTP') {
67+
if (err.code === 'EOTP')
6968
res = await requestOTP()
70-
} else if (needsMoreInfo) {
69+
else if (needsMoreInfo)
7170
throw err
72-
} else {
71+
else {
7372
// TODO: maybe this needs to check for err.code === 'E400' instead?
7473
res = await addNewUser()
7574
}
7675
}
7776

7877
const newCreds = {}
79-
if (res && res.token) {
78+
if (res && res.token)
8079
newCreds.token = res.token
81-
} else {
80+
else {
8281
newCreds.username = opts.creds.username
8382
newCreds.password = opts.creds.password
8483
newCreds.email = opts.creds.email
@@ -94,7 +93,7 @@ const login = async (opts) => {
9493

9594
return {
9695
message,
97-
newCreds
96+
newCreds,
9897
}
9998
}
10099

0 commit comments

Comments
 (0)