Skip to content

Commit

Permalink
chore: lint previously ignored files
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Nov 3, 2021
1 parent c035821 commit 08cd7be
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 24 deletions.
5 changes: 2 additions & 3 deletions index.js
@@ -1,5 +1,4 @@
if (require.main === module) {
if (require.main === module)
require('./lib/cli.js')(process)
} else {
else
throw new Error('The programmatic API was removed in npm v8.0.0')
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -220,7 +220,7 @@
"sudotest:nocleanup": "sudo NO_TEST_CLEANUP=1 npm run test --",
"posttest": "npm run lint",
"eslint": "eslint",
"lint": "npm run eslint -- test/lib test/bin bin lib scripts docs smoke-tests",
"lint": "npm run eslint -- bin docs lib scripts smoke-tests test ./*.js",
"lintfix": "npm run lint -- --fix",
"prelint": "rimraf test/npm_cache*",
"resetdeps": "bash scripts/resetdeps.sh",
Expand Down
13 changes: 6 additions & 7 deletions test/fixtures/mock-npm.js
Expand Up @@ -26,7 +26,7 @@ const RealMockNpm = (t, otherMocks = {}) => {
}
const Npm = t.mock('../../lib/npm.js', otherMocks)
class MockNpm extends Npm {
constructor() {
constructor () {
super()
for (const level in npmlog.levels) {
npmlog[level] = (...msg) => {
Expand Down Expand Up @@ -79,9 +79,8 @@ class MockNpm {
const config = base.config || {}

for (const attr in base) {
if (attr !== 'config') {
if (attr !== 'config')
this[attr] = base[attr]
}
}

this.flatOptions = base.flatOptions || {}
Expand All @@ -91,7 +90,7 @@ class MockNpm {
find: (k) => ({...realConfig.defaults, ...config})[k],
get: (k) => ({...realConfig.defaults, ...config})[k],
set: (k, v) => config[k] = v,
list: [{ ...realConfig.defaults, ...config}]
list: [{ ...realConfig.defaults, ...config}],
}
if (!this.log) {
this.log = {
Expand All @@ -110,18 +109,18 @@ class MockNpm {
}
}

output(...msg) {
output (...msg) {
if (this.base.output)
return this.base.output(msg)
this._mockOutputs.push(msg)
}
}

const FakeMockNpm = (base = {}) => {
return new MockNpm(base)
return new MockNpm(base)
}

module.exports = {
fake: FakeMockNpm,
real: RealMockNpm
real: RealMockNpm,
}
22 changes: 10 additions & 12 deletions test/fixtures/sandbox.js
Expand Up @@ -6,26 +6,26 @@ const { promisify } = require('util')
const mkdirp = require('mkdirp-infer-owner')
const npmlog = require('npmlog')
const rimraf = promisify(require('rimraf'))
const t = require('tap')

let active = null
const chain = new Map()
const sandboxes = new Map()

// Disable lint errors for assigning to process global
/* global process:writable */

// keep a reference to the real process
const _process = process

const processHook = createHook({
createHook({
init: (asyncId, type, triggerAsyncId, resource) => {
// track parentage of asyncIds
chain.set(asyncId, triggerAsyncId)
},
before: (asyncId) => {
// find the nearest parent id that has a sandbox
let parent = asyncId
while (chain.has(parent) && !sandboxes.has(parent)) {
while (chain.has(parent) && !sandboxes.has(parent))
parent = chain.get(parent)
}

process = sandboxes.has(parent)
? sandboxes.get(parent)
Expand Down Expand Up @@ -173,7 +173,7 @@ class Sandbox extends EventEmitter {
if (this[_npm]) {
// replace default config values with placeholders
for (const name of redactedDefaults) {
let value = this[_npm].config.defaults[name]
const value = this[_npm].config.defaults[name]
clean = clean.split(value).join(`{${name.toUpperCase()}}`)
}

Expand Down Expand Up @@ -201,21 +201,19 @@ class Sandbox extends EventEmitter {

// test.teardown hook
teardown () {
if (this[_parent]) {
if (this[_parent])
sandboxes.delete(this[_parent])
}

return rimraf(this[_dirs].temp).catch(() => null)
}

// proxy get handler
[_get] (target, prop, receiver) {
if (this[_data].has(prop)) {
if (this[_data].has(prop))
return this[_data].get(prop)
}

if (this[prop] !== undefined) {
if (this[prop] !== undefined)
return Reflect.get(this, prop, this)
}

const actual = Reflect.get(target, prop, receiver)
if (typeof actual === 'function') {
Expand Down
1 change: 0 additions & 1 deletion test/index.js
Expand Up @@ -20,4 +20,3 @@ t.test('loading as main module will load the cli', t => {
t.end()
})
})

0 comments on commit 08cd7be

Please sign in to comment.