import eslint from 'eslint';
import { baseRules } from '../../../lib/eslint/base.js';
let eslintInstance;
export default async ({ resolvePluginsRelativeTo, filePath, fileContents }) => {
    if (!eslintInstance) {
        eslintInstance = new eslint.ESLint({
            fix: true,
            useEslintrc: false,
            resolvePluginsRelativeTo,
            overrideConfig: {
                plugins: ['unused-imports', 'import'],
                extends: ['plugin:@typescript-eslint/base'],
                parserOptions: {
                    sourceType: 'module',
                    ecmaVersion: 'latest',
                },
                rules: baseRules,
            },
        });
    }
    if (await eslintInstance.isPathIgnored(filePath)) {
        return { result: fileContents };
    }
    try {
        const [result] = await eslintInstance.lintText(fileContents, { filePath });
        return { result: result.output ?? fileContents };
    }
    catch (error) {
        return { error: `${error}` };
    }
};
