diff --git a/bin/nyc.js b/bin/nyc.js
index e6a9be883..4b6154db3 100755
--- a/bin/nyc.js
+++ b/bin/nyc.js
@@ -5,7 +5,7 @@ const configUtil = require('../lib/config-util')
const { cliWrapper, suppressEPIPE } = require('../lib/commands/helpers')
const foreground = require('foreground-child')
const resolveFrom = require('resolve-from')
-const NYC = require('../index.js')
+const NYC = require('..')
// parse configuration and command-line arguments;
// we keep these values in a few different forms,
@@ -32,7 +32,7 @@ async function main () {
if (!argv.instrument) argv.instrumenter = './lib/instrumenters/noop'
else argv.instrumenter = './lib/instrumenters/istanbul'
- var nyc = (new NYC(argv))
+ const nyc = (new NYC(argv))
if (argv.clean) {
await nyc.reset()
} else {
diff --git a/index.js b/index.js
index 6d74d0831..107287bb0 100755
--- a/index.js
+++ b/index.js
@@ -36,7 +36,7 @@ if (/self-coverage/.test(__dirname)) {
}
function coverageFinder () {
- var coverage = global.__coverage__
+ let coverage = global.__coverage__
if (typeof __coverage__ === 'object') coverage = __coverage__
if (!coverage) coverage = global.__coverage__ = {}
return coverage
@@ -90,9 +90,10 @@ class NYC {
this.hookRunInThisContext = config.hookRunInThisContext
this.fakeRequire = null
- this.processInfo = new ProcessInfo(Object.assign({}, config._processInfo, {
+ this.processInfo = new ProcessInfo({
+ ...config._processInfo,
directory: path.resolve(this.tempDirectory(), 'processinfo')
- }))
+ })
this.hashCache = {}
}
@@ -101,7 +102,7 @@ class NYC {
const opts = {
salt: Hash.salt(this.config),
hashData: (input, metadata) => [metadata.filename],
- filenamePrefix: metadata => path.parse(metadata.filename).name + '-',
+ filenamePrefix: metadata => `${path.parse(metadata.filename).name}-`,
onHash: (input, metadata, hash) => {
this.hashCache[metadata.filename] = hash
},
@@ -109,7 +110,7 @@ class NYC {
// when running --all we should not load source-file from
// cache, we want to instead return the fake source.
disableCache: this._disableCachingTransform(),
- ext: ext
+ ext
}
if (this._eagerInstantiation) {
opts.transform = this._transformFactory(this.cacheDirectory)
@@ -157,13 +158,13 @@ class NYC {
}
_readTranspiledSource (filePath) {
- var source = null
- var ext = path.extname(filePath)
+ let source = null
+ let ext = path.extname(filePath)
if (typeof Module._extensions[ext] === 'undefined') {
ext = '.js'
}
Module._extensions[ext]({
- _compile: function (content, filename) {
+ _compile (content) {
source = content
}
}, filePath)
@@ -194,7 +195,7 @@ class NYC {
}
async instrumentAllFiles (input, output) {
- let inputDir = '.' + path.sep
+ let inputDir = `.${path.sep}`
const visitor = async relFile => {
const inFile = path.resolve(inputDir, relFile)
const inCode = await fs.readFile(inFile, 'utf-8')
@@ -270,12 +271,12 @@ class NYC {
}
}
- _transformFactory (cacheDir) {
+ _transformFactory () {
const instrumenter = this.instrumenter()
let instrumented
return (code, metadata, hash) => {
- const filename = metadata.filename
+ const { filename } = metadata
const sourceMap = {}
if (this._sourceMap) {
@@ -287,10 +288,10 @@ class NYC {
try {
instrumented = instrumenter.instrumentSync(code, filename, sourceMap)
- } catch (e) {
- debugLog('failed to instrument ' + filename + ' with error: ' + e.stack)
+ } catch (error) {
+ debugLog(`failed to instrument ${filename} with error: ${error.stack}`)
if (this.config.exitOnError) {
- console.error('Failed to instrument ' + filename)
+ console.error(`Failed to instrument ${filename}`)
process.exit(1)
} else {
instrumented = code
@@ -299,9 +300,8 @@ class NYC {
if (this.fakeRequire) {
return 'function x () {}'
- } else {
- return instrumented
}
+ return instrumented
}
}
@@ -314,7 +314,7 @@ class NYC {
_addHook (type) {
const handleJs = this._handleJs.bind(this)
const dummyMatcher = () => true // we do all processing in transformer
- libHook['hook' + type](dummyMatcher, handleJs, { extensions: this.extensions })
+ libHook[`hook${type}`](dummyMatcher, handleJs, { extensions: this.extensions })
}
_addRequireHooks () {
@@ -360,7 +360,7 @@ class NYC {
)
}
- wrap (bin) {
+ wrap () {
process.env.NYC_PROCESS_ID = this.processInfo.uuid
// This is a bug with the spawn-wrap method where
// we cannot force propagation of NYC_PROCESS_ID.
@@ -375,7 +375,7 @@ class NYC {
}
writeCoverageFile () {
- var coverage = coverageFinder()
+ const coverage = coverageFinder()
// Remove any files that should be excluded but snuck into the coverage
Object.keys(coverage).forEach(function (absFile) {
@@ -392,8 +392,8 @@ class NYC {
}, this)
}
- var id = this.processInfo.uuid
- var coverageFilename = path.resolve(this.tempDirectory(), id + '.json')
+ const id = this.processInfo.uuid
+ const coverageFilename = path.resolve(this.tempDirectory(), `${id}.json`)
fs.writeFileSync(
coverageFilename,
@@ -476,14 +476,14 @@ class NYC {
}
_checkCoverage (summary, thresholds, file) {
- Object.keys(thresholds).forEach(function (key) {
- var coverage = summary[key].pct
+ Object.keys(thresholds).forEach(key => {
+ const coverage = summary[key].pct
if (coverage < thresholds[key]) {
process.exitCode = 1
if (file) {
- console.error('ERROR: Coverage for ' + key + ' (' + coverage + '%) does not meet threshold (' + thresholds[key] + '%) for ' + file)
+ console.error(`ERROR: Coverage for ${key} (${coverage}%) does not meet threshold (${thresholds[key]}%) for ${file}`)
} else {
- console.error('ERROR: Coverage for ' + key + ' (' + coverage + '%) does not meet global threshold (' + thresholds[key] + '%)')
+ console.error(`ERROR: Coverage for ${key} (${coverage}%) does not meet global threshold (${thresholds[key]}%)`)
}
}
})
diff --git a/lib/commands/check-coverage.js b/lib/commands/check-coverage.js
index cc361d16e..2db439344 100644
--- a/lib/commands/check-coverage.js
+++ b/lib/commands/check-coverage.js
@@ -1,13 +1,13 @@
'use strict'
-const NYC = require('../../index.js')
+const NYC = require('../..')
const { cliWrapper, suppressEPIPE, setupOptions } = require('./helpers.js')
exports.command = 'check-coverage'
exports.describe = 'check whether coverage is within thresholds provided'
-exports.builder = function (yargs) {
+exports.builder = (yargs) => {
yargs
.demandCommand(0, 0)
.example('$0 check-coverage --lines 95', "check whether the JSON in nyc's output folder meets the thresholds provided")
diff --git a/lib/commands/instrument.js b/lib/commands/instrument.js
index cabb43775..e8d3c9a29 100644
--- a/lib/commands/instrument.js
+++ b/lib/commands/instrument.js
@@ -1,6 +1,6 @@
'use strict'
-const NYC = require('../../index.js')
+const NYC = require('../..')
const path = require('path')
const { promisify } = require('util')
const resolveFrom = require('resolve-from')
@@ -11,7 +11,7 @@ exports.command = 'instrument [output]'
exports.describe = 'instruments a file or a directory tree and writes the instrumented code to the desired output location'
-exports.builder = function (yargs) {
+exports.builder = (yargs) => {
yargs
.demandCommand(0, 0)
.example('$0 instrument ./lib ./output', 'instrument all .js files in ./lib with coverage and output in ./output')
diff --git a/lib/commands/merge.js b/lib/commands/merge.js
index 0aefd11ec..4a361d44f 100644
--- a/lib/commands/merge.js
+++ b/lib/commands/merge.js
@@ -4,13 +4,13 @@ const makeDir = require('make-dir')
const fs = require('../fs-promises')
const { cliWrapper, setupOptions } = require('./helpers.js')
-const NYC = require('../../index.js')
+const NYC = require('../..')
exports.command = 'merge [output-file]'
exports.describe = 'merge istanbul format coverage output in a given folder'
-exports.builder = function (yargs) {
+exports.builder = (yargs) => {
yargs
.demandCommand(0, 0)
.example('$0 merge ./out coverage.json', 'merge together reports in ./out and output as coverage.json')
diff --git a/lib/commands/report.js b/lib/commands/report.js
index 6efb44166..6cb65870b 100644
--- a/lib/commands/report.js
+++ b/lib/commands/report.js
@@ -1,13 +1,13 @@
'use strict'
-const NYC = require('../../index.js')
+const NYC = require('../..')
const { cliWrapper, suppressEPIPE, setupOptions } = require('./helpers.js')
exports.command = 'report'
exports.describe = 'run coverage report for .nyc_output'
-exports.builder = function (yargs) {
+exports.builder = (yargs) => {
yargs
.demandCommand(0, 0)
.example('$0 report --reporter=lcov', 'output an HTML lcov report to ./coverage')
@@ -17,7 +17,7 @@ exports.builder = function (yargs) {
exports.handler = cliWrapper(async argv => {
process.env.NYC_CWD = process.cwd()
- var nyc = new NYC(argv)
+ const nyc = new NYC(argv)
await nyc.report().catch(suppressEPIPE)
if (argv.checkCoverage) {
await nyc.checkCoverage({
diff --git a/lib/instrumenters/istanbul.js b/lib/instrumenters/istanbul.js
index 299f9bfea..3bec3146b 100644
--- a/lib/instrumenters/istanbul.js
+++ b/lib/instrumenters/istanbul.js
@@ -18,7 +18,7 @@ function InstrumenterIstanbul (options) {
return {
instrumentSync (code, filename, { sourceMap, registerMap }) {
- var instrumented = instrumenter.instrumentSync(code, filename, sourceMap)
+ let instrumented = instrumenter.instrumentSync(code, filename, sourceMap)
if (instrumented !== code) {
registerMap()
}
@@ -26,10 +26,10 @@ function InstrumenterIstanbul (options) {
// the instrumenter can optionally produce source maps,
// this is useful for features like remapping stack-traces.
if (options.produceSourceMap) {
- var lastSourceMap = instrumenter.lastSourceMap()
+ const lastSourceMap = instrumenter.lastSourceMap()
/* istanbul ignore else */
if (lastSourceMap) {
- instrumented += '\n' + convertSourceMap.fromObject(lastSourceMap).toComment()
+ instrumented += `\n${convertSourceMap.fromObject(lastSourceMap).toComment()}`
}
}
diff --git a/lib/instrumenters/noop.js b/lib/instrumenters/noop.js
index b0c9f70f9..3d6313bbc 100644
--- a/lib/instrumenters/noop.js
+++ b/lib/instrumenters/noop.js
@@ -4,7 +4,7 @@ function NOOP () {
const { readInitialCoverage } = require('istanbul-lib-instrument')
return {
- instrumentSync (code, filename) {
+ instrumentSync (code) {
const extracted = readInitialCoverage(code)
if (extracted) {
this.fileCoverage = extracted.coverageData
diff --git a/lib/process-args.js b/lib/process-args.js
index 60f5e5e5c..09f172f85 100644
--- a/lib/process-args.js
+++ b/lib/process-args.js
@@ -11,8 +11,8 @@ const commands = [
module.exports = {
// don't pass arguments that are meant
// for nyc to the bin being instrumented.
- hideInstrumenterArgs: function (yargv) {
- var argv = process.argv.slice(1)
+ hideInstrumenterArgs (yargv) {
+ let argv = process.argv.slice(1)
argv = argv.slice(argv.indexOf(yargv._[0]))
if (argv[0][0] === '-') {
argv.unshift(process.execPath)
@@ -21,12 +21,12 @@ module.exports = {
},
// don't pass arguments for the bin being
// instrumented to nyc.
- hideInstrumenteeArgs: function () {
- var argv = process.argv.slice(2)
- var yargv = Parser(argv)
+ hideInstrumenteeArgs () {
+ let argv = process.argv.slice(2)
+ const yargv = Parser(argv)
if (!yargv._.length) return argv
- for (var i = 0, command; (command = yargv._[i]) !== undefined; i++) {
- if (~commands.indexOf(command)) return argv
+ for (let i = 0, command; (command = yargv._[i]) !== undefined; i++) {
+ if (commands.includes(command)) return argv
}
// drop all the arguments after the bin being
diff --git a/lib/register-env.js b/lib/register-env.js
index a91ec5c27..088d78dbe 100644
--- a/lib/register-env.js
+++ b/lib/register-env.js
@@ -22,6 +22,6 @@ for (const env of copyAtLoad) {
}
}
-module.exports = function updateVariable (envName) {
+module.exports = (envName) => {
envToCopy[envName] = process.env[envName]
}
diff --git a/lib/source-maps.js b/lib/source-maps.js
index 8a3914cdf..a0c933f3f 100644
--- a/lib/source-maps.js
+++ b/lib/source-maps.js
@@ -66,7 +66,7 @@ class SourceMaps {
try {
const mapPath = this.cachedPath(absFile, hash)
this.loadedMaps[hash] = JSON.parse(await fs.readFile(mapPath, 'utf8'))
- } catch (e) {
+ } catch (error) {
// set to false to avoid repeatedly trying to load the map
this.loadedMaps[hash] = false
}
diff --git a/lib/wrap.js b/lib/wrap.js
index cf30637f4..5829d2035 100644
--- a/lib/wrap.js
+++ b/lib/wrap.js
@@ -1,6 +1,6 @@
'use strict'
-const NYC = require('../index.js')
+const NYC = require('..')
const config = JSON.parse(
process.env.NYC_CONFIG ||
@@ -25,4 +25,4 @@ if (process.env.NYC_CONFIG_OVERRIDE) {
process.env.NYC_CONFIG = JSON.stringify(config)
}
-;(new NYC(config)).wrap()
+(new NYC(config)).wrap()
diff --git a/self-coverage-helper.js b/self-coverage-helper.js
index 2ef7e82e1..6e7cafe7a 100644
--- a/self-coverage-helper.js
+++ b/self-coverage-helper.js
@@ -15,7 +15,7 @@ module.exports = {
const selfCoverageDir = path.join(__dirname, '.self_coverage')
mkdirp.sync(selfCoverageDir)
fs.writeFileSync(
- path.join(selfCoverageDir, process.pid + '.json'),
+ path.join(selfCoverageDir, `${process.pid}.json`),
JSON.stringify(coverage),
'utf-8'
)
diff --git a/test/add-all-files.js b/test/add-all-files.js
index 636947300..ae9fe2ffb 100644
--- a/test/add-all-files.js
+++ b/test/add-all-files.js
@@ -78,7 +78,7 @@ t.test('transpiles .js files added via addAllFiles', async t => {
await fs.unlink(needsTranspilePath)
})
-t.test('does not attempt to transpile files when they are excluded', async t => {
+t.test('does not attempt to transpile files when they are excluded', async () => {
const notNeedTranspilePath = path.join(fixtures, './do-not-need-transpile.do-not-transpile')
await fs.writeFile(
notNeedTranspilePath,
diff --git a/test/config-override.js b/test/config-override.js
index b7263ea11..212d5783b 100644
--- a/test/config-override.js
+++ b/test/config-override.js
@@ -10,6 +10,7 @@ t.test('spawn that does config overriding', t => testSuccess(t, {
args: [
'--exclude-after-remap=false',
'--include=conf-override-root.js',
- process.execPath, 'conf-override-root.js'
+ process.execPath,
+ 'conf-override-root.js'
]
}))
diff --git a/test/helpers/reset-state.js b/test/helpers/reset-state.js
index f11c5e8ec..639914d48 100644
--- a/test/helpers/reset-state.js
+++ b/test/helpers/reset-state.js
@@ -8,14 +8,14 @@ const extensions = Object.assign({}, require.extensions) // eslint-disable-line
const glob = promisify(require('glob'))
const rimraf = promisify(require('rimraf'))
-module.exports = async function () {
+module.exports = async () => {
// nuke any temporary files created during test runs.
const files = await glob('test/**/*/{.nyc_output,.cache}')
await Promise.all(files.map(f => rimraf(f)))
// reset Node's require cache.
Object.keys(require.cache).forEach((key) => {
- if (key.indexOf('node_modules') === -1) delete require.cache[key]
+ if (!key.includes('node_modules')) delete require.cache[key]
})
// reset any custom loaders for extensions, disabling the stack maintained
diff --git a/test/helpers/run-nyc.js b/test/helpers/run-nyc.js
index ca0adcecf..34f27595e 100644
--- a/test/helpers/run-nyc.js
+++ b/test/helpers/run-nyc.js
@@ -34,7 +34,7 @@ function sanitizeString (str, cwd, leavePathSep) {
async function runNYC ({ args, tempDir, leavePathSep, cwd = fixturesCLI, env = {} }) {
const runArgs = [nycBin].concat(tempDir ? ['--temp-dir', tempDir] : [], args)
const { status, stderr, stdout } = await spawn(process.execPath, runArgs, {
- cwd: cwd,
+ cwd,
env: {
...envPath,
...env
diff --git a/test/helpers/temp-dir-setup.js b/test/helpers/temp-dir-setup.js
index df61807e1..7d416f915 100644
--- a/test/helpers/temp-dir-setup.js
+++ b/test/helpers/temp-dir-setup.js
@@ -11,14 +11,14 @@ const mkdtemp = promisify(fs.mkdtemp)
function tempDirSetup (t, testFile) {
const { dir, name } = path.parse(testFile)
- const tempDirBase = path.resolve(dir, 'temp-dir-' + name)
+ const tempDirBase = path.resolve(dir, `temp-dir-${name}`)
makeDir.sync(tempDirBase)
// Do not use arrow function for beforeEach
// or afterEach, they need this from tap.
t.beforeEach(async function () {
- this.tempDir = await mkdtemp(tempDirBase + '/')
+ this.tempDir = await mkdtemp(`${tempDirBase}/`)
})
t.afterEach(function () {
diff --git a/test/issue-190.js b/test/issue-190.js
index 9e844e6af..ae88c12c1 100644
--- a/test/issue-190.js
+++ b/test/issue-190.js
@@ -13,14 +13,14 @@ const fakebin = path.resolve(fixturesCLI, 'fakebin')
const spawnOptions = {
cwd: path.resolve(fixturesCLI, 'run-npm-test-recursive'),
env: {
- PATH: fakebin + ':' + process.env.PATH
+ PATH: `${fakebin}:${process.env.PATH}`
}
}
async function writeFakeNPM (shebang) {
const targetPath = path.resolve(fakebin, 'npm')
const source = await fs.readFile(path.resolve(fakebin, 'npm-template.js'))
- await fs.writeFile(targetPath, '#!' + shebang + '\n' + source)
+ await fs.writeFile(targetPath, `#!${shebang}\n${source}`)
await fs.chmod(targetPath, 493) // 0o755
}
diff --git a/test/processinfo.js b/test/processinfo.js
index 30290234e..ca66ffc24 100644
--- a/test/processinfo.js
+++ b/test/processinfo.js
@@ -17,11 +17,15 @@ rimraf.sync(resolve(fixturesCLI, tmp))
t.teardown(() => rimraf(resolve(fixturesCLI, tmp)))
t.test('build some processinfo', t => {
- var args = [
- bin, '-t', tmp,
- node, 'selfspawn-fibonacci.js', '5'
+ const args = [
+ bin,
+ '-t',
+ tmp,
+ node,
+ 'selfspawn-fibonacci.js',
+ '5'
]
- var proc = spawn(process.execPath, args, {
+ const proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
env: {
PATH: process.env.PATH,
diff --git a/test/wrap.js b/test/wrap.js
index 2d28c2a2b..bf7d88718 100644
--- a/test/wrap.js
+++ b/test/wrap.js
@@ -28,8 +28,8 @@ t.test('wraps modules with coverage counters when they are required', async t =>
t.test('wraps modules with coverage counters when the custom require hook compiles them', async t => {
let required = false
- const hook = function (module, filename) {
- if (filename.indexOf('check-instrumented.js') !== -1) {
+ const hook = (module, filename) => {
+ if (filename.includes('check-instrumented.js')) {
required = true
}
module._compile(fs.readFileSync(filename, 'utf8'), filename)