UNPKG

@slippy-lint/slippy

Version:

A simple but powerful linter for Solidity

49 lines 1.52 kB
import path from "node:path"; import fs from "node:fs/promises"; import { createConfigLoader } from "../config.js"; import { Linter } from "../linter.js"; import { SlippyError, SlippyFileNotFoundError, } from "../errors.js"; import workerpool from "workerpool"; export default async function runLinter(sourceId) { try { return await internalRunLinter(sourceId); } catch (error) { if (SlippyError.isSlippyError(error)) { return { code: error.code, message: error.message, hint: error.hint, }; } throw error; } } async function internalRunLinter(sourceId) { const configLoader = await createConfigLoader(process.cwd()); const sourceIdToAbsolutePath = {}; const runner = new Linter(configLoader); try { const absolutePath = path.resolve(process.cwd(), sourceId); sourceIdToAbsolutePath[sourceId] = absolutePath; const file = { filePath: sourceId, content: await fs.readFile(absolutePath, "utf8"), }; const results = await runner.lintFiles([file]); return { lintResults: results, sourceIdToAbsolutePath, }; } catch (error) { if (error instanceof Error && "code" in error && error.code === "ENOENT") { throw new SlippyFileNotFoundError(sourceId); } throw error; } } workerpool.worker({ runLinter, }); //# sourceMappingURL=worker.js.map