@neodx/vfs
Version:
Simple virtual file system - working dir context, lazy changes, different modes, integrations and moreover
78 lines (77 loc) • 2.69 kB
JavaScript
import {
lazyValue as t,
concurrently as i,
toArray as a,
compact as e,
isTypeOfString as r
} from '@neodx/std';
import { extname as n } from 'pathe';
import { j as s, g as l } from '../_internal/operations-D4d9Xk5B.mjs';
import { c as o } from '../_internal/create-vfs-plugin-CTZbwgZU.mjs';
function f({
fix: f = !0,
auto: p = !0,
logErrors: g = !0,
logWarnings: c = !1,
eslintParams: d
} = {}) {
return o('eslint', (o, { context: m, beforeApply: w }) => {
let { fix: x, fixAll: h } = o,
b = t(async () => {
let { ESLint: t } = await import('eslint');
return new t({
overrideConfig: {
env: { es6: !0, node: !0 },
parserOptions: { ecmaVersion: 2022, sourceType: 'module' }
},
...d,
fix: f,
cwd: m.path
});
}),
E = m.log.child('eslint');
return (
(o.fix = async t => {
let l = await b(),
f = e(
(
await i(a(t), async t =>
(await o.isFile(t))
? (await l.isPathIgnored(t))
? (E.debug('Skipping %s, because it is ignored', s(m, t)), null)
: u.includes(n(t))
? await l.lintText(await o.read(t, 'utf-8'), { filePath: o.resolve(t) })
: (E.debug('Skipping %s, because it is not a source file', s(m, t)), null)
: (E.debug('Skipping %s, because it is not a file', s(m, t)), null)
)
).flat()
),
p = f.filter(t => t.fatalErrorCount > 0),
d = f.filter(t => t.fatalErrorCount > 0),
w = f.filter(t => t.fatalErrorCount > 0),
h = await l.loadFormatter('stylish');
w.length > 0 && E.error('ESLint fatal errors:%s', h.format(w)),
g && p.length > 0 && E.error('ESLint errors:%s', h.format(p)),
c && d.length > 0 && E.warn('ESLint warnings:%s', h.format(d)),
await i(
f,
async ({ filePath: t, fixableErrorCount: i, fixableWarningCount: a, output: e }) => {
if (r(e))
return E.debug('fixing %d ESLint issues in %s', i + a, t), await o.write(t, e);
}
),
await x?.(t);
}),
(o.fixAll = async () => {
E.debug('Fixing all ESLint issues in changed files...');
let t = await l(m, ['create', 'update']);
await o.fix(t.map(t => t.path)), await h?.();
}),
p && w(() => o.fixAll()),
o
);
});
}
let u = ['js', 'ts'].flatMap(t => [`.${t}`, `.c${t}`, `.m${t}`, `.${t}x`]);
export { f as eslint };
//# sourceMappingURL=eslint.mjs.map