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