Skip to content

Commit

Permalink
Add eslint for linting
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners committed May 17, 2021
1 parent b78575f commit d34f5fd
Show file tree
Hide file tree
Showing 31 changed files with 93 additions and 97 deletions.
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
extends: 'eslint:recommended',

env: {
node: true,
es2020: true
},

rules: {
'no-prototype-builtins': 'off',
'no-empty': 'off',
'no-regex-spaces': 'off',
'no-useless-escape': 'off'
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
!coverage-map.js
!postpublish.sh
!netlify.toml
!.eslintrc.js
2 changes: 1 addition & 1 deletion bin/jack.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const reporters = [...new Set([
...(require('tap-mocha-reporter').types),
...(require('treport/types')),
])]
const fs = require('fs')
// nyc bundles its deps, pull reporters out of it
const nycReporters = [
'clover',
Expand Down Expand Up @@ -692,6 +691,7 @@ Much more documentation available at: https://www.node-tap.org/
appended to the filenames.`,
}),

/* eslint-disable-next-line */
debug: flag({
envDefault: 'TAP_DEBUG',
description: 'Turn on debug mode',
Expand Down
7 changes: 3 additions & 4 deletions bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const isexe = require('isexe')
const yaml = require('tap-yaml')
const path = require('path')
const exists = require('fs-exists-cached').sync
const os = require('os')

const maybeResolve = id => {
try {
Expand Down Expand Up @@ -358,7 +357,7 @@ const runCoverageReportOnly = options => {
}

/* istanbul ignore next */
const pipeToCoveralls = async options => {
const pipeToCoveralls = async () => {
const reporter = spawn(node, [nycBin, 'report', '--reporter=text-lcov'], {
stdio: [ 0, 'pipe', 2 ]
})
Expand Down Expand Up @@ -398,7 +397,7 @@ const openHtmlCoverageReport = (options, code, signal) => {
}
}

const nycHelp = _ => fg(node, [nycBin, '--help'])
const nycHelp = () => fg(node, [nycBin, '--help'])

// export for easier testing
const setupTapEnv = exports.setupTapEnv = options => {
Expand Down Expand Up @@ -533,7 +532,7 @@ const saveFails = (options, tap) => {
} catch (er) {}
}

tap.on('bailout', reason => {
tap.on('bailout', () => {
// add any pending test files to the fails list.
fails.push.apply(fails, options.files.filter(file =>
successes.indexOf(file) === -1))
Expand Down
7 changes: 2 additions & 5 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
const t = require('./tap.js')
t.jobs = 1
const tapStack = [ t ]
let level = 0
const suiteStack = []

const describe = (name, fn, opt) =>
Expand Down Expand Up @@ -83,7 +82,6 @@ const it = (name, fn, options) => {
name = fn.name
options = options || {}
const todo = !fn
const suite = suiteStack[ suiteStack.length - 1 ]
const t = tapStack[ tapStack.length - 1 ]
if (!name)
name = ''
Expand Down Expand Up @@ -119,7 +117,6 @@ function moment (when, fn) {
t[when](function () {
if (!this.options.tapMochaTest)
return
const suite = suiteStack[ suiteStack.length - 1 ]

const [cb, p] = cbPromise()
const ret = fn.call(this, cb)
Expand All @@ -144,7 +141,7 @@ exports.beforeEach = beforeEach
exports.afterEach = afterEach

let saved
exports.global = _ => {
exports.global = () => {
if (!saved)
saved = new Map()

Expand All @@ -155,7 +152,7 @@ exports.global = _ => {
})
}

exports.deglobal = _ =>
exports.deglobal = () =>
Object.keys(exports).filter(g => g !== 'global').forEach(g => {
if (saved && saved.has(g))
global[g] = saved.get(g)
Expand Down
2 changes: 1 addition & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class Repl {
this.run(null, cb)
}

exit (cb) {
exit () {
this.watch.pause()
this.watch.kill('SIGTERM')
this.repl.close()
Expand Down
2 changes: 1 addition & 1 deletion lib/tap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
const {deprecate} = require('util')
const settings = require('../settings.js')
require('../settings.js')
const tap = require('libtap')

// Needs to be set before requiring mocha.js
Expand Down
9 changes: 4 additions & 5 deletions lib/watch.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const chokidar = require('chokidar')
const EE = require('events')
const Minipass = require('minipass')
const bin = require.resolve('../bin/run.js')
const {spawn} = require('child_process')
const onExit = require('signal-exit')
const {writeFileSync, readFileSync} = require('fs')
const fs = require('fs')
const {writeFileSync, readFileSync} = fs
const {stringify} = require('tap-yaml')
const {resolve} = require('path')

Expand Down Expand Up @@ -51,7 +51,6 @@ class Watch extends Minipass {
// Since a covered test was definitely included in its own
// test run, don't add it a second time, so we don't get
// two chokidar events for the same file change.
const cwd = process.cwd()
const fileSet = new Set(Object.keys(this.index.files))
Object.keys(this.index.externalIds)
.filter(f => !fileSet.has(resolve(f)))
Expand Down Expand Up @@ -103,7 +102,7 @@ class Watch extends Minipass {
this.run()
}

run (env) {
run () {
const set = [...new Set(this.queue)]
this.log('running tests', set)
writeFileSync(this.saveFile, set.join('\n') + '\n')
Expand Down Expand Up @@ -136,7 +135,7 @@ class Watch extends Minipass {
// then add those, but ignore if it's not there.
const leftover = (() => {
try {
return fs.readFileSync(saveFile, 'utf8').trim().split('\n')
return fs.readFileSync(this.saveFile, 'utf8').trim().split('\n')
} catch (er) {
return []
}
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"which": "^2.0.2"
},
"devDependencies": {
"eslint": "^7.25.0",
"flow-remove-types": "^2.112.0",
"node-preload": "^0.2.1",
"process-on-spawn": "^1.0.0",
Expand Down Expand Up @@ -84,6 +85,7 @@
"test": "node bin/run.js -M coverage-map.js",
"unit": "bash scripts/unit.sh",
"posttest": "rm -rf cli-tests-*",
"preunit": "npm run lint",
"postunit": "npm run posttest",
"t": "node bin/run.js -J -sfails.txt",
"preversion": "npm test",
Expand All @@ -92,7 +94,8 @@
"www:build": "cd docs; npm ci; npm run build",
"www:develop": "cd docs; npm run develop",
"start": "npm run www:develop",
"www:serve": "cd docs; npm run serve"
"www:serve": "cd docs; npm run serve",
"lint": "eslint 'bin/*.js' 'lib/*.js' 'test/**/*.js'"
},
"tap": {
"test-regex": "^test/.*\\.js$",
Expand Down Expand Up @@ -122,3 +125,4 @@
"url": "https://github.com/sponsors/isaacs"
}
}

2 changes: 1 addition & 1 deletion test/cb-promise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const t = require('../')
const cbPromise = require('../lib/cb-promise.js')
t.test('promise resolved when cb called', async t => {
t.test('promise resolved when cb called', async () => {
const [cb, p] = cbPromise()
cb()
return p
Expand Down
10 changes: 6 additions & 4 deletions test/mocha.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict'
/* global deglobal */

const {mocha} = require('../lib/tap.js')
const assert = require('assert')

Expand Down Expand Up @@ -61,14 +63,14 @@ mocha.describe('globals', () => {
})

if (process.version.match(/v[0-9]\./)) {
assert.throws(_ => mocha.after(),
assert.throws(() => mocha.after(),
'cannot call "after" outside of describe()')
assert.throws(_ => mocha.before(),
assert.throws(() => mocha.before(),
'cannot call "before" outside of describe()')
} else {
assert.throws(_ => mocha.after(),
assert.throws(() => mocha.after(),
new Error('cannot call "after" outside of describe()'))
assert.throws(_ => mocha.before(),
assert.throws(() => mocha.before(),
new Error('cannot call "before" outside of describe()'))
}

Expand Down
1 change: 0 additions & 1 deletion test/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ t.teardown(() => {
const {Repl} = require('../lib/repl.js')

const input = new Minipass({encoding: 'utf8'})
const {PassThrough} = require('stream')
const output = new Minipass({encoding: 'utf8'})
const repl = new Repl({}, input, output)

Expand Down
4 changes: 1 addition & 3 deletions test/run/bad-rcfile.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const {
tmpfile,
run,
tap,
dir,
t,
} = require('./')

const fs = require('fs')
t.test('bad rc file', t => {
fs.writeFileSync(`${dir}/.taprc`, 'this : is not : valid : yaml')
run(['--dump-config'], { cwd: dir }, (er, o, e) => {
run(['--dump-config'], { cwd: dir }, (er) => {
t.match(er, { code: 1 })
t.end()
})
Expand Down
25 changes: 11 additions & 14 deletions test/run/basic.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
const fs = require('fs')
const mkdirp = require('mkdirp')
const {
tmpfile,
run,
bin,
tap,
node,
dir,
t,
} = require('./')
Expand All @@ -14,7 +11,7 @@ if (process.env.TAP_SNAPSHOT !== '1')
t.jobs = require('os').cpus.length

t.test('no args', t => {
const c = run([], {
run([], {
cwd: dir,
}, (er, o, e) => {
t.match(er, { code: 1 })
Expand All @@ -34,47 +31,47 @@ t.test('stdin parsing', t => {
})

t.test('--help', t => {
run(['--help'], null, (er, o, e) => {
run(['--help'], null, (er, o) => {
t.equal(er, null)
t.match(o, /^Usage:/)
t.end()
})
})

t.test('--nyc-help', t => {
run(['--nyc-help'], null, (er, o, e) => {
run(['--nyc-help'], null, (er, o) => {
t.equal(er, null)
t.match(o, /\nOptions:\n/)
t.end()
})
})

t.test('--version', t => {
run(['--version'], null, (er, o, e) => {
run(['--version'], null, (er, o) => {
t.equal(er, null)
t.equal(o.trim(), require('../../package.json').version)
t.end()
})
})

t.test('--versions', t => {
run(['--versions'], null, (er, o, e) => {
run(['--versions'], null, (er, o) => {
t.equal(er, null)
t.matchSnapshot(o.replace(/^([^:]+): (.*)$/gm, '$1: {version}'), 'output')
t.end()
})
})

t.test('--parser-version', t => {
run(['--parser-version'], null, (er, o, e) => {
run(['--parser-version'], null, (er, o) => {
t.equal(er, null)
t.matchSnapshot(o, 'output')
t.end()
})
})

t.test('--nyc-version', t => {
run(['--nyc-version'], null, (er, o, e) => {
run(['--nyc-version'], null, (er, o) => {
t.equal(er, null)
t.equal(o.trim(), require('nyc/package.json').version)
t.end()
Expand All @@ -100,7 +97,7 @@ t.test('unknown short opt', t => {
t.test('basic test run', t => {
const ok = tmpfile(t, 'ok.js', `require(${tap}).pass('this is fine')`)
const args = ['-iSCbFt0', '-g/nope/i', '--', ok]
run(args, null, (err, stdout, stderr) => {
run(args, null, (err, stdout) => {
t.matchSnapshot(stdout, 'ok.js output')
t.end()
})
Expand All @@ -109,11 +106,11 @@ t.test('basic test run', t => {
t.test('ignored files', t => {
mkdirp.sync(`${dir}/ig/test/node_modules`)
mkdirp.sync(`${dir}/ig/node_modules`)
const ok = tmpfile(t, 'ig/test/ok.js',
tmpfile(t, 'ig/test/ok.js',
`require(${tap}).pass('this is fine')`)
const nope = tmpfile(t, 'ig/node_modules/nope.test.js',
tmpfile(t, 'ig/node_modules/nope.test.js',
`require(${tap}).fail('i should not be included')`)
const nope2 = tmpfile(t, 'ig/test/node_modules/nope.test.js',
tmpfile(t, 'ig/test/node_modules/nope.test.js',
`require(${tap}).fail('should also not be included')`)
tmpfile(t, 'ig/test/node_modules/foo.test.js',
`require(${tap}).fail('no foo included')`)
Expand Down
3 changes: 1 addition & 2 deletions test/run/cat.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const {
tmpfile,
run,
tap,
t,
} = require('./')

Expand All @@ -11,7 +10,7 @@ t.test('cat', t => {
1..1
ok 1 - this is fine
`)
run([ok], {}, (er, o, e) => {
run([ok], {}, (er, o) => {
t.equal(er, null)
t.matchSnapshot(o)
t.end()
Expand Down
2 changes: 0 additions & 2 deletions test/run/changed.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const cwd = process.cwd()
process.chdir(dir)
t.teardown(() => process.chdir(cwd))

const {resolve} = require('path')

const oktest = tmpfile(t, 'ok.test.js', `
const t = require(${tap})
t.match(require('./ok.js), { ok: true })
Expand Down

0 comments on commit d34f5fd

Please sign in to comment.