Skip to content

Commit

Permalink
Add eslint for linting
Browse files Browse the repository at this point in the history
PR-URL: #748
Credit: @jsumners
Close: #748
Reviewed-by: @isaacs

EDIT(@isaacs): move lint to postsnap, and do --fix by default.  We
always have to run snapshots before pushing a new version, and expect to
get code changes as a result.  This is much more convenient than having
tests just not run becuase of some scaffolding or something.
  • Loading branch information
jsumners authored and isaacs committed Mar 5, 2022
1 parent 162c1a8 commit 3f1ae47
Show file tree
Hide file tree
Showing 32 changed files with 1,464 additions and 111 deletions.
15 changes: 15 additions & 0 deletions .eslintrc.js
@@ -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
Expand Up @@ -25,3 +25,4 @@
!coverage-map.js
!postpublish.sh
!netlify.toml
!.eslintrc.js
2 changes: 1 addition & 1 deletion bin/jack.js
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 @@ -693,6 +692,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
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 @@ -536,7 +535,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
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
Expand Up @@ -186,7 +186,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
@@ -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
@@ -1,12 +1,12 @@
const proc = typeof process === 'object' && process ? process : null

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 @@ -55,7 +55,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 = proc.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 @@ -107,7 +106,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 @@ -140,7 +139,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

0 comments on commit 3f1ae47

Please sign in to comment.