Skip to content

Commit f65e28e

Browse files
committed
Refactor comments
1 parent 7f911be commit f65e28e

File tree

4 files changed

+40
-49
lines changed

4 files changed

+40
-49
lines changed

lib/index.js

+15-17
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,21 @@ var options = require('./options')
88

99
module.exports = start
1010

11-
/* No-op. */
1211
var noop = Function.prototype
1312

14-
/* Fake TTY stream. */
13+
// Fake TTY stream.
1514
var ttyStream = new stream.Readable()
1615
ttyStream.isTTY = true
1716

18-
/* Exit, lazily, with the correct exit status code. */
17+
// Exit, lazily, with the correct exit status code.
1918
var exitStatus = 0
2019

2120
process.on('exit', onexit)
2221

23-
/* Handle uncaught errors, such as from unexpected async
24-
* behaviour. */
22+
// Handle uncaught errors, such as from unexpected async behaviour.
2523
process.on('uncaughtException', fail)
2624

27-
/* Start the CLI. */
25+
// Start the CLI.
2826
function start(cliConfig) {
2927
var config
3028
var output
@@ -60,22 +58,22 @@ function start(cliConfig) {
6058
return
6159
}
6260

63-
/* Modify `config` for watching. */
61+
// Modify `config` for watching.
6462
if (config.watch) {
6563
output = config.output
6664

67-
/* Do not read from stdin(4). */
65+
// Do not read from stdin(4).
6866
config.streamIn = ttyStream
6967

70-
/* Do not write to stdout(4). */
68+
// Do not write to stdout(4).
7169
config.out = false
7270

7371
process.stderr.write(
7472
chalk.bold('Watching...') + ' (press CTRL+C to exit)\n',
7573
noop
7674
)
7775

78-
/* Prevent infinite loop if set to regeneration. */
76+
// Prevent infinite loop if set to regeneration.
7977
if (output === true) {
8078
config.output = false
8179

@@ -86,10 +84,10 @@ function start(cliConfig) {
8684
}
8785
}
8886

89-
/* Initial run */
87+
// Initial run.
9088
engine(config, done)
9189

92-
/* Handle complete run. */
90+
// Handle complete run.
9391
function done(err, code, context) {
9492
if (err) {
9593
clean()
@@ -103,15 +101,15 @@ function start(cliConfig) {
103101
}
104102
}
105103

106-
/* Clean the watcher. */
104+
// Clean the watcher.
107105
function clean() {
108106
if (watcher) {
109107
watcher.close()
110108
watcher = null
111109
}
112110
}
113111

114-
/* Subscribe a chokidar watcher to all processed files. */
112+
// Subscribe a chokidar watcher to all processed files.
115113
function subscribe(context) {
116114
watcher = chokidar
117115
.watch(context.fileSet.origins, {cwd: config.cwd, ignoreInitial: true})
@@ -127,12 +125,12 @@ function start(cliConfig) {
127125
}
128126

129127
function onsigint() {
130-
/* Hide the `^C` in terminal. */
128+
// Hide the `^C` in terminal.
131129
process.stderr.write('\n', noop)
132130

133131
clean()
134132

135-
/* Do another process if `output` specified regeneration. */
133+
// Do another process if `output` specified regeneration.
136134
if (output === true) {
137135
config.output = output
138136
config.watch = false
@@ -142,7 +140,7 @@ function start(cliConfig) {
142140
}
143141
}
144142

145-
/* Print an error, optionally with stack. */
143+
// Print an error, optionally with stack.
146144
function fail(err, pretty) {
147145
var message =
148146
(pretty ? String(err).trim() : err.stack) ||

lib/options.js

+19-20
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var schema = require('./schema')
99

1010
module.exports = options
1111

12-
/* Schema for `minimist`. */
12+
// Schema for `minimist`.
1313
var minischema = {
1414
unknown: handleUnknownArgument,
1515
default: {},
@@ -20,7 +20,7 @@ var minischema = {
2020

2121
schema.forEach(addEach)
2222

23-
/* Parse CLI options. */
23+
// Parse CLI options.
2424
function options(flags, configuration) {
2525
var extension = configuration.extensions[0]
2626
var name = configuration.name
@@ -55,7 +55,7 @@ function options(flags, configuration) {
5555

5656
return {
5757
helpMessage: help,
58-
/* “hidden” feature, makes testing easier. */
58+
// “hidden” feature, makes testing easier.
5959
cwd: configuration.cwd,
6060
processor: configuration.processor,
6161
help: config.help,
@@ -102,12 +102,12 @@ function addEach(option) {
102102
}
103103
}
104104

105-
/* Parse `extensions`. */
105+
// Parse `extensions`.
106106
function extensions(value) {
107107
return flatten(normalize(value).map(splitList))
108108
}
109109

110-
/* Parse `plugins`. */
110+
// Parse `plugins`.
111111
function plugins(value) {
112112
var result = {}
113113

@@ -120,7 +120,7 @@ function plugins(value) {
120120
return result
121121
}
122122

123-
/* Parse `reporter`: only one is accepted. */
123+
// Parse `reporter`: only one is accepted.
124124
function reporter(value) {
125125
var all = normalize(value)
126126
.map(splitOptions)
@@ -131,7 +131,7 @@ function reporter(value) {
131131
return all[all.length - 1] || []
132132
}
133133

134-
/* Parse `settings`. */
134+
// Parse `settings`.
135135
function settings(value) {
136136
var cache = {}
137137

@@ -142,15 +142,15 @@ function settings(value) {
142142
return cache
143143
}
144144

145-
/* Parse configuration. */
145+
// Parse configuration.
146146
function parseConfig(flags, cache) {
147147
var flag
148148
var message
149149

150150
try {
151151
flags = toCamelCase(parseJSON(flags))
152152
} catch (error) {
153-
/* Fix position */
153+
// Fix position
154154
message = error.message.replace(/at(?= position)/, 'around')
155155

156156
throw fault('Cannot parse `%s` as JSON: %s', flags, message)
@@ -163,19 +163,19 @@ function parseConfig(flags, cache) {
163163
return cache
164164
}
165165

166-
/* Handle an unknown flag. */
166+
// Handle an unknown flag.
167167
function handleUnknownArgument(flag) {
168-
/* Glob. */
168+
// Glob.
169169
if (flag.charAt(0) !== '-') {
170170
return
171171
}
172172

173-
/* Long options. Always unknown. */
173+
// Long options, always unknown.
174174
if (flag.charAt(1) === '-') {
175175
throw fault('Unknown option `%s`, expected:\n%s', flag, inspectAll(schema))
176176
}
177177

178-
/* Short options. Can be grouped. */
178+
// Short options, can be grouped.
179179
flag
180180
.slice(1)
181181
.split('')
@@ -206,12 +206,12 @@ function handleUnknownArgument(flag) {
206206
}
207207
}
208208

209-
/* Inspect all `options`. */
209+
// Inspect all `options`.
210210
function inspectAll(options) {
211211
return table(options.map(inspect))
212212
}
213213

214-
/* Inspect one `option`. */
214+
// Inspect one `option`.
215215
function inspect(option) {
216216
var description = option.description
217217
var long = option.long
@@ -229,7 +229,7 @@ function inspect(option) {
229229
]
230230
}
231231

232-
/* Normalize `value`. */
232+
// Normalize `value`.
233233
function normalize(value) {
234234
if (!value) {
235235
return []
@@ -242,7 +242,7 @@ function normalize(value) {
242242
return flatten(value.map(normalize))
243243
}
244244

245-
/* Flatten `values`. */
245+
// Flatten `values`.
246246
function flatten(values) {
247247
return [].concat.apply([], values)
248248
}
@@ -255,8 +255,7 @@ function splitList(value) {
255255
return value.split(',')
256256
}
257257

258-
/* Transform the keys on an object to camel-case,
259-
* recursivly. */
258+
// Transform the keys on an object to camel-case, recursivly.
260259
function toCamelCase(object) {
261260
var result = {}
262261
var value
@@ -275,7 +274,7 @@ function toCamelCase(object) {
275274
return result
276275
}
277276

278-
/* Parse a (lazy?) JSON config. */
277+
// Parse a (lazy?) JSON config.
279278
function parseJSON(value) {
280279
return json5.parse('{' + value + '}')
281280
}

test/fixtures/example/cli.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
#!/usr/bin/env node
22
'use strict'
33

4-
var extend = require('xtend')
4+
var xtend = require('xtend')
55
var start = require('../../..')
66
var config = require('../config')
77
var processor = require('../processor')
88

9-
start(
10-
extend(config, {
11-
/* Hidden feature, for tests. */
12-
cwd: __dirname,
13-
processor: processor
14-
})
15-
)
9+
start(xtend(config, {cwd: __dirname, processor: processor}))

test/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ test('unified-args', function(t) {
268268

269269
st.plan(1)
270270

271-
/* Should be quoted. */
271+
// Should be quoted.
272272
execa(bin, ['.', flag, 'foo:bar']).then(st.fail, onfail)
273273

274274
function onfail(res) {
@@ -288,7 +288,7 @@ test('unified-args', function(t) {
288288
execa(bin, ['one.txt', flag, '"foo-bar":"baz"']).then(onsuccess, st.fail)
289289

290290
function onsuccess(res) {
291-
/* Parser and Compiler both log stringified settings. */
291+
// Parser and Compiler both log stringified settings.
292292
st.deepEqual(
293293
[res.stdout, strip(res.stderr)],
294294
['{"fooBar":"baz"}\none', 'one.txt: no issues found'],
@@ -325,7 +325,7 @@ test('unified-args', function(t) {
325325
execa(bin, ['one.txt', flag, './plugin']).then(onsuccess, st.fail)
326326

327327
function onsuccess(res) {
328-
/* Attacher logs options, which are `undefined`. */
328+
// Attacher logs options, which are `undefined`.
329329
st.deepEqual(
330330
[res.stdout, strip(res.stderr)],
331331
['undefined\none', 'one.txt: no issues found'],
@@ -340,7 +340,7 @@ test('unified-args', function(t) {
340340

341341
st.plan(1)
342342

343-
/* Should be quoted. */
343+
// Should be quoted.
344344
execa(bin, ['.', flag, './plugin=foo:bar']).then(st.fail, onfail)
345345

346346
function onfail(res) {

0 commit comments

Comments
 (0)