diff options
author | Gar <gar+gh@danger.computer> | 2021-06-04 17:11:41 +0300 |
---|---|---|
committer | Gar <gar+gh@danger.computer> | 2021-06-10 20:09:03 +0300 |
commit | f130a81d62bf4f540ab252a09ff5a618827f9265 (patch) | |
tree | ae41e2ddd68a09bf486c96375ee5c80e2d842934 /scripts | |
parent | 26d00c47785dfb300eab6a926f9d7c4d566776b1 (diff) |
fix(linting): add scripts, docs, smoke-tests
There is code in all of these places we control so it should be linted
PR-URL: https://github.com/npm/cli/pull/3367
Credit: @wraithgar
Close: #3367
Reviewed-by: @isaacs
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/bundle-and-gitignore-deps.js | 2 | ||||
-rw-r--r-- | scripts/changelog.js | 59 | ||||
-rw-r--r-- | scripts/config-doc-command.js | 2 | ||||
-rw-r--r-- | scripts/config-doc.js | 6 | ||||
-rw-r--r-- | scripts/docs-build.js | 13 | ||||
-rw-r--r-- | scripts/update-dist-tags.js | 8 |
6 files changed, 44 insertions, 46 deletions
diff --git a/scripts/bundle-and-gitignore-deps.js b/scripts/bundle-and-gitignore-deps.js index b15720c03..1c7f0eb36 100644 --- a/scripts/bundle-and-gitignore-deps.js +++ b/scripts/bundle-and-gitignore-deps.js @@ -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) diff --git a/scripts/changelog.js b/scripts/changelog.js index f36ad56c9..0951bd027 100644 --- a/scripts/changelog.js +++ b/scripts/changelog.js @@ -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') @@ -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}))`) - } } } @@ -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], @@ -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}` - } }) } diff --git a/scripts/config-doc-command.js b/scripts/config-doc-command.js index d7f734ed5..48bc02654 100644 --- a/scripts/config-doc-command.js +++ b/scripts/config-doc-command.js @@ -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] diff --git a/scripts/config-doc.js b/scripts/config-doc.js index 8d8294906..5014bcdc4 100644 --- a/scripts/config-doc.js +++ b/scripts/config-doc.js @@ -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) } diff --git a/scripts/docs-build.js b/scripts/docs-build.js index a1540ebb9..8e217d225 100644 --- a/scripts/docs-build.js +++ b/scripts/docs-build.js @@ -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) { @@ -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) }) }) diff --git a/scripts/update-dist-tags.js b/scripts/update-dist-tags.js index f28bfd0b9..371d0c03a 100644 --- a/scripts/update-dist-tags.js +++ b/scripts/update-dist-tags.js @@ -79,9 +79,9 @@ 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) } @@ -89,9 +89,9 @@ function parseOTP (args) { // --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) } |