Skip to content

Commit 2238f28

Browse files
committed
feature: @putout/engine-loader: add ability to disable all rules except couple enabled
1 parent 6ba9abf commit 2238f28

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed

packages/engine-loader/lib/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,13 @@ module.exports.loadPlugins = (options) => {
6767
loadedRules,
6868
});
6969

70+
const cookedNotEnabled = parseRules(rules, {
71+
enable: false,
72+
});
73+
7074
return filterEnabledPlugins({
7175
plugins,
72-
cookedRules,
76+
cookedRules: cookedNotEnabled,
7377
});
7478
};
7579

packages/engine-loader/lib/rules/parse-rules.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ const parseState = (rule, value) => {
2424
return value;
2525
};
2626

27-
module.exports.parseRules = (rules) => {
28-
rules = parseSubrules(rules);
27+
module.exports.parseRules = (rules, {enable = true} = {}) => {
28+
if (enable)
29+
rules = parseSubrules(rules);
2930

3031
const result = [];
3132
const plugin = null;

packages/engine-loader/test/load-plugins.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ test('putout: loader: no options.pluginNames', (t) => {
243243
t.end();
244244
});
245245

246-
test('putout: loader: enable part of rule', (t) => {
246+
test('putout: loader: enable part of plugin', (t) => {
247247
const source = `const {run} = require('madrun');`;
248248

249249
const {code} = putout(source, {
@@ -294,6 +294,31 @@ test('putout: loader: disabled part of rule', (t) => {
294294
t.end();
295295
});
296296

297+
test('putout: loader: enable part of rule', (t) => {
298+
const code = montag`
299+
const {run} = require('madrun');
300+
301+
module.exports = {
302+
'lint': () => 'bin/putout.js .',
303+
'fix:lint': () => run('lint', '--fix'),
304+
};
305+
`;
306+
307+
const {places} = putout(code, {
308+
fix: false,
309+
rules: {
310+
'madrun': 'off',
311+
'madrun/add-madrun-to-lint': 'on',
312+
},
313+
plugins: ['madrun'],
314+
});
315+
316+
const expected = [];
317+
318+
t.deepEqual(places, expected, 'should disable all but couple of rules in plugin');
319+
t.end();
320+
});
321+
297322
test('putout: loader: plugin is a function', (t) => {
298323
const [e] = tryCatch(putout, 'hello', {
299324
loadPlugins,

packages/engine-runner/lib/progress.spec.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test('putout: runner: progress: start', async (t) => {
2424
putout(source, {
2525
progress,
2626
rules: {
27+
'filesystem': 'off',
2728
'filesystem/remove-files': ['on', {
2829
names: ['coverage'],
2930
}],
@@ -32,7 +33,7 @@ test('putout: runner: progress: start', async (t) => {
3233
}),
3334
]);
3435

35-
t.equal(pluginsCount, 4);
36+
t.equal(pluginsCount, 1);
3637
t.end();
3738
});
3839

@@ -52,6 +53,7 @@ test('putout: runner: progress: end', async (t) => {
5253
putout(source, {
5354
progress,
5455
rules: {
56+
'filesystem': 'off',
5557
'filesystem/remove-files': ['on', {
5658
names: ['coverage'],
5759
}],
@@ -60,7 +62,7 @@ test('putout: runner: progress: end', async (t) => {
6062
}),
6163
]);
6264

63-
t.equal(pluginsCount, 4);
65+
t.equal(pluginsCount, 1);
6466
t.end();
6567
});
6668

@@ -90,6 +92,6 @@ test('putout: runner: progress: push', async (t) => {
9092
}),
9193
]);
9294

93-
t.equal(pluginsCount, 4);
95+
t.equal(pluginsCount, 1);
9496
t.end();
9597
});

packages/operate/lib/replace-with/replace-with.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,12 @@ test('putout: operate: replaceWith: parentPath', (t) => {
187187
const {code} = putout(source, {
188188
rules: {
189189
'putout': 'off',
190+
'putout/apply-create-test': 'on',
190191
'putout/apply-fixture-name-to-message': 'on',
192+
'putout/declare': 'on',
193+
'putout/convert-dirname-to-url': 'on',
191194
'putout/move-require-on-top-level': 'on',
195+
'putout/replace-test-message': 'on',
192196
},
193197
plugins: ['putout'],
194198
});

0 commit comments

Comments
 (0)