Skip to content

Commit 20c82ab

Browse files
authored
Run stricter linter to cleanup problems and force ES6 usage (#566)
Also shorten fs.write() promise code
1 parent a631c53 commit 20c82ab

28 files changed

Lines changed: 98 additions & 129 deletions

lib/copy-sync/copy-sync.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ function checkDest (dest) {
191191
// return true if dest is a subdir of src, otherwise false.
192192
// extract dest base dir and check if that is the same as src basename.
193193
function isSrcSubdir (src, dest) {
194-
let srcArray = path.resolve(src).split(path.sep)
195-
let destArray = path.resolve(dest).split(path.sep)
194+
const srcArray = path.resolve(src).split(path.sep)
195+
const destArray = path.resolve(dest).split(path.sep)
196196

197197
return srcArray.reduce((acc, current, i) => {
198198
return acc && destArray[i] === current

lib/copy-sync/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
module.exports = {
24
copySync: require('./copy-sync')
35
}

lib/copy/__tests__/ncp/broken-symlink.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const assert = require('assert')
99

1010
/* global afterEach, beforeEach, describe, it */
1111

12-
describe('ncp broken symlink', function () {
12+
describe('ncp broken symlink', () => {
1313
const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'ncp-broken-symlinks')
1414
const src = path.join(TEST_DIR, 'src')
1515
const out = path.join(TEST_DIR, 'out')

lib/copy/__tests__/ncp/ncp.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('ncp', () => {
4141
it('files are copied correctly', cb => {
4242
readDirFiles(src, 'utf8', (srcErr, srcFiles) => {
4343
function filter (files) {
44-
for (let fileName in files) {
44+
for (const fileName in files) {
4545
const curFile = files[fileName]
4646
if (curFile instanceof Object) {
4747
return filter(curFile)
@@ -143,7 +143,7 @@ describe('ncp', () => {
143143
})
144144

145145
// see https://github.com/AvianFlu/ncp/issues/71
146-
describe('Issue 71: Odd Async Behaviors', cb => {
146+
describe('Issue 71: Odd Async Behaviors', () => {
147147
const fixtures = path.join(__dirname, 'fixtures', 'regular-fixtures')
148148
const src = path.join(fixtures, 'src')
149149
const out = path.join(fixtures, 'out')

lib/copy/copy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ function checkDest (dest, cb) {
245245
// return true if dest is a subdir of src, otherwise false.
246246
// extract dest base dir and check if that is the same as src basename.
247247
function isSrcSubdir (src, dest) {
248-
let srcArray = path.resolve(src).split(path.sep)
249-
let destArray = path.resolve(dest).split(path.sep)
248+
const srcArray = path.resolve(src).split(path.sep)
249+
const destArray = path.resolve(dest).split(path.sep)
250250

251251
return srcArray.reduce((acc, current, i) => {
252252
return acc && destArray[i] === current

lib/copy/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
const u = require('universalify').fromCallback
24
module.exports = {
35
copy: u(require('./copy'))

lib/ensure/__tests__/link.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('fse-ensure-link', () => {
8585
return done()
8686
}
8787
args.push(callback)
88-
return fn.apply(null, args)
88+
return fn(...args)
8989
})
9090
}
9191

@@ -103,7 +103,7 @@ describe('fse-ensure-link', () => {
103103
return done()
104104
}
105105
args.push(callback)
106-
return fn.apply(null, args)
106+
return fn(...args)
107107
})
108108
}
109109

@@ -120,7 +120,7 @@ describe('fse-ensure-link', () => {
120120
return done()
121121
}
122122
args.push(callback)
123-
return fn.apply(null, args)
123+
return fn(...args)
124124
})
125125
}
126126

@@ -129,7 +129,7 @@ describe('fse-ensure-link', () => {
129129
const dstpath = args[1]
130130

131131
it(`should create link file using src ${srcpath} and dst ${dstpath}`, () => {
132-
fn.apply(null, args)
132+
fn(...args)
133133
const srcContent = fs.readFileSync(srcpath, 'utf8')
134134
const dstDir = path.dirname(dstpath)
135135
const dstBasename = path.basename(dstpath)
@@ -151,7 +151,7 @@ describe('fse-ensure-link', () => {
151151
const dstdirExistsBefore = fs.existsSync(path.dirname(dstpath))
152152
let err = null
153153
try {
154-
fn.apply(null, args)
154+
fn(...args)
155155
} catch (e) {
156156
err = e
157157
}
@@ -167,7 +167,7 @@ describe('fse-ensure-link', () => {
167167

168168
it(`should do nothing using src ${srcpath} and dst ${dstpath}`, () => {
169169
const destinationContentBefore = fs.readFileSync(dstpath, 'utf8')
170-
fn.apply(null, args)
170+
fn(...args)
171171
const destinationContentAfter = fs.readFileSync(dstpath, 'utf8')
172172
assert.equal(destinationContentBefore, destinationContentAfter)
173173
})

lib/ensure/__tests__/symlink-paths.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('symlink-type', () => {
7171
done()
7272
}
7373
args.push(callback)
74-
return symlinkPaths.apply(null, args)
74+
return symlinkPaths(...args)
7575
})
7676
})
7777
})
@@ -81,7 +81,7 @@ describe('symlink-type', () => {
8181
const args = test[0].slice(0)
8282
const expectedRelativePaths = test[1]
8383
it(`should return '${JSON.stringify(expectedRelativePaths)}' when src '${args[0]}' and dst is '${args[1]}'`, () => {
84-
const relativePaths = symlinkPathsSync.apply(null, args)
84+
const relativePaths = symlinkPathsSync(...args)
8585
assert.deepEqual(relativePaths, expectedRelativePaths)
8686
})
8787
})

lib/ensure/__tests__/symlink-type.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('symlink-type', () => {
102102
done()
103103
}
104104
args.push(callback)
105-
return symlinkType.apply(null, args)
105+
return symlinkType(...args)
106106
})
107107
})
108108
})
@@ -112,7 +112,7 @@ describe('symlink-type', () => {
112112
const args = test[0]
113113
const expectedType = test[1]
114114
it(`should return '${expectedType}' when src '${args[0]}'`, () => {
115-
const type = symlinkTypeSync.apply(null, args)
115+
const type = symlinkTypeSync(...args)
116116
assert.equal(type, expectedType)
117117
})
118118
})

lib/ensure/__tests__/symlink.test.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe('fse-ensure-symlink', () => {
9797
return done()
9898
}
9999
args.push(callback)
100-
return fn.apply(null, args)
100+
return fn(...args)
101101
})
102102
}
103103

@@ -117,7 +117,7 @@ describe('fse-ensure-symlink', () => {
117117
return done()
118118
}
119119
args.push(callback)
120-
return fn.apply(null, args)
120+
return fn(...args)
121121
})
122122
}
123123

@@ -134,7 +134,7 @@ describe('fse-ensure-symlink', () => {
134134
return done()
135135
}
136136
args.push(callback)
137-
return fn.apply(null, args)
137+
return fn(...args)
138138
})
139139
}
140140

@@ -150,7 +150,7 @@ describe('fse-ensure-symlink', () => {
150150
return done()
151151
}
152152
args.push(callback)
153-
return fn.apply(null, args)
153+
return fn(...args)
154154
})
155155
}
156156

@@ -173,7 +173,7 @@ describe('fse-ensure-symlink', () => {
173173
return done()
174174
}
175175
args.push(callback)
176-
return fn.apply(null, args)
176+
return fn(...args)
177177
})
178178
}
179179

@@ -193,7 +193,7 @@ describe('fse-ensure-symlink', () => {
193193
return done()
194194
}
195195
args.push(callback)
196-
return fn.apply(null, args)
196+
return fn(...args)
197197
})
198198
}
199199

@@ -210,7 +210,7 @@ describe('fse-ensure-symlink', () => {
210210
return done()
211211
}
212212
args.push(callback)
213-
return fn.apply(null, args)
213+
return fn(...args)
214214
})
215215
}
216216

@@ -226,15 +226,15 @@ describe('fse-ensure-symlink', () => {
226226
return done()
227227
}
228228
args.push(callback)
229-
return fn.apply(null, args)
229+
return fn(...args)
230230
})
231231
}
232232

233233
function fileSuccessSync (args, fn) {
234234
const srcpath = args[0]
235235
const dstpath = args[1]
236236
it(`should create symlink file using src ${srcpath} and dst ${dstpath}`, () => {
237-
fn.apply(null, args)
237+
fn(...args)
238238
const relative = symlinkPathsSync(srcpath, dstpath)
239239
const srcContent = fs.readFileSync(relative.toCwd, 'utf8')
240240
const dstDir = path.dirname(dstpath)
@@ -252,7 +252,7 @@ describe('fse-ensure-symlink', () => {
252252
const srcpath = args[0]
253253
const dstpath = args[1]
254254
it(`should create broken symlink file using src ${srcpath} and dst ${dstpath}`, () => {
255-
fn.apply(null, args)
255+
fn(...args)
256256
const dstDir = path.dirname(dstpath)
257257
const dstBasename = path.basename(dstpath)
258258
const isSymlink = fs.lstatSync(dstpath).isSymbolicLink()
@@ -270,7 +270,7 @@ describe('fse-ensure-symlink', () => {
270270
const dstdirExistsBefore = fs.existsSync(path.dirname(dstpath))
271271
let err = null
272272
try {
273-
fn.apply(null, args)
273+
fn(...args)
274274
} catch (e) {
275275
err = e
276276
}
@@ -285,7 +285,7 @@ describe('fse-ensure-symlink', () => {
285285
const dstpath = args[1]
286286
it(`should do nothing using src ${srcpath} and dst ${dstpath}`, () => {
287287
const destinationContentBefore = fs.readFileSync(dstpath, 'utf8')
288-
fn.apply(null, args)
288+
fn(...args)
289289
const destinationContentAfter = fs.readFileSync(dstpath, 'utf8')
290290
assert.equal(destinationContentBefore, destinationContentAfter)
291291
})
@@ -295,7 +295,7 @@ describe('fse-ensure-symlink', () => {
295295
const srcpath = args[0]
296296
const dstpath = args[1]
297297
it(`should create symlink dir using src ${srcpath} and dst ${dstpath}`, () => {
298-
fn.apply(null, args)
298+
fn(...args)
299299
const relative = symlinkPathsSync(srcpath, dstpath)
300300
const srcContents = fs.readdirSync(relative.toCwd)
301301
const dstDir = path.dirname(dstpath)
@@ -313,7 +313,7 @@ describe('fse-ensure-symlink', () => {
313313
const srcpath = args[0]
314314
const dstpath = args[1]
315315
it(`should create broken symlink dir using src ${srcpath} and dst ${dstpath}`, () => {
316-
fn.apply(null, args)
316+
fn(...args)
317317
const dstDir = path.dirname(dstpath)
318318
const dstBasename = path.basename(dstpath)
319319
const isSymlink = fs.lstatSync(dstpath).isSymbolicLink()
@@ -331,7 +331,7 @@ describe('fse-ensure-symlink', () => {
331331
const dstdirExistsBefore = fs.existsSync(path.dirname(dstpath))
332332
let err = null
333333
try {
334-
fn.apply(null, args)
334+
fn(...args)
335335
} catch (e) {
336336
err = e
337337
}
@@ -346,7 +346,7 @@ describe('fse-ensure-symlink', () => {
346346
const dstpath = args[1]
347347
it(`should do nothing using src ${srcpath} and dst ${dstpath}`, () => {
348348
const destinationContentBefore = fs.readdirSync(dstpath)
349-
fn.apply(null, args)
349+
fn(...args)
350350
const destinationContentAfter = fs.readdirSync(dstpath)
351351
assert.deepEqual(destinationContentBefore, destinationContentAfter)
352352
})

0 commit comments

Comments
 (0)