Skip to content

Commit f130a81

Browse files
committed
fix(linting): add scripts, docs, smoke-tests
There is code in all of these places we control so it should be linted PR-URL: #3367 Credit: @wraithgar Close: #3367 Reviewed-by: @isaacs
1 parent 26d00c4 commit f130a81

9 files changed

+303
-318
lines changed

docs/dockhand.js

+256-269
Large diffs are not rendered by default.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
"sudotest:nocleanup": "sudo NO_TEST_CLEANUP=1 npm run test --",
205205
"posttest": "npm run lint",
206206
"eslint": "eslint",
207-
"lint": "npm run eslint -- test/lib test/bin lib",
207+
"lint": "npm run eslint -- test/lib test/bin lib scripts docs smoke-tests",
208208
"lintfix": "npm run lint -- --fix",
209209
"prelint": "rimraf test/npm_cache*",
210210
"resetdeps": "bash scripts/resetdeps.sh",

scripts/bundle-and-gitignore-deps.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const arb = new Arborist({ path: resolve(__dirname, '..') })
99
const shouldIgnore = []
1010

1111
arb.loadVirtual().then(tree => {
12-
for (const [name, node] of tree.children.entries()) {
12+
for (const node of tree.children.values()) {
1313
if (node.dev || node.isLink) {
1414
console.error('ignore', node.name)
1515
shouldIgnore.push(node.name)

scripts/changelog.js

+28-31
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,38 @@ const log = execSync(`git log --reverse --pretty='format:%h %H%d %s (%aN)%n%b%n-
1818
main()
1919

2020
function shortname (url) {
21-
let matched = url.match(/https:\/\/github\.com\/([^/]+\/[^/]+)\/(?:pull|issues)\/(\d+)/) ||
21+
const matched = url.match(/https:\/\/github\.com\/([^/]+\/[^/]+)\/(?:pull|issues)\/(\d+)/) ||
2222
url.match(/https:\/\/(npm\.community)\/t\/(?:[^/]+\/)(\d+)/)
23-
if (!matched) return false
24-
let repo = matched[1]
25-
let id = matched[2]
26-
if (repo !== 'npm/cli') {
23+
if (!matched)
24+
return false
25+
const repo = matched[1]
26+
const id = matched[2]
27+
if (repo !== 'npm/cli')
2728
return `${repo}#${id}`
28-
} else {
29+
else
2930
return `#${id}`
30-
}
3131
}
3232

3333
function printCommit (c) {
3434
console.log(`* [\`${c.shortid}\`](https://github.com/npm/cli/commit/${c.fullid})`)
3535
if (c.fixes.length) {
3636
for (const fix of c.fixes) {
37-
let label = shortname(fix)
38-
if (label) {
37+
const label = shortname(fix)
38+
if (label)
3939
console.log(` [${label}](${fix})`)
40-
}
4140
}
4241
} else if (c.prurl) {
43-
let label = shortname(c.prurl)
44-
if (label) {
42+
const label = shortname(c.prurl)
43+
if (label)
4544
console.log(` [${label}](${c.prurl})`)
46-
} else {
45+
else
4746
console.log(` [#](${c.prurl})`)
48-
}
4947
}
50-
let msg = c.message
48+
const msg = c.message
5149
.replace(/^\s+/mg, '')
5250
.replace(/^[-a-z]+: /, '')
5351
.replace(/^/mg, ' ')
54-
.replace(/^ Reviewed-by: @.*/mg, '')
52+
.replace(/^ {2}Reviewed-by: @.*/mg, '')
5553
.replace(/\n$/, '')
5654
// backtickify package@version
5755
.replace(/^(\s*@?[^@\s]+@\d+[.]\d+[.]\d+)\b(\s*\S)/g, '$1:$2')
@@ -60,14 +58,13 @@ function printCommit (c) {
6058
.replace(/\b([a-f0-9]{7,8})\b/g, '[`$1`](https://github.com/npm/cli/commit/$1)')
6159
console.log(msg)
6260
// don't assign credit for dep updates
63-
if (!/^ `[^`]+@\d+\.\d+\.\d+[^`]*`:?$/m.test(msg)) {
61+
if (!/^ {2}`[^`]+@\d+\.\d+\.\d+[^`]*`:?$/m.test(msg)) {
6462
if (c.credit) {
6563
c.credit.forEach(function (credit) {
6664
console.log(` ([@${credit}](https://github.com/${credit}))`)
6765
})
68-
} else {
66+
} else
6967
console.log(` ([@${c.author}](https://github.com/${c.author}))`)
70-
}
7168
}
7269
}
7370

@@ -77,9 +74,9 @@ function main () {
7774
line = line.replace(/\r/g, '')
7875
let m
7976
/* eslint no-cond-assign:0 */
80-
if (/^---$/.test(line)) {
77+
if (/^---$/.test(line))
8178
printCommit(commit)
82-
} else if (m = line.match(/^([a-f0-9]{7,10}) ([a-f0-9]+) (?:[(]([^)]+)[)] )?(.*?) [(](.*?)[)]/)) {
79+
else if (m = line.match(/^([a-f0-9]{7,10}) ([a-f0-9]+) (?:[(]([^)]+)[)] )?(.*?) [(](.*?)[)]/)) {
8380
commit = {
8481
shortid: m[1],
8582
fullid: m[2],
@@ -88,23 +85,23 @@ function main () {
8885
author: m[5],
8986
prurl: null,
9087
fixes: [],
91-
credit: null
88+
credit: null,
9289
}
93-
} else if (m = line.match(/^PR-URL: (.*)/)) {
90+
} else if (m = line.match(/^PR-URL: (.*)/))
9491
commit.prurl = m[1]
95-
} else if (m = line.match(/^Credit: @(.*)/)) {
96-
if (!commit.credit) commit.credit = []
92+
else if (m = line.match(/^Credit: @(.*)/)) {
93+
if (!commit.credit)
94+
commit.credit = []
9795
commit.credit.push(m[1])
98-
} else if (m = line.match(/^(?:Fix(?:es)|Closes?): #?([0-9]+)/)) {
96+
} else if (m = line.match(/^(?:Fix(?:es)|Closes?): #?([0-9]+)/))
9997
commit.fixes.push(`https://github.com/npm/cli/issues/${m[1]}`)
100-
} else if (m = line.match(/^(?:Fix(?:es)|Closes?): ([^#]+)#([0-9]*)/)) {
98+
else if (m = line.match(/^(?:Fix(?:es)|Closes?): ([^#]+)#([0-9]*)/))
10199
commit.fixes.push(`https://github.com/${m[1]}/issues/${m[2]}`)
102-
} else if (m = line.match(/^(?:Fix(?:es)|Closes?): (https?:\/\/.*)/)) {
100+
else if (m = line.match(/^(?:Fix(?:es)|Closes?): (https?:\/\/.*)/))
103101
commit.fixes.push(m[1])
104-
} else if (m = line.match(/^Reviewed-By: @(.*)/)) {
102+
else if (m = line.match(/^Reviewed-By: @(.*)/))
105103
commit.reviewed = m[1]
106-
} else if (/\S/.test(line)) {
104+
else if (/\S/.test(line))
107105
commit.message += `\n${line}`
108-
}
109106
})
110107
}

scripts/config-doc-command.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { definitions } = require('../lib/utils/config/index.js')
22
const { writeFileSync, readFileSync } = require('fs')
3-
const { resolve, basename, relative } = require('path')
3+
const { resolve } = require('path')
44

55
const configDoc = process.argv[2]
66
const commandFile = process.argv[3]

scripts/config-doc.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ const addShorthands = doc => {
3939
shorta.localeCompare(shortb, 'en')
4040
})
4141
.map(([short, expansion]) => {
42-
const dash = short.length === 1 ? '-' : '--'
43-
return `* \`${dash}${short}\`: \`${expansion.join(' ')}\``
44-
}).join('\n')
42+
const dash = short.length === 1 ? '-' : '--'
43+
return `* \`${dash}${short}\`: \`${expansion.join(' ')}\``
44+
}).join('\n')
4545
return addBetweenTags(doc, startTag, endTag, body)
4646
}
4747

scripts/docs-build.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ var src = args[0]
88
var dest = args[1] || src
99

1010
fs.readFile(src, 'utf8', function (err, data) {
11-
if (err) return console.log(err)
11+
if (err)
12+
return console.log(err)
1213

1314
function frontmatter (match, p1) {
1415
const fm = { }
1516

1617
p1.split(/\r?\n/).forEach((kv) => {
17-
let result = kv.match(/^([^\s:]+):\s*(.*)/)
18-
if (result) {
18+
const result = kv.match(/^([^\s:]+):\s*(.*)/)
19+
if (result)
1920
fm[result[1]] = result[2]
20-
}
2121
})
2222

23-
return `# ${fm['title']}(${fm['section']}) - ${fm['description']}`
23+
return `# ${fm.title}(${fm.section}) - ${fm.description}`
2424
}
2525

2626
function replacer (match, p1) {
@@ -35,6 +35,7 @@ fs.readFile(src, 'utf8', function (err, data) {
3535
.trim()
3636

3737
fs.writeFile(dest, marked(result), 'utf8', function (err) {
38-
if (err) return console.log(err)
38+
if (err)
39+
return console.log(err)
3940
})
4041
})

scripts/update-dist-tags.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ function parseOTP (args) {
7979
}
8080
case 1: {
8181
// --otp=123456 or --otp123456
82-
if (otp) {
82+
if (otp)
8383
return otp
84-
}
84+
8585
console.error('Invalid otp value supplied. [CASE 1]')
8686
process.exit(1)
8787
}
8888
case 2: {
8989
// --otp 123456
9090
// INFO: validating the second argument is an otp code
9191
const isValidOtp = PARSE_OTP_VALUE.test(args[1])
92-
if (isValidOtp) {
92+
if (isValidOtp)
9393
return args[1]
94-
}
94+
9595
console.error('Invalid otp value supplied. [CASE 2]')
9696
process.exit(1)
9797
}

smoke-tests/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ t.cleanSnapshot = s => s.split(cwd).join('{CWD}')
1212
.split(process.cwd()).join('{CWD}')
1313
.replace(/\\+/g, '/')
1414
.replace(/\r\n/g, '\n')
15-
.replace(/\ \(in a browser\)/g, '')
16-
.replace(/^npm@.*\ /mg, 'npm ')
15+
.replace(/ \(in a browser\)/g, '')
16+
.replace(/^npm@.* /mg, 'npm ')
1717

1818
// setup server
1919
const { start, stop, registry } = require('./server.js')

0 commit comments

Comments
 (0)