From 37554a5ad77d9373b180c1c7905adcfeea4e7a74 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 22 Feb 2019 15:49:12 -0800 Subject: [PATCH] [Refactor] improve eslint settings --- .eslintrc | 20 ++++++++++++++++++-- bin.js | 12 ++++++------ getLockfile.js | 2 +- getProjectTempDir.js | 8 ++++---- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/.eslintrc b/.eslintrc index bb612a0..e5cd589 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,18 +9,34 @@ }, "rules": { "consistent-return": 1, - "dot-notation": [2, { "allowKeywords": true }], "func-name-matching": 0, "max-nested-callbacks": 0, "max-params": [2, 4], - "no-console": 0, "sort-keys": 0, + + "comma-dangle": [2, { + "arrays": "always-multiline", + "objects": "always-multiline", + "imports": "always-multiline", + "exports": "always-multiline", + "functions": "never", + }], + "dot-notation": [2, { "allowKeywords": true }], + "no-console": 0, + "object-shorthand": [2, "always"], + "prefer-const": 2, + "quote-props": [2, "as-needed", { + "keywords": false, + "numbers": true, + "unnecessary": true, + }], }, "overrides": [ { "files": "test*", "rules": { "max-nested-callbacks": 0, + "max-params": 0, }, }, ], diff --git a/bin.js b/bin.js index 022cead..cdaa458 100755 --- a/bin.js +++ b/bin.js @@ -17,33 +17,33 @@ const { argv: { output, date, - 'package': pkg - } + package: pkg, + }, } = require('yargs') .help() .option('date', { type: 'string', describe: '“now”, or a date (same format as `new Date()`)', demandOption: true, - coerce: function (arg) { + coerce(arg) { if (arg !== 'now' && !new Date(arg).getTime()) { throw new TypeError('`date` must be “now” or a valid format for `new Date`'); } return arg; - } + }, }) .option('package', { type: 'string', describe: 'path to a `package.json` file', normalize: true, - coerce: function (arg) { return path.resolve(arg); } + coerce(arg) { return path.resolve(arg); }, }) .default('package', filename, path.relative(process.cwd(), filename)) .option('output', { alias: 'o', describe: 'output file path', normalize: true, - demandOption: true + demandOption: true, }); getLockfile(pkg, date === 'now' ? undefined : date, { logger: console.log.bind(console), npmNeeded: '^6.9.0-0' }) diff --git a/getLockfile.js b/getLockfile.js index 6ce06e7..193ff65 100644 --- a/getLockfile.js +++ b/getLockfile.js @@ -24,7 +24,7 @@ module.exports = function getLockfile(packageFile, date, { npmNeeded, logger = ( logger(chalk.blue(`Creating \`package.json\` in temp dir for ${date || '“now”'} lockfile`)); return Promise.all([ copyFile(packageFile, path.join(tmpDir, 'package.json')), - copyFile(npmRC, path.join(tmpDir, '.npmrc')) + copyFile(npmRC, path.join(tmpDir, '.npmrc')), ]); }); return Promise.all([tmpDirP, copyPkg]).then(([tmpDir]) => new Promise((resolve, reject) => { diff --git a/getProjectTempDir.js b/getProjectTempDir.js index f10a4b4..c49209e 100644 --- a/getProjectTempDir.js +++ b/getProjectTempDir.js @@ -30,15 +30,15 @@ const getRootTempDir = function getRootTempDir(npmNeeded, logger = () => {}) { cleanupHandlers.push(cleanup); nodeCleanup(finalCleanup); })).then(tmpDir => { - var npmV = execSync('npm --version', { encoding: 'utf-8', cwd: tmpDir }); + const npmV = execSync('npm --version', { encoding: 'utf-8', cwd: tmpDir }); logger(`${chalk.blue('Checking npm version:')} \`npm --version\` -> v${npmV}`); if (!semver.satisfies(npmV, npmNeeded)) { const pkgContents = { - 'private': true, + private: true, name: 'npm-jail', dependencies: { - npm: npmNeeded - } + npm: npmNeeded, + }, }; return writeFile( path.join(tmpDir, 'package.json'),