Skip to content

Commit e899de3

Browse files
committed
feature: putout: cli: get-options: putout --no-config: do not exit when no plugins passed
1 parent bf9b31c commit e899de3

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

packages/putout/bin/tracer.spec.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,12 @@ test('putout: bin: cli: tracer: -h', async (t) => {
2424
t.equal(stdout, `${help()}\n`);
2525
t.end();
2626
});
27+
28+
test('putout: bin: cli: tracer --no-config', (t) => {
29+
const {stdout} = spawnSync(cliPath, ['--no-config'], {
30+
encoding: 'utf8',
31+
});
32+
33+
t.equal(stdout, '');
34+
t.end();
35+
});

packages/putout/lib/cli/get-options.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const process = require('node:process');
44
const {join, dirname} = require('node:path');
55

66
const buildPlugins = require('./build-plugins');
7-
const parseOptions = require('../parse-options');
7+
const _parseOptions = require('../parse-options');
88

99
const {assign} = Object;
1010
const {env} = process;
@@ -19,7 +19,16 @@ PUTOUT_CONFIG_FILE && assign(maybeConfig, require(join(
1919
PUTOUT_CONFIG_FILE,
2020
)));
2121

22-
module.exports = ({noConfig, plugins, name, transform, rulesdir}) => {
22+
module.exports = (overrides = {}) => {
23+
const {
24+
noConfig,
25+
plugins = [],
26+
name,
27+
transform,
28+
rulesdir,
29+
parseOptions = _parseOptions,
30+
} = overrides;
31+
2332
const transformPlugins = buildPlugins(transform);
2433

2534
if (noConfig)

packages/putout/lib/cli/get-options.spec.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,41 @@ test('putout: cli: get-options: PUTOUT_CONFIG_FILE', (t) => {
4242
t.deepEqual(result, expected);
4343
t.end();
4444
});
45+
46+
test('putout: cli: get-options: no plugins', (t) => {
47+
const {PUTOUT_CONFIG_FILE} = process.env;
48+
49+
process.env.PUTOUT_CONFIG_FILE = './hello-config';
50+
51+
const parseOptions = stub().returns({
52+
from: 'parse-options',
53+
plugins: [],
54+
});
55+
56+
mockRequire(join(process.cwd(), './hello-config'), {
57+
hello: 'world',
58+
});
59+
60+
const getOptions = reRequire('./get-options');
61+
62+
const result = getOptions({
63+
parseOptions,
64+
});
65+
66+
if (!PUTOUT_CONFIG_FILE)
67+
delete process.env.PUTOUT_CONFIG_FILE;
68+
else
69+
process.env.PUTOUT_CONFIG_FILE = PUTOUT_CONFIG_FILE;
70+
71+
stopAll();
72+
reRequire('./get-options');
73+
74+
const expected = {
75+
hello: 'world',
76+
from: 'parse-options',
77+
plugins: [],
78+
};
79+
80+
t.deepEqual(result, expected);
81+
t.end();
82+
});

0 commit comments

Comments
 (0)