Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit ac7a817

Browse files
committed
Move from "var" to "const"/"let"
1 parent e5fdc3a commit ac7a817

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

cli.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env node
22

3-
var check = require('./')
3+
const check = require('./')
44

5-
var args = require('minimist')(process.argv.slice(2), {
5+
const args = require('minimist')(process.argv.slice(2), {
66
default: {
77
missing: false,
88
extra: false,
@@ -44,10 +44,10 @@ if (args.help || args._.length === 0) {
4444

4545
function extensions (arg) {
4646
if (!arg) return undefined
47-
var extensions = {}
47+
const extensions = {}
4848

4949
function add (value) {
50-
var parts = value.trim().split(':', 2)
50+
const parts = value.trim().split(':', 2)
5151

5252
parts[0].split(',').forEach(function (ext) {
5353
extensions[ext.charAt(0) === '.' ? ext : '.' + ext] = parts[1]
@@ -71,16 +71,16 @@ check({
7171
detective: args.detective
7272
})
7373
.then(data => {
74-
var pkg = data.package
75-
var deps = data.used
76-
var failed = 0
77-
var options = {
74+
const pkg = data.package
75+
const deps = data.used
76+
let failed = 0
77+
const options = {
7878
excludeDev: args.dev === false,
7979
excludePeer: args.peer === false,
8080
ignore: [].concat(args.i || [])
8181
}
8282
if (args.extra) {
83-
var extras = check.extra(pkg, deps, options)
83+
const extras = check.extra(pkg, deps, options)
8484
failed += extras.length
8585
if (extras.length) {
8686
console.error('Fail! Modules in package.json not used in code: ' + extras.join(', '))
@@ -89,7 +89,7 @@ check({
8989
}
9090
}
9191
if (args.missing || !args.extra) {
92-
var missing = check.missing(pkg, deps, options)
92+
const missing = check.missing(pkg, deps, options)
9393
failed += missing.length
9494
if (missing.length) {
9595
console.error('Fail! Dependencies not listed in package.json: ' + missing.join(', '))

index.js

+34-34
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
var path = require('path')
2-
var fs = require('fs')
3-
var readPackage = require('read-package-json')
4-
var builtins = require('builtins')()
5-
var resolveModule = require('resolve')
6-
var debug = require('debug')('dependency-check')
7-
var isRelative = require('is-relative')
8-
9-
var promisedReadPackage = function (pkgPath) {
1+
const path = require('path')
2+
const fs = require('fs')
3+
const readPackage = require('read-package-json')
4+
const builtins = require('builtins')()
5+
const resolveModule = require('resolve')
6+
const debug = require('debug')('dependency-check')
7+
const isRelative = require('is-relative')
8+
9+
const promisedReadPackage = function (pkgPath) {
1010
return new Promise((resolve, reject) => {
1111
readPackage(pkgPath, (err, pkg) => {
1212
if (err) return reject(err)
@@ -16,8 +16,8 @@ var promisedReadPackage = function (pkgPath) {
1616
}
1717

1818
module.exports = function (opts, cb) {
19-
var pkgPath = opts.path
20-
var result = promisedReadPackage(pkgPath)
19+
let pkgPath = opts.path
20+
const result = promisedReadPackage(pkgPath)
2121
.catch(err => {
2222
if (err && err.code === 'EISDIR') {
2323
pkgPath = path.join(pkgPath, 'package.json')
@@ -45,8 +45,8 @@ module.exports = function (opts, cb) {
4545
}
4646

4747
module.exports.missing = function (pkg, deps, options) {
48-
var missing = []
49-
var config = configure(pkg, options)
48+
const missing = []
49+
const config = configure(pkg, options)
5050

5151
deps.map(used => {
5252
if (config.allDeps.indexOf(used) === -1 && config.ignore.indexOf(used) === -1) {
@@ -58,8 +58,8 @@ module.exports.missing = function (pkg, deps, options) {
5858
}
5959

6060
module.exports.extra = function (pkg, deps, options) {
61-
var missing = []
62-
var config = configure(pkg, options)
61+
const missing = []
62+
const config = configure(pkg, options)
6363

6464
config.allDeps.map(dep => {
6565
if (deps.indexOf(dep) === -1 && config.ignore.indexOf(dep) === -1) {
@@ -84,7 +84,7 @@ function noopDetective () {
8484

8585
function getExtensions (extensions, detective) {
8686
// Initialize extensions with node.js default handlers.
87-
var result = {
87+
const result = {
8888
'.js': noopDetective,
8989
'.node': noopDetective,
9090
'.json': noopDetective
@@ -113,8 +113,8 @@ function getExtensions (extensions, detective) {
113113
function configure (pkg, options) {
114114
options = options || {}
115115

116-
var allDeps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}))
117-
var ignore = options.ignore || []
116+
let allDeps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}))
117+
let ignore = options.ignore || []
118118

119119
if (typeof ignore === 'string') ignore = [ignore]
120120

@@ -137,23 +137,23 @@ function isNotRelative (file) {
137137
}
138138

139139
function parse (opts) {
140-
var pkgPath = opts.path
141-
var pkg = opts.package
142-
var extensions = opts.extensions
143-
144-
var deps = {}
145-
var paths = []
146-
var seen = []
147-
var core = []
148-
var mainPath = path.resolve(pkg.main || path.join(path.dirname(pkgPath), 'index.js'))
140+
const pkgPath = opts.path
141+
const pkg = opts.package
142+
const extensions = opts.extensions
143+
144+
const deps = {}
145+
const paths = []
146+
const seen = []
147+
const core = []
148+
const mainPath = path.resolve(pkg.main || path.join(path.dirname(pkgPath), 'index.js'))
149149
if (!opts.noDefaultEntries && fs.existsSync(mainPath)) paths.push(mainPath)
150150

151151
if (!opts.noDefaultEntries && pkg.bin) {
152152
if (typeof pkg.bin === 'string') {
153153
paths.push(path.resolve(path.join(path.dirname(pkgPath), pkg.bin)))
154154
} else {
155155
Object.keys(pkg.bin).forEach(cmdName => {
156-
var cmd = pkg.bin[cmdName]
156+
const cmd = pkg.bin[cmdName]
157157
paths.push(path.resolve(path.join(path.dirname(pkgPath), cmd)))
158158
})
159159
}
@@ -176,7 +176,7 @@ function parse (opts) {
176176

177177
return Promise.all(paths.map(file => resolveDep(file)))
178178
.then(allDeps => {
179-
var used = {}
179+
const used = {}
180180
// merge all deps into one unique list
181181
allDeps.forEach(deps => {
182182
Object.keys(deps).forEach(dep => {
@@ -207,8 +207,8 @@ function parse (opts) {
207207
}
208208

209209
function getDeps (file) {
210-
var ext = path.extname(file)
211-
var detective = extensions[ext] || extensions['.js']
210+
const ext = path.extname(file)
211+
const detective = extensions[ext] || extensions['.js']
212212

213213
if (typeof detective !== 'function') {
214214
return Promise.reject(new Error('Detective function missing for "' + file + '"'))
@@ -221,10 +221,10 @@ function parse (opts) {
221221
})
222222
})
223223
.then(contents => {
224-
var requires = detective(contents)
225-
var relatives = []
224+
const requires = detective(contents)
225+
const relatives = []
226226
requires.map(req => {
227-
var isCore = builtins.indexOf(req) > -1
227+
const isCore = builtins.indexOf(req) > -1
228228
if (isNotRelative(req) && !isCore) {
229229
// require('foo/bar') -> require('foo')
230230
if (req[0] !== '@' && req.indexOf('/') > -1) req = req.split('/')[0]

0 commit comments

Comments
 (0)