add --output-config CLI option

can help to get the default config for adaption

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2020-06-06 12:49:55 +02:00
parent 177b4d5ea7
commit 4e679d18a2

View File

@ -9,7 +9,9 @@ program
.usage('[options] [<file(s) ...>]') .usage('[options] [<file(s) ...>]')
.option('-c, --config <configfile>', 'uses <configfile> for eslint config instead.') .option('-c, --config <configfile>', 'uses <configfile> for eslint config instead.')
.option('-e, --extend <configfile>', 'uses <configfile> ontop of default eslint config.') .option('-e, --extend <configfile>', 'uses <configfile> ontop of default eslint config.')
.option('-f, --fix', 'if set, fixes will be applied.'); .option('-f, --fix', 'if set, fixes will be applied.')
.option('--output-config', 'if set, only output the config as JSON and exit.')
;
program.on('--help', function() { program.on('--help', function() {
console.log(''); console.log('');
@ -26,7 +28,7 @@ if (program.config && program.extend) {
process.exit(1); process.exit(1);
} }
if (program.args.length < 1) { if (program.args.length < 1 && !program.outputConfig) {
program.help(); program.help();
} }
@ -246,6 +248,12 @@ if (program.config) {
console.log(`Extend with path: ${config.extends}`); console.log(`Extend with path: ${config.extends}`);
} }
if (program.outputConfig) {
let cfg = JSON.stringify(config, null, 2);
console.log(cfg);
process.exit(0);
}
const cli = new eslint.CLIEngine({ const cli = new eslint.CLIEngine({
baseConfig: config, baseConfig: config,
useEslintrc: true, useEslintrc: true,