Skip to content

Commit a45076c

Browse files
committed
Refactor code-style
1 parent 91f0875 commit a45076c

File tree

4 files changed

+119
-125
lines changed

4 files changed

+119
-125
lines changed

lib/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import chalk from 'chalk'
44
import chokidar from 'chokidar'
55
import {options} from './options.js'
66

7-
var noop = Function.prototype
7+
const noop = Function.prototype
88

99
// Fake TTY stream.
10-
var ttyStream = new stream.Readable()
10+
const ttyStream = new stream.Readable()
1111
ttyStream.isTTY = true
1212

1313
// Exit, lazily, with the correct exit status code.
14-
var exitStatus = 0
14+
let exitStatus = 0
1515

1616
process.on('exit', onexit)
1717

@@ -20,9 +20,9 @@ process.on('uncaughtException', fail)
2020

2121
// Start the CLI.
2222
export function args(cliConfig) {
23-
var config
24-
var output
25-
var watcher
23+
let config
24+
let output
25+
let watcher
2626

2727
try {
2828
config = options(process.argv.slice(2), cliConfig)
@@ -140,7 +140,7 @@ export function args(cliConfig) {
140140
function fail(error, pretty) {
141141
// Old versions of Node
142142
/* c8 ignore next 1 */
143-
var message = (pretty ? String(error).trim() : error.stack) || error
143+
const message = (pretty ? String(error).trim() : error.stack) || error
144144

145145
exitStatus = 1
146146

lib/options.js

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import json5 from 'json5'
55
import fault from 'fault'
66
import {schema} from './schema.js'
77

8+
const own = {}.hasOwnProperty
9+
810
// Schema for `minimist`.
9-
var minischema = {
11+
const minischema = {
1012
unknown: handleUnknownArgument,
1113
default: {},
1214
alias: {},
@@ -21,12 +23,9 @@ while (++index < schema.length) {
2123

2224
// Parse CLI options.
2325
export function options(flags, configuration) {
24-
var extension = configuration.extensions[0]
25-
var name = configuration.name
26-
var config = toCamelCase(minimist(flags, minischema))
27-
var help
28-
var ext
29-
var report
26+
const extension = configuration.extensions[0]
27+
const name = configuration.name
28+
const config = toCamelCase(minimist(flags, minischema))
3029
let index = -1
3130

3231
while (++index < schema.length) {
@@ -36,10 +35,9 @@ export function options(flags, configuration) {
3635
}
3736
}
3837

39-
ext = commaSeparated(config.ext)
40-
report = reporter(config.report)
41-
42-
help = [
38+
const ext = commaSeparated(config.ext)
39+
const report = reporter(config.report)
40+
const help = [
4341
inspectAll(schema),
4442
'',
4543
'Examples:',
@@ -94,7 +92,7 @@ export function options(flags, configuration) {
9492
}
9593

9694
function addEach(option) {
97-
var value = option.default
95+
const value = option.default
9896

9997
minischema.default[option.long] = value === undefined ? null : value
10098

@@ -114,7 +112,7 @@ function commaSeparated(value) {
114112

115113
// Parse `plugins`.
116114
function plugins(value) {
117-
var result = {}
115+
const result = {}
118116
const normalized = normalize(value).map((d) => splitOptions(d))
119117
let index = -1
120118

@@ -128,9 +126,9 @@ function plugins(value) {
128126

129127
// Parse `reporter`: only one is accepted.
130128
function reporter(value) {
131-
var all = normalize(value)
129+
const all = normalize(value)
132130
.map((d) => splitOptions(d))
133-
.map(function (value) {
131+
.map((value) => {
134132
return [value[0], value[1] ? parseConfig(value[1], {}) : null]
135133
})
136134

@@ -139,7 +137,7 @@ function reporter(value) {
139137

140138
// Parse `settings`.
141139
function settings(value) {
142-
var cache = {}
140+
const cache = {}
143141
const normalized = normalize(value)
144142
let index = -1
145143

@@ -152,8 +150,8 @@ function settings(value) {
152150

153151
// Parse configuration.
154152
function parseConfig(flags, cache) {
155-
var flag
156-
var message
153+
let flag
154+
let message
157155

158156
try {
159157
flags = toCamelCase(parseJSON(flags))
@@ -165,7 +163,9 @@ function parseConfig(flags, cache) {
165163
}
166164

167165
for (flag in flags) {
168-
cache[flag] = flags[flag]
166+
if (own.call(flags, flag)) {
167+
cache[flag] = flags[flag]
168+
}
169169
}
170170

171171
return cache
@@ -208,8 +208,8 @@ function inspectAll(options) {
208208

209209
// Inspect one `option`.
210210
function inspect(option) {
211-
var description = option.description
212-
var long = option.long
211+
let description = option.description
212+
let long = option.long
213213

214214
if (option.default === true || option.truelike) {
215215
description += ' (on by default)'
@@ -253,18 +253,20 @@ function splitList(value) {
253253

254254
// Transform the keys on an object to camel-case, recursivly.
255255
function toCamelCase(object) {
256-
var result = {}
257-
var value
258-
var key
256+
const result = {}
257+
let value
258+
let key
259259

260260
for (key in object) {
261-
value = object[key]
261+
if (own.call(object, key)) {
262+
value = object[key]
262263

263-
if (value && typeof value === 'object' && !('length' in value)) {
264-
value = toCamelCase(value)
265-
}
264+
if (value && typeof value === 'object' && !('length' in value)) {
265+
value = toCamelCase(value)
266+
}
266267

267-
result[camelcase(key)] = value
268+
result[camelcase(key)] = value
269+
}
268270
}
269271

270272
return result

package.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@
7171
},
7272
"xo": {
7373
"prettier": true,
74-
"rules": {
75-
"no-var": "off",
76-
"prefer-arrow-callback": "off",
77-
"unicorn/no-fn-reference-in-iterator": "off",
78-
"guard-for-in": "off"
79-
},
8074
"ignores": [
8175
"**/*.ts"
8276
]

0 commit comments

Comments
 (0)