diff options
author | Gar <gar+gh@danger.computer> | 2021-11-04 20:21:00 +0300 |
---|---|---|
committer | Gar <gar+gh@danger.computer> | 2021-11-05 00:45:18 +0300 |
commit | 225645420cf3d13bc0b0d591f7f7bf21a9c24e47 (patch) | |
tree | 107797bef3206793cda93d7dad97f3ab54ef3cd8 /scripts | |
parent | de45f90eebbf51205748ed3f09fbeab6cc000b3e (diff) |
chore: update to latest eslint and linting rules
This brings us in line with the rest of the linting rules we are wanting
to use on the npm cli repos.
There were several hundred over-length lines and instead of editing them
all by hand I piped the failing file through `prettier` and back through
`eslint` just to save some time and energy. This means there may be
some quirks in the linting those files have, but we can fix those if we
see them and they bother us.
Other than that there were about 50 lines that are legitimately
over-length, all are now explicitly overridden. Many are tests that
could be snapshots.
PR-URL: https://github.com/npm/cli/pull/3995
Credit: @wraithgar
Close: #3995
Reviewed-by: @lukekarrys
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/changelog.js | 58 | ||||
-rw-r--r-- | scripts/config-doc-command.js | 9 | ||||
-rw-r--r-- | scripts/config-doc.js | 6 | ||||
-rw-r--r-- | scripts/docs-build.js | 9 | ||||
-rw-r--r-- | scripts/git-dirty.js | 5 | ||||
-rw-r--r-- | scripts/update-dist-tags.js | 16 |
6 files changed, 64 insertions, 39 deletions
diff --git a/scripts/changelog.js b/scripts/changelog.js index 0951bd027..ef5497d7d 100644 --- a/scripts/changelog.js +++ b/scripts/changelog.js @@ -13,21 +13,26 @@ the result to the changelog. */ const execSync = require('child_process').execSync const branch = process.argv[2] || 'origin/latest' -const log = execSync(`git log --reverse --pretty='format:%h %H%d %s (%aN)%n%b%n---%n' ${branch}...`).toString().split(/\n/) +const log = execSync(`git log --reverse --pretty='format:%h %H%d %s (%aN)%n%b%n---%n' ${branch}...`) + .toString() + .split(/\n/) main() function shortname (url) { - const matched = url.match(/https:\/\/github\.com\/([^/]+\/[^/]+)\/(?:pull|issues)\/(\d+)/) || - url.match(/https:\/\/(npm\.community)\/t\/(?:[^/]+\/)(\d+)/) - if (!matched) + const matched = + url.match(/https:\/\/github\.com\/([^/]+\/[^/]+)\/(?:pull|issues)\/(\d+)/) || + url.match(/https:\/\/(npm\.community)\/t\/(?:[^/]+\/)(\d+)/) + if (!matched) { return false + } const repo = matched[1] const id = matched[2] - if (repo !== 'npm/cli') + if (repo !== 'npm/cli') { return `${repo}#${id}` - else + } else { return `#${id}` + } } function printCommit (c) { @@ -35,21 +40,23 @@ function printCommit (c) { if (c.fixes.length) { for (const fix of c.fixes) { const label = shortname(fix) - if (label) + if (label) { console.log(` [${label}](${fix})`) + } } } else if (c.prurl) { const label = shortname(c.prurl) - if (label) + if (label) { console.log(` [${label}](${c.prurl})`) - else + } else { console.log(` [#](${c.prurl})`) + } } const msg = c.message - .replace(/^\s+/mg, '') + .replace(/^\s+/gm, '') .replace(/^[-a-z]+: /, '') - .replace(/^/mg, ' ') - .replace(/^ {2}Reviewed-by: @.*/mg, '') + .replace(/^/gm, ' ') + .replace(/^ {2}Reviewed-by: @.*/gm, '') .replace(/\n$/, '') // backtickify package@version .replace(/^(\s*@?[^@\s]+@\d+[.]\d+[.]\d+)\b(\s*\S)/g, '$1:$2') @@ -63,8 +70,9 @@ function printCommit (c) { c.credit.forEach(function (credit) { console.log(` ([@${credit}](https://github.com/${credit}))`) }) - } else + } else { console.log(` ([@${c.author}](https://github.com/${c.author}))`) + } } } @@ -74,9 +82,11 @@ 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], @@ -87,21 +97,23 @@ function main () { fixes: [], 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) + } 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 085ac958d..9db026f30 100644 --- a/scripts/config-doc-command.js +++ b/scripts/config-doc-command.js @@ -16,12 +16,14 @@ const describeAll = () => const addBetweenTags = (doc, startTag, endTag, body) => { const startSplit = doc.split(startTag) - if (startSplit.length !== 2) + if (startSplit.length !== 2) { throw new Error('Did not find exactly one start tag') + } const endSplit = startSplit[1].split(endTag) - if (endSplit.length !== 2) + if (endSplit.length !== 2) { throw new Error('Did not find exactly one end tag') + } return [ startSplit[0], @@ -47,6 +49,7 @@ const addDescriptions = doc => { const doc = readFileSync(configDoc, 'utf8') const hasTag = doc.includes('<!-- AUTOGENERATED CONFIG DESCRIPTIONS START -->') const newDoc = params && hasTag ? addDescriptions(doc) : doc -if (params && !hasTag) +if (params && !hasTag) { console.error('WARNING: did not find config description section', configDoc) +} writeFileSync(configDoc, newDoc) diff --git a/scripts/config-doc.js b/scripts/config-doc.js index 03e8fbc2d..b14baa381 100644 --- a/scripts/config-doc.js +++ b/scripts/config-doc.js @@ -5,12 +5,14 @@ const configDoc = resolve(__dirname, '../docs/content/using-npm/config.md') const addBetweenTags = (doc, startTag, endTag, body) => { const startSplit = doc.split(startTag) - if (startSplit.length !== 2) + if (startSplit.length !== 2) { throw new Error('Did not find exactly one start tag') + } const endSplit = startSplit[1].split(endTag) - if (endSplit.length !== 2) + if (endSplit.length !== 2) { throw new Error('Did not find exactly one end tag') + } return [ startSplit[0], diff --git a/scripts/docs-build.js b/scripts/docs-build.js index 8e217d225..63658c79b 100644 --- a/scripts/docs-build.js +++ b/scripts/docs-build.js @@ -8,16 +8,18 @@ var src = args[0] var dest = args[1] || src fs.readFile(src, 'utf8', function (err, data) { - if (err) + if (err) { return console.log(err) + } function frontmatter (match, p1) { const fm = { } p1.split(/\r?\n/).forEach((kv) => { const result = kv.match(/^([^\s:]+):\s*(.*)/) - if (result) + if (result) { fm[result[1]] = result[2] + } }) return `# ${fm.title}(${fm.section}) - ${fm.description}` @@ -35,7 +37,8 @@ fs.readFile(src, 'utf8', function (err, data) { .trim() fs.writeFile(dest, marked(result), 'utf8', function (err) { - if (err) + if (err) { return console.log(err) + } }) }) diff --git a/scripts/git-dirty.js b/scripts/git-dirty.js index 4199768de..484a4d23e 100644 --- a/scripts/git-dirty.js +++ b/scripts/git-dirty.js @@ -10,7 +10,8 @@ if (status || signal) { console.error({ status, signal }) process.exitCode = status || 1 } -if (stdout.trim() !== '') +if (stdout.trim() !== '') { throw new Error('git dirty') -else +} else { console.log('git clean') +} diff --git a/scripts/update-dist-tags.js b/scripts/update-dist-tags.js index 371d0c03a..825823ce5 100644 --- a/scripts/update-dist-tags.js +++ b/scripts/update-dist-tags.js @@ -20,8 +20,8 @@ const { execSync } = require('child_process') const semver = require('semver') const path = require('path') -const getMajorVersion = (input) => semver.parse(input).major -const getMinorVersion = (input) => semver.parse(input).minor +const getMajorVersion = input => semver.parse(input).major +const getMinorVersion = input => semver.parse(input).minor // INFO: String templates to generate the tags to update const LATEST_TAG = (strings, major) => `latest-${major}` @@ -51,7 +51,7 @@ function main () { const removeTag = REMOVE_TAG`${major}${minor}` const updateList = [].concat(TAG_LIST, latestTag, nextTag) - updateList.forEach((tag) => { + updateList.forEach(tag => { setDistTag(tag, version, otp) }) removeDistTag(removeTag, version, otp) @@ -79,8 +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,8 +90,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) @@ -104,7 +106,9 @@ function parseOTP (args) { function setDistTag (tag, version, otp) { try { - const result = execSync(`npm dist-tag set npm@${version} ${tag} --otp=${otp}`, { encoding: 'utf-8' }) + const result = execSync(`npm dist-tag set npm@${version} ${tag} --otp=${otp}`, { + encoding: 'utf-8', + }) console.log('Result:', result) } catch (err) { console.error('Bad dist-tag command.') |