From 163f021115b7d724759ab7bdd878aabc2b5a94dd Mon Sep 17 00:00:00 2001 From: Gar Date: Thu, 11 Aug 2022 11:28:25 -0700 Subject: [PATCH] fix: linting (#48) --- lib/link-gently.js | 2 ++ lib/shim-bin.js | 5 ++-- test/fix-bin.js | 72 +++++++++++++++++++++------------------------ test/link-gently.js | 9 +++--- 4 files changed, 43 insertions(+), 45 deletions(-) diff --git a/lib/link-gently.js b/lib/link-gently.js index 671ce38a586e7..d9ef25e7c5b0b 100644 --- a/lib/link-gently.js +++ b/lib/link-gently.js @@ -64,6 +64,8 @@ const linkGently = async ({ path, to, from, absFrom, force }) => { if (target.indexOf(path) === 0 || force) { return rm(to).then(() => CLOBBER) } + // neither skip nor clobber + return false }) } else { // doesn't exist, dir might not either diff --git a/lib/shim-bin.js b/lib/shim-bin.js index 70259a49e5b0c..bde328e510c53 100644 --- a/lib/shim-bin.js +++ b/lib/shim-bin.js @@ -56,12 +56,12 @@ const shimBin = ({ path, to, from, absFrom, force }) => { } if (force) { - return + return false } return Promise.all(shims.map((s, i) => [s, stats[i]]).map(([s, st]) => { if (!st) { - return + return false } return readCmdShim(s) .then(target => { @@ -69,6 +69,7 @@ const shimBin = ({ path, to, from, absFrom, force }) => { if (target.indexOf(resolve(path)) !== 0) { return failEEXIST({ from, to, path }) } + return false }, er => handleReadCmdShimError({ er, from, to })) })) }) diff --git a/test/fix-bin.js b/test/fix-bin.js index 63e7886e2d232..14b98987ffe59 100644 --- a/test/fix-bin.js +++ b/test/fix-bin.js @@ -5,31 +5,29 @@ const umask = process.umask() const fs = require('fs') const { readFileSync, statSync, chmodSync } = fs -t.test('fix windows hashbang', t => { +t.test('fix windows hashbang', async t => { const dir = t.testdir({ whb: `#!/usr/bin/env node\r\nconsole.log('hello')\r\n`, }) chmodSync(`${dir}/whb`, 0o644) - return fixBin(`${dir}/whb`).then(() => { - t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms') - t.equal(readFileSync(`${dir}/whb`, 'utf8'), - `#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line') - }) + await fixBin(`${dir}/whb`) + t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms') + t.equal(readFileSync(`${dir}/whb`, 'utf8'), + `#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line') }) -t.test('dont fix non-windows hashbang file', t => { +t.test('dont fix non-windows hashbang file', async t => { const dir = t.testdir({ goodhb: `#!/usr/bin/env node\nconsole.log('hello')\r\n`, }) chmodSync(`${dir}/goodhb`, 0o644) - return fixBin(`${dir}/goodhb`).then(() => { - t.equal((statSync(`${dir}/goodhb`).mode & 0o777), 0o777 & (~umask), 'has exec perms') - t.equal(readFileSync(`${dir}/goodhb`, 'utf8'), - `#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line') - }) + await fixBin(`${dir}/goodhb`) + t.equal((statSync(`${dir}/goodhb`).mode & 0o777), 0o777 & (~umask), 'has exec perms') + t.equal(readFileSync(`${dir}/goodhb`, 'utf8'), + `#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line') }) -t.test('failure to read means not a windows hash bang file', t => { +t.test('failure to read means not a windows hash bang file', async t => { const fsMock = { ...fs, read: (a, b, c, d, e, cb) => { @@ -45,15 +43,14 @@ t.test('failure to read means not a windows hash bang file', t => { whb: `#!/usr/bin/env node\r\nconsole.log('hello')\r\n`, }) chmodSync(`${dir}/whb`, 0o644) - return mockedFixBin(`${dir}/whb`).then(() => { - t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms') - t.equal(readFileSync(`${dir}/whb`, 'utf8'), - /* eslint-disable-next-line max-len */ - `#!/usr/bin/env node\r\nconsole.log('hello')\r\n`, 'did not fix \\r on hashbang line (failed read)') - }) + await mockedFixBin(`${dir}/whb`) + t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms') + t.equal(readFileSync(`${dir}/whb`, 'utf8'), + /* eslint-disable-next-line max-len */ + `#!/usr/bin/env node\r\nconsole.log('hello')\r\n`, 'did not fix \\r on hashbang line (failed read)') }) -t.test('failure to close is ignored', t => { +t.test('failure to close is ignored', async t => { const fsMock = { ...fs, close: (fd, cb) => { @@ -69,34 +66,33 @@ t.test('failure to close is ignored', t => { whb: `#!/usr/bin/env node\r\nconsole.log('hello')\r\n`, }) chmodSync(`${dir}/whb`, 0o644) - return mockedFixBin(`${dir}/whb`).then(() => { - t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms') - t.equal(readFileSync(`${dir}/whb`, 'utf8'), - /* eslint-disable-next-line max-len */ - `#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line (ignored failed close)') - }) + await mockedFixBin(`${dir}/whb`) + t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms') + t.equal( + readFileSync(`${dir}/whb`, 'utf8'), + `#!/usr/bin/env node\nconsole.log('hello')\r\n`, + 'fixed \\r on hashbang line (ignored failed close)' + ) }) -t.test('custom exec mode', t => { +t.test('custom exec mode', async t => { const dir = t.testdir({ goodhb: `#!/usr/bin/env node\nconsole.log('hello')\r\n`, }) chmodSync(`${dir}/goodhb`, 0o644) - return fixBin(`${dir}/goodhb`, 0o755).then(() => { - t.equal((statSync(`${dir}/goodhb`).mode & 0o755), 0o755 & (~umask), 'has exec perms') - t.equal(readFileSync(`${dir}/goodhb`, 'utf8'), - `#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line') - }) + await fixBin(`${dir}/goodhb`, 0o755) + t.equal((statSync(`${dir}/goodhb`).mode & 0o755), 0o755 & (~umask), 'has exec perms') + t.equal(readFileSync(`${dir}/goodhb`, 'utf8'), + `#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line') }) -t.test('custom exec mode in windows', t => { +t.test('custom exec mode in windows', async t => { const dir = t.testdir({ goodhb: `#!/usr/bin/env node\r\nconsole.log('hello')\r\n`, }) chmodSync(`${dir}/goodhb`, 0o644) - return fixBin(`${dir}/goodhb`, 0o755).then(() => { - t.equal((statSync(`${dir}/goodhb`).mode & 0o755), 0o755 & (~umask), 'has exec perms') - t.equal(readFileSync(`${dir}/goodhb`, 'utf8'), - `#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line') - }) + await fixBin(`${dir}/goodhb`, 0o755) + t.equal((statSync(`${dir}/goodhb`).mode & 0o755), 0o755 & (~umask), 'has exec perms') + t.equal(readFileSync(`${dir}/goodhb`, 'utf8'), + `#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line') }) diff --git a/test/link-gently.js b/test/link-gently.js index 0223799eac3f0..32dc7741e7c86 100644 --- a/test/link-gently.js +++ b/test/link-gently.js @@ -109,7 +109,7 @@ t.test('racey race', async t => { existingLink: t.fixture('symlink', './pkg/hello.js'), existingFile: 'hello', }) - return Promise.all([ + await Promise.all([ mockedLinkGently({ path: `${dir}/pkg`, from: `./pkg/hello.js`, @@ -125,8 +125,7 @@ t.test('racey race', async t => { force: true, }), new Promise((res) => fs.symlink(__filename, `${dir}/racecar`, 'file', res)), - ]).then(() => { - const target = fs.readlinkSync(`${dir}/racecar`) - t.match(target, /^\.\/(other)?pkg\/hello\.js$/, 'should link to one of them') - }) + ]) + const target = fs.readlinkSync(`${dir}/racecar`) + t.match(target, /^\.\/(other)?pkg\/hello\.js$/, 'should link to one of them') })