Skip to content

Commit

Permalink
fix(linting): add scripts, docs, smoke-tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wraithgar committed Jun 4, 2021
1 parent efaf6f6 commit a49b8d7
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 318 deletions.
525 changes: 256 additions & 269 deletions docs/dockhand.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
"sudotest:nocleanup": "sudo NO_TEST_CLEANUP=1 npm run test --",
"posttest": "npm run lint",
"eslint": "eslint",
"lint": "npm run eslint -- test/lib test/bin lib",
"lint": "npm run eslint -- test/lib test/bin lib scripts docs smoke-tests",
"lintfix": "npm run lint -- --fix",
"prelint": "rimraf test/npm_cache*",
"resetdeps": "bash scripts/resetdeps.sh",
Expand Down
2 changes: 1 addition & 1 deletion scripts/bundle-and-gitignore-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const arb = new Arborist({ path: resolve(__dirname, '..') })
const shouldIgnore = []

arb.loadVirtual().then(tree => {
for (const [name, node] of tree.children.entries()) {
for (const node of tree.children.values()) {
if (node.dev || node.isLink) {
console.error('ignore', node.name)
shouldIgnore.push(node.name)
Expand Down
59 changes: 28 additions & 31 deletions scripts/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,38 @@ const log = execSync(`git log --reverse --pretty='format:%h %H%d %s (%aN)%n%b%n-
main()

function shortname (url) {
let matched = url.match(/https:\/\/github\.com\/([^/]+\/[^/]+)\/(?:pull|issues)\/(\d+)/) ||
const matched = url.match(/https:\/\/github\.com\/([^/]+\/[^/]+)\/(?:pull|issues)\/(\d+)/) ||
url.match(/https:\/\/(npm\.community)\/t\/(?:[^/]+\/)(\d+)/)
if (!matched) return false
let repo = matched[1]
let id = matched[2]
if (repo !== 'npm/cli') {
if (!matched)
return false
const repo = matched[1]
const id = matched[2]
if (repo !== 'npm/cli')
return `${repo}#${id}`
} else {
else
return `#${id}`
}
}

function printCommit (c) {
console.log(`* [\`${c.shortid}\`](https://github.com/npm/cli/commit/${c.fullid})`)
if (c.fixes.length) {
for (const fix of c.fixes) {
let label = shortname(fix)
if (label) {
const label = shortname(fix)
if (label)
console.log(` [${label}](${fix})`)
}
}
} else if (c.prurl) {
let label = shortname(c.prurl)
if (label) {
const label = shortname(c.prurl)
if (label)
console.log(` [${label}](${c.prurl})`)
} else {
else
console.log(` [#](${c.prurl})`)
}
}
let msg = c.message
const msg = c.message
.replace(/^\s+/mg, '')
.replace(/^[-a-z]+: /, '')
.replace(/^/mg, ' ')
.replace(/^ Reviewed-by: @.*/mg, '')
.replace(/^ {2}Reviewed-by: @.*/mg, '')
.replace(/\n$/, '')
// backtickify package@version
.replace(/^(\s*@?[^@\s]+@\d+[.]\d+[.]\d+)\b(\s*\S)/g, '$1:$2')
Expand All @@ -60,14 +58,13 @@ function printCommit (c) {
.replace(/\b([a-f0-9]{7,8})\b/g, '[`$1`](https://github.com/npm/cli/commit/$1)')
console.log(msg)
// don't assign credit for dep updates
if (!/^ `[^`]+@\d+\.\d+\.\d+[^`]*`:?$/m.test(msg)) {
if (!/^ {2}`[^`]+@\d+\.\d+\.\d+[^`]*`:?$/m.test(msg)) {
if (c.credit) {
c.credit.forEach(function (credit) {
console.log(` ([@${credit}](https://github.com/${credit}))`)
})
} else {
} else
console.log(` ([@${c.author}](https://github.com/${c.author}))`)
}
}
}

Expand All @@ -77,9 +74,9 @@ function main () {
line = line.replace(/\r/g, '')
let m
/* eslint no-cond-assign:0 */
if (/^---$/.test(line)) {
if (/^---$/.test(line))
printCommit(commit)
} else if (m = line.match(/^([a-f0-9]{7,10}) ([a-f0-9]+) (?:[(]([^)]+)[)] )?(.*?) [(](.*?)[)]/)) {
else if (m = line.match(/^([a-f0-9]{7,10}) ([a-f0-9]+) (?:[(]([^)]+)[)] )?(.*?) [(](.*?)[)]/)) {
commit = {
shortid: m[1],
fullid: m[2],
Expand All @@ -88,23 +85,23 @@ function main () {
author: m[5],
prurl: null,
fixes: [],
credit: null
credit: null,
}
} else if (m = line.match(/^PR-URL: (.*)/)) {
} else if (m = line.match(/^PR-URL: (.*)/))
commit.prurl = m[1]
} else if (m = line.match(/^Credit: @(.*)/)) {
if (!commit.credit) commit.credit = []
else if (m = line.match(/^Credit: @(.*)/)) {
if (!commit.credit)
commit.credit = []
commit.credit.push(m[1])
} else if (m = line.match(/^(?:Fix(?:es)|Closes?): #?([0-9]+)/)) {
} else if (m = line.match(/^(?:Fix(?:es)|Closes?): #?([0-9]+)/))
commit.fixes.push(`https://github.com/npm/cli/issues/${m[1]}`)
} else if (m = line.match(/^(?:Fix(?:es)|Closes?): ([^#]+)#([0-9]*)/)) {
else if (m = line.match(/^(?:Fix(?:es)|Closes?): ([^#]+)#([0-9]*)/))
commit.fixes.push(`https://github.com/${m[1]}/issues/${m[2]}`)
} else if (m = line.match(/^(?:Fix(?:es)|Closes?): (https?:\/\/.*)/)) {
else if (m = line.match(/^(?:Fix(?:es)|Closes?): (https?:\/\/.*)/))
commit.fixes.push(m[1])
} else if (m = line.match(/^Reviewed-By: @(.*)/)) {
else if (m = line.match(/^Reviewed-By: @(.*)/))
commit.reviewed = m[1]
} else if (/\S/.test(line)) {
else if (/\S/.test(line))
commit.message += `\n${line}`
}
})
}
2 changes: 1 addition & 1 deletion scripts/config-doc-command.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { definitions } = require('../lib/utils/config/index.js')
const { writeFileSync, readFileSync } = require('fs')
const { resolve, basename, relative } = require('path')
const { resolve } = require('path')

const configDoc = process.argv[2]
const commandFile = process.argv[3]
Expand Down
6 changes: 3 additions & 3 deletions scripts/config-doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ const addShorthands = doc => {
shorta.localeCompare(shortb, 'en')
})
.map(([short, expansion]) => {
const dash = short.length === 1 ? '-' : '--'
return `* \`${dash}${short}\`: \`${expansion.join(' ')}\``
}).join('\n')
const dash = short.length === 1 ? '-' : '--'
return `* \`${dash}${short}\`: \`${expansion.join(' ')}\``
}).join('\n')
return addBetweenTags(doc, startTag, endTag, body)
}

Expand Down
13 changes: 7 additions & 6 deletions scripts/docs-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ var src = args[0]
var dest = args[1] || src

fs.readFile(src, 'utf8', function (err, data) {
if (err) return console.log(err)
if (err)
return console.log(err)

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

p1.split(/\r?\n/).forEach((kv) => {
let result = kv.match(/^([^\s:]+):\s*(.*)/)
if (result) {
const result = kv.match(/^([^\s:]+):\s*(.*)/)
if (result)
fm[result[1]] = result[2]
}
})

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

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

fs.writeFile(dest, marked(result), 'utf8', function (err) {
if (err) return console.log(err)
if (err)
return console.log(err)
})
})
8 changes: 4 additions & 4 deletions scripts/update-dist-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ function parseOTP (args) {
}
case 1: {
// --otp=123456 or --otp123456
if (otp) {
if (otp)
return otp
}

console.error('Invalid otp value supplied. [CASE 1]')
process.exit(1)
}
case 2: {
// --otp 123456
// INFO: validating the second argument is an otp code
const isValidOtp = PARSE_OTP_VALUE.test(args[1])
if (isValidOtp) {
if (isValidOtp)
return args[1]
}

console.error('Invalid otp value supplied. [CASE 2]')
process.exit(1)
}
Expand Down
4 changes: 2 additions & 2 deletions smoke-tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ t.cleanSnapshot = s => s.split(cwd).join('{CWD}')
.split(process.cwd()).join('{CWD}')
.replace(/\\+/g, '/')
.replace(/\r\n/g, '\n')
.replace(/\ \(in a browser\)/g, '')
.replace(/^npm@.*\ /mg, 'npm ')
.replace(/ \(in a browser\)/g, '')
.replace(/^npm@.* /mg, 'npm ')

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

0 comments on commit a49b8d7

Please sign in to comment.