/
parser.js
82 lines (78 loc) · 2.48 KB
/
parser.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import path from 'path'
import findUp from 'find-up'
import yargs from 'yargs'
import {oneLine} from 'common-tags'
import arrify from 'arrify'
const parser = yargs
.usage('Usage: $0 <globs>... [--option-1 option-1-value --option-2]')
.help('h')
.alias('h', 'help')
.version()
.options({
write: {
default: false,
describe: 'Edit the file in-place (beware!)',
type: 'boolean',
},
stdin: {default: false, describe: 'Read input via stdin', type: 'boolean'},
'eslint-ignore': {
default: true,
type: 'boolean',
describe: oneLine`
Only format matching files even if
they are not ignored by .eslintignore.
(can use --no-eslint-ignore to disable this)
`,
},
eslintPath: {
default: getPathInHostNodeModules('eslint'),
describe: 'The path to the eslint module to use',
coerce: coercePath,
},
prettierPath: {
describe: 'The path to the prettier module to use',
default: getPathInHostNodeModules('prettier'),
coerce: coercePath,
},
ignore: {
describe: oneLine`
pattern(s) you wish to ignore
(can be used multiple times
and includes **/node_modules/** automatically)
`,
coerce: arrify,
},
'log-level': {
describe: 'The log level to use',
choices: ['silent', 'error', 'warn', 'info', 'debug', 'trace'],
alias: 'l',
default: 'warn',
},
// TODO: if we allow people to to specify a config path,
// we need to read that somehow. These can come invarious
// formats and we'd have to work out `extends` somehow as well.
// I don't know whether ESLint exposes a way to do this...
// Contributions welcome!
// eslintConfigPath: {
// describe: 'Path to the eslint config to use for eslint --fix',
// },
// TODO: would this be just a JSON file? There's never going to be
// a `.prettierrc`: https://github.com/jlongster/prettier/issues/154
// so we'll have to be careful how we do this (if we do it at all).
// prettierOptions: {
// describe: 'Path to the prettier config to use',
// },,
})
.strict()
export default parser
function getPathInHostNodeModules(module) {
const modulePath = findUp.sync(`node_modules/${module}`)
if (modulePath) {
return modulePath
} else {
return path.relative(__dirname, `../node_modules/${module}`)
}
}
function coercePath(input) {
return path.isAbsolute(input) ? input : path.join(process.cwd(), input)
}