Skip to content

Commit 3f1ae47

Browse files
jsumnersisaacs
authored andcommitted
Add eslint for linting
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.
1 parent 162c1a8 commit 3f1ae47

32 files changed

+1464
-111
lines changed

.eslintrc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
extends: 'eslint:recommended',
3+
4+
env: {
5+
node: true,
6+
es2020: true
7+
},
8+
9+
rules: {
10+
'no-prototype-builtins': 'off',
11+
'no-empty': 'off',
12+
'no-regex-spaces': 'off',
13+
'no-useless-escape': 'off'
14+
}
15+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
!coverage-map.js
2626
!postpublish.sh
2727
!netlify.toml
28+
!.eslintrc.js

bin/jack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const reporters = [...new Set([
66
...(require('tap-mocha-reporter').types),
77
...(require('treport/types')),
88
])]
9-
const fs = require('fs')
109
// nyc bundles its deps, pull reporters out of it
1110
const nycReporters = [
1211
'clover',
@@ -693,6 +692,7 @@ Much more documentation available at: https://www.node-tap.org/
693692
appended to the filenames.`,
694693
}),
695694

695+
/* eslint-disable-next-line */
696696
debug: flag({
697697
envDefault: 'TAP_DEBUG',
698698
description: 'Turn on debug mode',

bin/run.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const isexe = require('isexe')
2020
const yaml = require('tap-yaml')
2121
const path = require('path')
2222
const exists = require('fs-exists-cached').sync
23-
const os = require('os')
2423

2524
const maybeResolve = id => {
2625
try {
@@ -358,7 +357,7 @@ const runCoverageReportOnly = options => {
358357
}
359358

360359
/* istanbul ignore next */
361-
const pipeToCoveralls = async options => {
360+
const pipeToCoveralls = async () => {
362361
const reporter = spawn(node, [nycBin, 'report', '--reporter=text-lcov'], {
363362
stdio: [ 0, 'pipe', 2 ]
364363
})
@@ -398,7 +397,7 @@ const openHtmlCoverageReport = (options, code, signal) => {
398397
}
399398
}
400399

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

403402
// export for easier testing
404403
const setupTapEnv = exports.setupTapEnv = options => {
@@ -536,7 +535,7 @@ const saveFails = (options, tap) => {
536535
} catch (er) {}
537536
}
538537

539-
tap.on('bailout', reason => {
538+
tap.on('bailout', () => {
540539
// add any pending test files to the fails list.
541540
fails.push.apply(fails, options.files.filter(file =>
542541
successes.indexOf(file) === -1))

lib/mocha.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
const t = require('./tap.js')
33
t.jobs = 1
44
const tapStack = [ t ]
5-
let level = 0
65
const suiteStack = []
76

87
const describe = (name, fn, opt) =>
@@ -83,7 +82,6 @@ const it = (name, fn, options) => {
8382
name = fn.name
8483
options = options || {}
8584
const todo = !fn
86-
const suite = suiteStack[ suiteStack.length - 1 ]
8785
const t = tapStack[ tapStack.length - 1 ]
8886
if (!name)
8987
name = ''
@@ -119,7 +117,6 @@ function moment (when, fn) {
119117
t[when](function () {
120118
if (!this.options.tapMochaTest)
121119
return
122-
const suite = suiteStack[ suiteStack.length - 1 ]
123120

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

146143
let saved
147-
exports.global = _ => {
144+
exports.global = () => {
148145
if (!saved)
149146
saved = new Map()
150147

@@ -155,7 +152,7 @@ exports.global = _ => {
155152
})
156153
}
157154

158-
exports.deglobal = _ =>
155+
exports.deglobal = () =>
159156
Object.keys(exports).filter(g => g !== 'global').forEach(g => {
160157
if (saved && saved.has(g))
161158
global[g] = saved.get(g)

lib/repl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class Repl {
186186
this.run(null, cb)
187187
}
188188

189-
exit (cb) {
189+
exit () {
190190
this.watch.pause()
191191
this.watch.kill('SIGTERM')
192192
this.repl.close()

lib/tap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22
const {deprecate} = require('util')
3-
const settings = require('../settings.js')
3+
require('../settings.js')
44
const tap = require('libtap')
55

66
// Needs to be set before requiring mocha.js

lib/watch.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const proc = typeof process === 'object' && process ? process : null
22

33
const chokidar = require('chokidar')
4-
const EE = require('events')
54
const Minipass = require('minipass')
65
const bin = require.resolve('../bin/run.js')
76
const {spawn} = require('child_process')
87
const onExit = require('signal-exit')
9-
const {writeFileSync, readFileSync} = require('fs')
8+
const fs = require('fs')
9+
const {writeFileSync, readFileSync} = fs
1010
const {stringify} = require('tap-yaml')
1111
const {resolve} = require('path')
1212

@@ -55,7 +55,6 @@ class Watch extends Minipass {
5555
// Since a covered test was definitely included in its own
5656
// test run, don't add it a second time, so we don't get
5757
// two chokidar events for the same file change.
58-
const cwd = proc.cwd()
5958
const fileSet = new Set(Object.keys(this.index.files))
6059
Object.keys(this.index.externalIds)
6160
.filter(f => !fileSet.has(resolve(f)))
@@ -107,7 +106,7 @@ class Watch extends Minipass {
107106
this.run()
108107
}
109108

110-
run (env) {
109+
run () {
111110
const set = [...new Set(this.queue)]
112111
this.log('running tests', set)
113112
writeFileSync(this.saveFile, set.join('\n') + '\n')
@@ -140,7 +139,7 @@ class Watch extends Minipass {
140139
// then add those, but ignore if it's not there.
141140
const leftover = (() => {
142141
try {
143-
return fs.readFileSync(saveFile, 'utf8').trim().split('\n')
142+
return fs.readFileSync(this.saveFile, 'utf8').trim().split('\n')
144143
} catch (er) {
145144
return []
146145
}

0 commit comments

Comments
 (0)