Skip to content

Commit 163f021

Browse files
authored
fix: linting (npm#48)
1 parent df2d8e8 commit 163f021

4 files changed

Lines changed: 43 additions & 45 deletions

File tree

lib/link-gently.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ const linkGently = async ({ path, to, from, absFrom, force }) => {
6464
if (target.indexOf(path) === 0 || force) {
6565
return rm(to).then(() => CLOBBER)
6666
}
67+
// neither skip nor clobber
68+
return false
6769
})
6870
} else {
6971
// doesn't exist, dir might not either

lib/shim-bin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,20 @@ const shimBin = ({ path, to, from, absFrom, force }) => {
5656
}
5757

5858
if (force) {
59-
return
59+
return false
6060
}
6161

6262
return Promise.all(shims.map((s, i) => [s, stats[i]]).map(([s, st]) => {
6363
if (!st) {
64-
return
64+
return false
6565
}
6666
return readCmdShim(s)
6767
.then(target => {
6868
target = resolve(dirname(to), target)
6969
if (target.indexOf(resolve(path)) !== 0) {
7070
return failEEXIST({ from, to, path })
7171
}
72+
return false
7273
}, er => handleReadCmdShimError({ er, from, to }))
7374
}))
7475
})

test/fix-bin.js

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,29 @@ const umask = process.umask()
55
const fs = require('fs')
66
const { readFileSync, statSync, chmodSync } = fs
77

8-
t.test('fix windows hashbang', t => {
8+
t.test('fix windows hashbang', async t => {
99
const dir = t.testdir({
1010
whb: `#!/usr/bin/env node\r\nconsole.log('hello')\r\n`,
1111
})
1212
chmodSync(`${dir}/whb`, 0o644)
13-
return fixBin(`${dir}/whb`).then(() => {
14-
t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms')
15-
t.equal(readFileSync(`${dir}/whb`, 'utf8'),
16-
`#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line')
17-
})
13+
await fixBin(`${dir}/whb`)
14+
t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms')
15+
t.equal(readFileSync(`${dir}/whb`, 'utf8'),
16+
`#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line')
1817
})
1918

20-
t.test('dont fix non-windows hashbang file', t => {
19+
t.test('dont fix non-windows hashbang file', async t => {
2120
const dir = t.testdir({
2221
goodhb: `#!/usr/bin/env node\nconsole.log('hello')\r\n`,
2322
})
2423
chmodSync(`${dir}/goodhb`, 0o644)
25-
return fixBin(`${dir}/goodhb`).then(() => {
26-
t.equal((statSync(`${dir}/goodhb`).mode & 0o777), 0o777 & (~umask), 'has exec perms')
27-
t.equal(readFileSync(`${dir}/goodhb`, 'utf8'),
28-
`#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line')
29-
})
24+
await fixBin(`${dir}/goodhb`)
25+
t.equal((statSync(`${dir}/goodhb`).mode & 0o777), 0o777 & (~umask), 'has exec perms')
26+
t.equal(readFileSync(`${dir}/goodhb`, 'utf8'),
27+
`#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line')
3028
})
3129

32-
t.test('failure to read means not a windows hash bang file', t => {
30+
t.test('failure to read means not a windows hash bang file', async t => {
3331
const fsMock = {
3432
...fs,
3533
read: (a, b, c, d, e, cb) => {
@@ -45,15 +43,14 @@ t.test('failure to read means not a windows hash bang file', t => {
4543
whb: `#!/usr/bin/env node\r\nconsole.log('hello')\r\n`,
4644
})
4745
chmodSync(`${dir}/whb`, 0o644)
48-
return mockedFixBin(`${dir}/whb`).then(() => {
49-
t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms')
50-
t.equal(readFileSync(`${dir}/whb`, 'utf8'),
51-
/* eslint-disable-next-line max-len */
52-
`#!/usr/bin/env node\r\nconsole.log('hello')\r\n`, 'did not fix \\r on hashbang line (failed read)')
53-
})
46+
await mockedFixBin(`${dir}/whb`)
47+
t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms')
48+
t.equal(readFileSync(`${dir}/whb`, 'utf8'),
49+
/* eslint-disable-next-line max-len */
50+
`#!/usr/bin/env node\r\nconsole.log('hello')\r\n`, 'did not fix \\r on hashbang line (failed read)')
5451
})
5552

56-
t.test('failure to close is ignored', t => {
53+
t.test('failure to close is ignored', async t => {
5754
const fsMock = {
5855
...fs,
5956
close: (fd, cb) => {
@@ -69,34 +66,33 @@ t.test('failure to close is ignored', t => {
6966
whb: `#!/usr/bin/env node\r\nconsole.log('hello')\r\n`,
7067
})
7168
chmodSync(`${dir}/whb`, 0o644)
72-
return mockedFixBin(`${dir}/whb`).then(() => {
73-
t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms')
74-
t.equal(readFileSync(`${dir}/whb`, 'utf8'),
75-
/* eslint-disable-next-line max-len */
76-
`#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line (ignored failed close)')
77-
})
69+
await mockedFixBin(`${dir}/whb`)
70+
t.equal((statSync(`${dir}/whb`).mode & 0o777), 0o777 & (~umask), 'has exec perms')
71+
t.equal(
72+
readFileSync(`${dir}/whb`, 'utf8'),
73+
`#!/usr/bin/env node\nconsole.log('hello')\r\n`,
74+
'fixed \\r on hashbang line (ignored failed close)'
75+
)
7876
})
7977

80-
t.test('custom exec mode', t => {
78+
t.test('custom exec mode', async t => {
8179
const dir = t.testdir({
8280
goodhb: `#!/usr/bin/env node\nconsole.log('hello')\r\n`,
8381
})
8482
chmodSync(`${dir}/goodhb`, 0o644)
85-
return fixBin(`${dir}/goodhb`, 0o755).then(() => {
86-
t.equal((statSync(`${dir}/goodhb`).mode & 0o755), 0o755 & (~umask), 'has exec perms')
87-
t.equal(readFileSync(`${dir}/goodhb`, 'utf8'),
88-
`#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line')
89-
})
83+
await fixBin(`${dir}/goodhb`, 0o755)
84+
t.equal((statSync(`${dir}/goodhb`).mode & 0o755), 0o755 & (~umask), 'has exec perms')
85+
t.equal(readFileSync(`${dir}/goodhb`, 'utf8'),
86+
`#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line')
9087
})
9188

92-
t.test('custom exec mode in windows', t => {
89+
t.test('custom exec mode in windows', async t => {
9390
const dir = t.testdir({
9491
goodhb: `#!/usr/bin/env node\r\nconsole.log('hello')\r\n`,
9592
})
9693
chmodSync(`${dir}/goodhb`, 0o644)
97-
return fixBin(`${dir}/goodhb`, 0o755).then(() => {
98-
t.equal((statSync(`${dir}/goodhb`).mode & 0o755), 0o755 & (~umask), 'has exec perms')
99-
t.equal(readFileSync(`${dir}/goodhb`, 'utf8'),
100-
`#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line')
101-
})
94+
await fixBin(`${dir}/goodhb`, 0o755)
95+
t.equal((statSync(`${dir}/goodhb`).mode & 0o755), 0o755 & (~umask), 'has exec perms')
96+
t.equal(readFileSync(`${dir}/goodhb`, 'utf8'),
97+
`#!/usr/bin/env node\nconsole.log('hello')\r\n`, 'fixed \\r on hashbang line')
10298
})

test/link-gently.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ t.test('racey race', async t => {
109109
existingLink: t.fixture('symlink', './pkg/hello.js'),
110110
existingFile: 'hello',
111111
})
112-
return Promise.all([
112+
await Promise.all([
113113
mockedLinkGently({
114114
path: `${dir}/pkg`,
115115
from: `./pkg/hello.js`,
@@ -125,8 +125,7 @@ t.test('racey race', async t => {
125125
force: true,
126126
}),
127127
new Promise((res) => fs.symlink(__filename, `${dir}/racecar`, 'file', res)),
128-
]).then(() => {
129-
const target = fs.readlinkSync(`${dir}/racecar`)
130-
t.match(target, /^\.\/(other)?pkg\/hello\.js$/, 'should link to one of them')
131-
})
128+
])
129+
const target = fs.readlinkSync(`${dir}/racecar`)
130+
t.match(target, /^\.\/(other)?pkg\/hello\.js$/, 'should link to one of them')
132131
})

0 commit comments

Comments
 (0)