forked from stephenmathieson-boneyard/node-cpplint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse-options.js
52 lines (42 loc) · 1.03 KB
/
parse-options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
var extend = require('./extend.js');
/**
* Supported counting (`--counting=`) types
* @type {Array}
*/
var COUNTING_TYPES = [
'total',
'toplevel',
'detailed'
];
// verbosity requirements
var MAX_VERBOSITY = 5;
var MIN_VERBOSITY = 0;
/**
* The default _cpplint_ options
* @type {Object}
*/
var defaults = {};
defaults.verbosity = 1;
defaults.counting = 'total';
/**
* @async
* @param {Object} options
* @param {Function} next
*/
function parseOptions(options, next) {
var conf = extend(defaults, options, true);
if (!conf.files || !conf.files.length) {
return next(new Error('must provide some files'));
}
if (conf.verbosity > MAX_VERBOSITY || conf.verbosity < MIN_VERBOSITY) {
return next(new Error('invalid verbosity level (0-5)'));
}
if (COUNTING_TYPES.indexOf(conf.counting) === -1) {
return next(new Error('invalid counting type (' + COUNTING_TYPES.join(', ')
+ ')'));
}
next(null, conf);
}
module.exports.defaults = defaults;
module.exports.parseOptions = parseOptions;