mirror of
https://github.com/electron/node-gyp.git
synced 2025-08-15 12:58:19 +02:00
src: implement standard.js linting
In addition: * moved module.exports to the bottom * no single-line if statements * no if statements without a { * const for requires * array declarations get spaces inside [ ] * 'use strict' in all .js files PR-URL: https://github.com/nodejs/node-gyp/pull/1794 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: João Reis <reis@janeasystems.com>
This commit is contained in:
parent
7e8127068f
commit
e40c99e283
28 changed files with 739 additions and 661 deletions
|
@ -1,9 +1,9 @@
|
|||
'use strict'
|
||||
|
||||
var test = require('tap').test
|
||||
var configure = require('../lib/configure')
|
||||
var execFile = require('child_process').execFile
|
||||
var PythonFinder = configure.test.PythonFinder
|
||||
const test = require('tap').test
|
||||
const configure = require('../lib/configure')
|
||||
const execFile = require('child_process').execFile
|
||||
const PythonFinder = configure.test.PythonFinder
|
||||
|
||||
require('npmlog').level = 'warn'
|
||||
|
||||
|
@ -22,8 +22,8 @@ test('find python', function (t) {
|
|||
})
|
||||
})
|
||||
|
||||
function poison(object, property) {
|
||||
function fail() {
|
||||
function poison (object, property) {
|
||||
function fail () {
|
||||
console.error(Error(`Property ${property} should not have been accessed.`))
|
||||
process.abort()
|
||||
}
|
||||
|
@ -31,12 +31,14 @@ function poison(object, property) {
|
|||
configurable: false,
|
||||
enumerable: false,
|
||||
get: fail,
|
||||
set: fail,
|
||||
set: fail
|
||||
}
|
||||
Object.defineProperty(object, property, descriptor)
|
||||
}
|
||||
|
||||
function TestPythonFinder() { PythonFinder.apply(this, arguments) }
|
||||
function TestPythonFinder () {
|
||||
PythonFinder.apply(this, arguments)
|
||||
}
|
||||
TestPythonFinder.prototype = Object.create(PythonFinder.prototype)
|
||||
// Silence npmlog - remove for debugging
|
||||
TestPythonFinder.prototype.log = {
|
||||
|
@ -44,28 +46,28 @@ TestPythonFinder.prototype.log = {
|
|||
verbose: () => {},
|
||||
info: () => {},
|
||||
warn: () => {},
|
||||
error: () => {},
|
||||
error: () => {}
|
||||
}
|
||||
|
||||
test('find python - python', function (t) {
|
||||
t.plan(6)
|
||||
|
||||
var f = new TestPythonFinder('python', done)
|
||||
f.execFile = function(program, args, opts, cb) {
|
||||
f.execFile = function(program, args, opts, cb) {
|
||||
f.execFile = function (program, args, opts, cb) {
|
||||
f.execFile = function (program, args, opts, cb) {
|
||||
poison(f, 'execFile')
|
||||
t.strictEqual(program, '/path/python')
|
||||
t.ok(/sys\.version_info/.test(args[1]))
|
||||
cb(null, '2.7.15')
|
||||
}
|
||||
t.strictEqual(program,
|
||||
process.platform === 'win32' ? '"python"' : 'python')
|
||||
process.platform === 'win32' ? '"python"' : 'python')
|
||||
t.ok(/sys\.executable/.test(args[1]))
|
||||
cb(null, '/path/python')
|
||||
}
|
||||
f.findPython()
|
||||
|
||||
function done(err, python) {
|
||||
function done (err, python) {
|
||||
t.strictEqual(err, null)
|
||||
t.strictEqual(python, '/path/python')
|
||||
}
|
||||
|
@ -75,10 +77,10 @@ test('find python - python too old', function (t) {
|
|||
t.plan(2)
|
||||
|
||||
var f = new TestPythonFinder(null, done)
|
||||
f.execFile = function(program, args, opts, cb) {
|
||||
if (/sys\.executable/.test(args[args.length-1])) {
|
||||
f.execFile = function (program, args, opts, cb) {
|
||||
if (/sys\.executable/.test(args[args.length - 1])) {
|
||||
cb(null, '/path/python')
|
||||
} else if (/sys\.version_info/.test(args[args.length-1])) {
|
||||
} else if (/sys\.version_info/.test(args[args.length - 1])) {
|
||||
cb(null, '2.3.4')
|
||||
} else {
|
||||
t.fail()
|
||||
|
@ -86,7 +88,7 @@ test('find python - python too old', function (t) {
|
|||
}
|
||||
f.findPython()
|
||||
|
||||
function done(err) {
|
||||
function done (err) {
|
||||
t.ok(/Could not find any Python/.test(err))
|
||||
t.ok(/not supported/i.test(f.errorLog))
|
||||
}
|
||||
|
@ -96,10 +98,10 @@ test('find python - python too new', function (t) {
|
|||
t.plan(2)
|
||||
|
||||
var f = new TestPythonFinder(null, done)
|
||||
f.execFile = function(program, args, opts, cb) {
|
||||
if (/sys\.executable/.test(args[args.length-1])) {
|
||||
f.execFile = function (program, args, opts, cb) {
|
||||
if (/sys\.executable/.test(args[args.length - 1])) {
|
||||
cb(null, '/path/python')
|
||||
} else if (/sys\.version_info/.test(args[args.length-1])) {
|
||||
} else if (/sys\.version_info/.test(args[args.length - 1])) {
|
||||
cb(null, '3.0.0')
|
||||
} else {
|
||||
t.fail()
|
||||
|
@ -107,7 +109,7 @@ test('find python - python too new', function (t) {
|
|||
}
|
||||
f.findPython()
|
||||
|
||||
function done(err) {
|
||||
function done (err) {
|
||||
t.ok(/Could not find any Python/.test(err))
|
||||
t.ok(/not supported/i.test(f.errorLog))
|
||||
}
|
||||
|
@ -117,10 +119,10 @@ test('find python - no python', function (t) {
|
|||
t.plan(2)
|
||||
|
||||
var f = new TestPythonFinder(null, done)
|
||||
f.execFile = function(program, args, opts, cb) {
|
||||
if (/sys\.executable/.test(args[args.length-1])) {
|
||||
f.execFile = function (program, args, opts, cb) {
|
||||
if (/sys\.executable/.test(args[args.length - 1])) {
|
||||
cb(new Error('not found'))
|
||||
} else if (/sys\.version_info/.test(args[args.length-1])) {
|
||||
} else if (/sys\.version_info/.test(args[args.length - 1])) {
|
||||
cb(new Error('not a Python executable'))
|
||||
} else {
|
||||
t.fail()
|
||||
|
@ -128,7 +130,7 @@ test('find python - no python', function (t) {
|
|||
}
|
||||
f.findPython()
|
||||
|
||||
function done(err) {
|
||||
function done (err) {
|
||||
t.ok(/Could not find any Python/.test(err))
|
||||
t.ok(/not in PATH/.test(f.errorLog))
|
||||
}
|
||||
|
@ -138,14 +140,14 @@ test('find python - no python2', function (t) {
|
|||
t.plan(2)
|
||||
|
||||
var f = new TestPythonFinder(null, done)
|
||||
f.execFile = function(program, args, opts, cb) {
|
||||
if (/sys\.executable/.test(args[args.length-1])) {
|
||||
if (program == 'python2') {
|
||||
f.execFile = function (program, args, opts, cb) {
|
||||
if (/sys\.executable/.test(args[args.length - 1])) {
|
||||
if (program === 'python2') {
|
||||
cb(new Error('not found'))
|
||||
} else {
|
||||
cb(null, '/path/python')
|
||||
}
|
||||
} else if (/sys\.version_info/.test(args[args.length-1])) {
|
||||
} else if (/sys\.version_info/.test(args[args.length - 1])) {
|
||||
cb(null, '2.7.14')
|
||||
} else {
|
||||
t.fail()
|
||||
|
@ -153,7 +155,7 @@ test('find python - no python2', function (t) {
|
|||
}
|
||||
f.findPython()
|
||||
|
||||
function done(err, python) {
|
||||
function done (err, python) {
|
||||
t.strictEqual(err, null)
|
||||
t.strictEqual(python, '/path/python')
|
||||
}
|
||||
|
@ -166,8 +168,8 @@ test('find python - no python2, no python, unix', function (t) {
|
|||
f.checkPyLauncher = t.fail
|
||||
f.win = false
|
||||
|
||||
f.execFile = function(program, args, opts, cb) {
|
||||
if (/sys\.executable/.test(args[args.length-1])) {
|
||||
f.execFile = function (program, args, opts, cb) {
|
||||
if (/sys\.executable/.test(args[args.length - 1])) {
|
||||
cb(new Error('not found'))
|
||||
} else {
|
||||
t.fail()
|
||||
|
@ -175,7 +177,7 @@ test('find python - no python2, no python, unix', function (t) {
|
|||
}
|
||||
f.findPython()
|
||||
|
||||
function done(err) {
|
||||
function done (err) {
|
||||
t.ok(/Could not find any Python/.test(err))
|
||||
t.ok(/not in PATH/.test(f.errorLog))
|
||||
}
|
||||
|
@ -187,15 +189,15 @@ test('find python - no python, use python launcher', function (t) {
|
|||
var f = new TestPythonFinder(null, done)
|
||||
f.win = true
|
||||
|
||||
f.execFile = function(program, args, opts, cb) {
|
||||
f.execFile = function (program, args, opts, cb) {
|
||||
if (program === 'py.exe') {
|
||||
t.notEqual(args.indexOf('-2'), -1)
|
||||
t.notEqual(args.indexOf('-c'), -1)
|
||||
return cb(null, 'Z:\\snake.exe')
|
||||
}
|
||||
if (/sys\.executable/.test(args[args.length-1])) {
|
||||
if (/sys\.executable/.test(args[args.length - 1])) {
|
||||
cb(new Error('not found'))
|
||||
} else if (/sys\.version_info/.test(args[args.length-1])) {
|
||||
} else if (/sys\.version_info/.test(args[args.length - 1])) {
|
||||
if (program === 'Z:\\snake.exe') {
|
||||
cb(null, '2.7.14')
|
||||
} else {
|
||||
|
@ -207,7 +209,7 @@ test('find python - no python, use python launcher', function (t) {
|
|||
}
|
||||
f.findPython()
|
||||
|
||||
function done(err, python) {
|
||||
function done (err, python) {
|
||||
t.strictEqual(err, null)
|
||||
t.strictEqual(python, 'Z:\\snake.exe')
|
||||
}
|
||||
|
@ -219,11 +221,11 @@ test('find python - python 3, use python launcher', function (t) {
|
|||
var f = new TestPythonFinder(null, done)
|
||||
f.win = true
|
||||
|
||||
f.execFile = function(program, args, opts, cb) {
|
||||
f.execFile = function (program, args, opts, cb) {
|
||||
if (program === 'py.exe') {
|
||||
f.execFile = function(program, args, opts, cb) {
|
||||
f.execFile = function (program, args, opts, cb) {
|
||||
poison(f, 'execFile')
|
||||
if (/sys\.version_info/.test(args[args.length-1])) {
|
||||
if (/sys\.version_info/.test(args[args.length - 1])) {
|
||||
cb(null, '2.7.14')
|
||||
} else {
|
||||
t.fail()
|
||||
|
@ -233,9 +235,9 @@ test('find python - python 3, use python launcher', function (t) {
|
|||
t.notEqual(args.indexOf('-c'), -1)
|
||||
return cb(null, 'Z:\\snake.exe')
|
||||
}
|
||||
if (/sys\.executable/.test(args[args.length-1])) {
|
||||
if (/sys\.executable/.test(args[args.length - 1])) {
|
||||
cb(null, '/path/python')
|
||||
} else if (/sys\.version_info/.test(args[args.length-1])) {
|
||||
} else if (/sys\.version_info/.test(args[args.length - 1])) {
|
||||
cb(null, '3.0.0')
|
||||
} else {
|
||||
t.fail()
|
||||
|
@ -243,76 +245,76 @@ test('find python - python 3, use python launcher', function (t) {
|
|||
}
|
||||
f.findPython()
|
||||
|
||||
function done(err, python) {
|
||||
function done (err, python) {
|
||||
t.strictEqual(err, null)
|
||||
t.strictEqual(python, 'Z:\\snake.exe')
|
||||
}
|
||||
})
|
||||
|
||||
test('find python - python 3, use python launcher, python 2 too old',
|
||||
function (t) {
|
||||
t.plan(6)
|
||||
function (t) {
|
||||
t.plan(6)
|
||||
|
||||
var f = new TestPythonFinder(null, done)
|
||||
f.win = true
|
||||
var f = new TestPythonFinder(null, done)
|
||||
f.win = true
|
||||
|
||||
f.execFile = function(program, args, opts, cb) {
|
||||
if (program === 'py.exe') {
|
||||
f.execFile = function(program, args, opts, cb) {
|
||||
if (/sys\.version_info/.test(args[args.length-1])) {
|
||||
f.execFile = function(program, args, opts, cb) {
|
||||
if (/sys\.version_info/.test(args[args.length-1])) {
|
||||
poison(f, 'execFile')
|
||||
t.strictEqual(program, f.defaultLocation)
|
||||
cb(new Error('not found'))
|
||||
} else {
|
||||
t.fail()
|
||||
f.execFile = function (program, args, opts, cb) {
|
||||
if (program === 'py.exe') {
|
||||
f.execFile = function (program, args, opts, cb) {
|
||||
if (/sys\.version_info/.test(args[args.length - 1])) {
|
||||
f.execFile = function (program, args, opts, cb) {
|
||||
if (/sys\.version_info/.test(args[args.length - 1])) {
|
||||
poison(f, 'execFile')
|
||||
t.strictEqual(program, f.defaultLocation)
|
||||
cb(new Error('not found'))
|
||||
} else {
|
||||
t.fail()
|
||||
}
|
||||
}
|
||||
t.strictEqual(program, 'Z:\\snake.exe')
|
||||
cb(null, '2.3.4')
|
||||
} else {
|
||||
t.fail()
|
||||
}
|
||||
t.strictEqual(program, 'Z:\\snake.exe')
|
||||
cb(null, '2.3.4')
|
||||
} else {
|
||||
t.fail()
|
||||
}
|
||||
t.notEqual(args.indexOf('-2'), -1)
|
||||
t.notEqual(args.indexOf('-c'), -1)
|
||||
return cb(null, 'Z:\\snake.exe')
|
||||
}
|
||||
if (/sys\.executable/.test(args[args.length - 1])) {
|
||||
cb(null, '/path/python')
|
||||
} else if (/sys\.version_info/.test(args[args.length - 1])) {
|
||||
cb(null, '3.0.0')
|
||||
} else {
|
||||
t.fail()
|
||||
}
|
||||
t.notEqual(args.indexOf('-2'), -1)
|
||||
t.notEqual(args.indexOf('-c'), -1)
|
||||
return cb(null, 'Z:\\snake.exe')
|
||||
}
|
||||
if (/sys\.executable/.test(args[args.length-1])) {
|
||||
cb(null, '/path/python')
|
||||
} else if (/sys\.version_info/.test(args[args.length-1])) {
|
||||
cb(null, '3.0.0')
|
||||
} else {
|
||||
t.fail()
|
||||
}
|
||||
}
|
||||
f.findPython()
|
||||
f.findPython()
|
||||
|
||||
function done(err) {
|
||||
t.ok(/Could not find any Python/.test(err))
|
||||
t.ok(/not supported/i.test(f.errorLog))
|
||||
}
|
||||
})
|
||||
function done (err) {
|
||||
t.ok(/Could not find any Python/.test(err))
|
||||
t.ok(/not supported/i.test(f.errorLog))
|
||||
}
|
||||
})
|
||||
|
||||
test('find python - no python, no python launcher, good guess', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var re = /C:[\\\/]Python27[\\\/]python[.]exe/
|
||||
var re = /C:[\\/]Python27[\\/]python[.]exe/
|
||||
var f = new TestPythonFinder(null, done)
|
||||
f.win = true
|
||||
|
||||
f.execFile = function(program, args, opts, cb) {
|
||||
f.execFile = function (program, args, opts, cb) {
|
||||
if (program === 'py.exe') {
|
||||
f.execFile = function(program, args, opts, cb) {
|
||||
f.execFile = function (program, args, opts, cb) {
|
||||
poison(f, 'execFile')
|
||||
t.ok(re.test(program))
|
||||
t.ok(/sys\.version_info/.test(args[args.length-1]))
|
||||
t.ok(/sys\.version_info/.test(args[args.length - 1]))
|
||||
cb(null, '2.7.14')
|
||||
}
|
||||
return cb(new Error('not found'))
|
||||
}
|
||||
if (/sys\.executable/.test(args[args.length-1])) {
|
||||
if (/sys\.executable/.test(args[args.length - 1])) {
|
||||
cb(new Error('not found'))
|
||||
} else {
|
||||
t.fail()
|
||||
|
@ -320,7 +322,7 @@ test('find python - no python, no python launcher, good guess', function (t) {
|
|||
}
|
||||
f.findPython()
|
||||
|
||||
function done(err, python) {
|
||||
function done (err, python) {
|
||||
t.strictEqual(err, null)
|
||||
t.ok(re.test(python))
|
||||
}
|
||||
|
@ -332,10 +334,10 @@ test('find python - no python, no python launcher, bad guess', function (t) {
|
|||
var f = new TestPythonFinder(null, done)
|
||||
f.win = true
|
||||
|
||||
f.execFile = function(program, args, opts, cb) {
|
||||
if (/sys\.executable/.test(args[args.length-1])) {
|
||||
f.execFile = function (program, args, opts, cb) {
|
||||
if (/sys\.executable/.test(args[args.length - 1])) {
|
||||
cb(new Error('not found'))
|
||||
} else if (/sys\.version_info/.test(args[args.length-1])) {
|
||||
} else if (/sys\.version_info/.test(args[args.length - 1])) {
|
||||
cb(new Error('not a Python executable'))
|
||||
} else {
|
||||
t.fail()
|
||||
|
@ -343,7 +345,7 @@ test('find python - no python, no python launcher, bad guess', function (t) {
|
|||
}
|
||||
f.findPython()
|
||||
|
||||
function done(err) {
|
||||
function done (err) {
|
||||
t.ok(/Could not find any Python/.test(err))
|
||||
t.ok(/not in PATH/.test(f.errorLog))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue