Skip to content

Commit 4dd1beb

Browse files
committed
feature: @putout/cli-process-file: use flatlint only when reason = parse
1 parent 9a13e85 commit 4dd1beb

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

packages/cli-process-file/lib/process-file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports = ({fix, fixCount, logError, raw}) => async function processFile(
3838
printer: configurePrinter(name, printer),
3939
});
4040

41-
if (!again && e && e.reason !== 'traverse') {
41+
if (!again && e && e.reason === 'parse') {
4242
raw && logError(e);
4343

4444
const {lint} = await simpleImport('samadhi');

packages/cli-process-file/lib/process-file.spec.js

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,7 @@ test('putout: cli: process-file: plugin not found', async (t) => {
440440
stopAll();
441441

442442
const expected = {
443-
code: montag`
444-
__putout_processor_yaml({
445-
hello: 'world',
446-
});
447-
`,
443+
code: `__putout_processor_yaml({hello: 'world'});`,
448444
places: [{
449445
message: `Cannot find package 'putout-plugin-travis'`,
450446
position: {
@@ -876,7 +872,7 @@ test('putout: cli: process-file: transform error', async (t) => {
876872
t.end();
877873
});
878874

879-
test('putout: cli: process-file: transform error: no flatlint', async (t) => {
875+
test('putout: cli: process-file: transform error: no flatlint: reason: traverse', async (t) => {
880876
const {extract} = await import('@putout/operate');
881877
const source = 'const a = () => {}';
882878
const fix = true;
@@ -906,6 +902,50 @@ test('putout: cli: process-file: transform error: no flatlint', async (t) => {
906902
source,
907903
index: 0,
908904
length: 1,
905+
simpleImport,
906+
options: {
907+
plugins: [
908+
['throws', plugin],
909+
],
910+
},
911+
});
912+
913+
t.notCalled(simpleImport);
914+
t.end();
915+
});
916+
917+
test('putout: cli: process-file: transform error: no flatlint: reason: fix', async (t) => {
918+
const source = 'const a = () => {}';
919+
const fix = true;
920+
921+
const log = stub();
922+
const write = stub();
923+
const simpleImport = stub();
924+
925+
const fn = processFile({
926+
fix,
927+
log,
928+
write,
929+
});
930+
931+
const plugin = {
932+
report: noop,
933+
fix: () => {
934+
throw Error('x');
935+
},
936+
traverse: ({push}) => ({
937+
Function(path) {
938+
push(path);
939+
},
940+
}),
941+
};
942+
943+
await fn({
944+
name: 'example.js',
945+
source,
946+
index: 0,
947+
length: 1,
948+
simpleImport,
909949
options: {
910950
plugins: [
911951
['throws', plugin],

0 commit comments

Comments
 (0)