Skip to content

Commit fade161

Browse files
committed
feature: @putout/cli-process-file: FLATLINT
1 parent ec130dc commit fade161

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
'use strict';
22

3+
const process = require('node:process');
34
const tryToCatch = require('try-to-catch');
45
const eslint = require('@putout/eslint');
56
const {parseMatch} = require('putout/parse-match');
67
const {mergeOptions} = require('putout/merge-options');
78
const parseError = require('putout/parse-error');
89
const {putoutAsync} = require('putout');
10+
const once = require('once');
911

1012
const {simpleImport: _simpleImport} = require('./simple-import');
1113

@@ -16,13 +18,16 @@ const getMatchedOptions = (name, options) => {
1618
return mergeOptions(options, parseMatch(name, options.match));
1719
};
1820

21+
const getEnv = once(() => process.env);
22+
1923
module.exports = ({fix, fixCount, logError, raw}) => async function processFile(overrides) {
2024
const {
2125
name = '<input>',
2226
source,
2327
startLine,
2428
options = {},
2529
again,
30+
env = getEnv(),
2631
simpleImport = _simpleImport,
2732
} = overrides;
2833

@@ -40,7 +45,9 @@ module.exports = ({fix, fixCount, logError, raw}) => async function processFile(
4045

4146
e && raw && logError(e);
4247

43-
if (!again && e && e.reason === 'parse') {
48+
const {FLATLINT} = env;
49+
50+
if (FLATLINT || !again && e && e.reason === 'parse') {
4451
const {lint} = await simpleImport('samadhi');
4552
const [code, places] = await lint(source, {
4653
startLine,

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,48 @@ test('putout: cli: process-file: transform error: no flatlint: reason: traverse'
914914
t.end();
915915
});
916916

917+
test('putout: cli: process-file: transform error: flatlint: env variable FLATLINT', async (t) => {
918+
const {extract} = await import('@putout/operate');
919+
const source = 'const a = () => {}';
920+
const fix = true;
921+
922+
const log = stub();
923+
const write = stub();
924+
const simpleImport = stub();
925+
926+
const fn = processFile({
927+
fix,
928+
log,
929+
write,
930+
});
931+
932+
const plugin = {
933+
report: noop,
934+
fix: noop,
935+
traverse: () => ({
936+
Function(path) {
937+
extract(path);
938+
},
939+
}),
940+
};
941+
942+
await fn({
943+
name: 'example.js',
944+
source,
945+
index: 0,
946+
length: 1,
947+
simpleImport,
948+
options: {
949+
plugins: [
950+
['throws', plugin],
951+
],
952+
},
953+
});
954+
955+
t.notCalled(simpleImport);
956+
t.end();
957+
});
958+
917959
test('putout: cli: process-file: transform error: no flatlint: reason: fix', async (t) => {
918960
const source = 'const a = () => {}';
919961
const fix = true;

packages/cli-process-file/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@putout/eslint": "^4.0.0",
2828
"@putout/formatter-eslint": "^2.0.2",
2929
"deepmerge": "^4.3.1",
30+
"once": "^1.4.0",
3031
"samadhi": "^2.14.1",
3132
"try-catch": "^3.0.0",
3233
"try-to-catch": "^3.0.0"

0 commit comments

Comments
 (0)