Skip to content

Commit

Permalink
chore: fix playground eslint autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Dec 9, 2024
1 parent 62717f0 commit 2819a54
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions playgrounds/playground/moquerie.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,32 @@ export default defineConfig({
{
name: 'eslint-autofix',

writeCode: async ({ code }) => {
// @ts-expect-error no types
const { FlatESLint } = await import('eslint/use-at-your-own-risk')
writeCode: async ({ code, path }) => {
const { ESLint } = await import('eslint')

if (!eslint) {
const configPath = resolve(__dirname, 'eslint.config.js')
console.log(configPath)
eslint = new FlatESLint({
fix: true,
eslint = new ESLint({
cwd: __dirname,
overrideConfigFile: configPath,
fix: true,
ignore: false,
})
}

console.log('ESLint autofixing', code)

const results = await eslint.lintText(code)
await FlatESLint.outputFixes(results)
const results = await eslint.lintText(code, {
filePath: path,
})
await ESLint.outputFixes(results)
const [result] = results
console.log(result)
if (result?.output) {
console.log('ESLint autofix applied', result.output)
return result.output
}
else if (result?.messages?.length) {
for (const message of result.messages) {
console[message.fatal ? 'error' : 'warn'](`[ESLint] ${message.message} - ${path} (${message.line}:${message.column})`)
}
}
},
},

Expand Down

0 comments on commit 2819a54

Please sign in to comment.