Skip to content

Commit

Permalink
src: implement standard.js linting
Browse files Browse the repository at this point in the history
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: #1794
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: João Reis <reis@janeasystems.com>
  • Loading branch information
rvagg committed Jul 6, 2019
1 parent 7e81270 commit e40c99e
Show file tree
Hide file tree
Showing 28 changed files with 746 additions and 668 deletions.
6 changes: 0 additions & 6 deletions .eslintrc.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions .jshintrc

This file was deleted.

29 changes: 15 additions & 14 deletions bin/node-gyp.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#!/usr/bin/env node

'use strict'

process.title = 'node-gyp'

var envPaths = require('env-paths')
var gyp = require('../')
var log = require('npmlog')
var os = require('os')
const envPaths = require('env-paths')
const gyp = require('../')
const log = require('npmlog')
const os = require('os')

/**
* Process and execute the selected commands.
*/

var prog = gyp()
const prog = gyp()
var completed = false
prog.parseArgv(process.argv)
prog.devDir = prog.opts.devdir
Expand All @@ -24,8 +26,8 @@ if (prog.devDir) {
} else {
throw new Error(
"node-gyp requires that the user's home directory is specified " +
"in either of the environmental variables HOME or USERPROFILE. " +
"Overide with: --devdir /path/to/.node-gyp")
'in either of the environmental variables HOME or USERPROFILE. ' +
'Overide with: --devdir /path/to/.node-gyp')
}

if (prog.todo.length === 0) {
Expand All @@ -42,7 +44,6 @@ log.verbose('cli', process.argv)
log.info('using', 'node-gyp@%s', prog.version)
log.info('using', 'node@%s | %s | %s', process.versions.node, process.platform, process.arch)


/**
* Change dir if -C/--directory was passed.
*/
Expand Down Expand Up @@ -84,7 +85,7 @@ function run () {
log.error('not ok')
return process.exit(1)
}
if (command.name == 'list') {
if (command.name === 'list') {
var versions = arguments[1]
if (versions.length > 0) {
versions.forEach(function (version) {
Expand Down Expand Up @@ -122,18 +123,18 @@ function errorMessage () {
var os = require('os')
log.error('System', os.type() + ' ' + os.release())
log.error('command', process.argv
.map(JSON.stringify).join(' '))
.map(JSON.stringify).join(' '))
log.error('cwd', process.cwd())
log.error('node -v', process.version)
log.error('node-gyp -v', 'v' + prog.package.version)
}

function issueMessage () {
errorMessage()
log.error('', [ 'This is a bug in `node-gyp`.'
, 'Try to update node-gyp and file an Issue if it does not help:'
, ' <https://github.com/nodejs/node-gyp/issues>'
].join('\n'))
log.error('', [ 'This is a bug in `node-gyp`.',
'Try to update node-gyp and file an Issue if it does not help:',
' <https://github.com/nodejs/node-gyp/issues>'
].join('\n'))
}

// start running the given commands!
Expand Down
56 changes: 32 additions & 24 deletions lib/build.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
'use strict'

module.exports = exports = build

var fs = require('graceful-fs')
, path = require('path')
, glob = require('glob')
, log = require('npmlog')
, which = require('which')
, win = process.platform === 'win32'
const fs = require('graceful-fs')
const path = require('path')
const glob = require('glob')
const log = require('npmlog')
const which = require('which')
const win = process.platform === 'win32'

exports.usage = 'Invokes `' + (win ? 'msbuild' : 'make') + '` and builds the module'

Expand All @@ -17,18 +16,19 @@ function build (gyp, argv, callback) {
} else if (process.platform.indexOf('bsd') !== -1) {
platformMake = 'gmake'
} else if (win && argv.length > 0) {
argv = argv.map(function(target) {
argv = argv.map(function (target) {
return '/t:' + target
})
}

var makeCommand = gyp.opts.make || process.env.MAKE || platformMake
, command = win ? 'msbuild' : makeCommand
, jobs = gyp.opts.jobs || process.env.JOBS
, buildType
, config
, arch
, nodeDir
var command = win ? 'msbuild' : makeCommand
var jobs = gyp.opts.jobs || process.env.JOBS
var buildType
var config
var arch
var nodeDir
var guessedSolution

loadConfigGypi()

Expand All @@ -38,16 +38,17 @@ function build (gyp, argv, callback) {

function loadConfigGypi () {
var configPath = path.resolve('build', 'config.gypi')

fs.readFile(configPath, 'utf8', function (err, data) {
if (err) {
if (err.code == 'ENOENT') {
if (err.code === 'ENOENT') {
callback(new Error('You must run `node-gyp configure` first!'))
} else {
callback(err)
}
return
}
config = JSON.parse(data.replace(/\#.+\n/, ''))
config = JSON.parse(data.replace(/#.+\n/, ''))

// get the 'arch', 'buildType', and 'nodeDir' vars from the config
buildType = config.target_defaults.default_configuration
Expand Down Expand Up @@ -79,7 +80,9 @@ function build (gyp, argv, callback) {

function findSolutionFile () {
glob('build/*.sln', function (err, files) {
if (err) return callback(err)
if (err) {
return callback(err)
}
if (files.length === 0) {
return callback(new Error('Could not find *.sln file. Did you run "configure"?'))
}
Expand Down Expand Up @@ -124,9 +127,12 @@ function build (gyp, argv, callback) {
function doBuild () {
// Enable Verbose build
var verbose = log.levels[log.level] <= log.levels.verbose
var j

if (!win && verbose) {
argv.push('V=1')
}

if (win && !verbose) {
argv.push('/clp:Verbosity=minimal')
}
Expand All @@ -142,12 +148,12 @@ function build (gyp, argv, callback) {
// Since there are many ways to state '32-bit Intel', default to it.
// N.B. msbuild's Condition string equality tests are case-insensitive.
var archLower = arch.toLowerCase()
var p = archLower === 'x64' ? 'x64' :
(archLower === 'arm' ? 'ARM' :
(archLower === 'arm64' ? 'ARM64' : 'Win32'))
var p = archLower === 'x64' ? 'x64'
: (archLower === 'arm' ? 'ARM'
: (archLower === 'arm64' ? 'ARM64' : 'Win32'))
argv.push('/p:Configuration=' + buildType + ';Platform=' + p)
if (jobs) {
var j = parseInt(jobs, 10)
j = parseInt(jobs, 10)
if (!isNaN(j) && j > 0) {
argv.push('/m:' + j)
} else if (jobs.toUpperCase() === 'MAX') {
Expand All @@ -160,7 +166,7 @@ function build (gyp, argv, callback) {
argv.push('-C')
argv.push('build')
if (jobs) {
var j = parseInt(jobs, 10)
j = parseInt(jobs, 10)
if (!isNaN(j) && j > 0) {
argv.push('--jobs')
argv.push(j)
Expand All @@ -174,7 +180,7 @@ function build (gyp, argv, callback) {
if (win) {
// did the user specify their own .sln file?
var hasSln = argv.some(function (arg) {
return path.extname(arg) == '.sln'
return path.extname(arg) === '.sln'
})
if (!hasSln) {
argv.unshift(gyp.opts.solution || guessedSolution)
Expand All @@ -195,3 +201,5 @@ function build (gyp, argv, callback) {
callback()
}
}

module.exports = build
12 changes: 6 additions & 6 deletions lib/clean.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
'use strict'

module.exports = exports = clean

exports.usage = 'Removes any generated build files and the "out" dir'

var rm = require('rimraf')
var log = require('npmlog')
const rm = require('rimraf')
const log = require('npmlog')

function clean (gyp, argv, callback) {
// Remove the 'build' dir
Expand All @@ -13,3 +10,6 @@ function clean (gyp, argv, callback) {
log.verbose('clean', 'removing "%s" directory', buildDir)
rm(buildDir, callback)
}

module.exports = clean
module.exports.usage = 'Removes any generated build files and the "out" dir'
Loading

0 comments on commit e40c99e

Please sign in to comment.