Files
orca/config/scripts/oxlint-plugin-test-runner.mjs
mirror 34fa2cd5ca
Skill update round trip / roundtrip (false, macos-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (false, macos-latest, symlink, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (false, ubuntu-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (false, ubuntu-latest, symlink, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (false, ubuntu-latest, symlink, latest) (push) Canceled after 0s
Skill update round trip / roundtrip (false, windows-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (false, windows-latest, symlink, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, macos-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, macos-latest, symlink, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, ubuntu-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, ubuntu-latest, symlink, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, windows-latest, copy, 1.5.17) (push) Canceled after 0s
Skill update round trip / roundtrip (true, windows-latest, symlink, 1.5.17) (push) Canceled after 0s
source snapshot 2026-09-02
2026-09-02 02:03:16 +08:00

59 lines
1.6 KiB
JavaScript

import { spawnSync } from 'node:child_process'
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { createRequire } from 'node:module'
import { tmpdir } from 'node:os'
import path from 'node:path'
import process from 'node:process'
const oxlintPackageDirectory = path.dirname(
createRequire(import.meta.url).resolve('oxlint/package.json')
)
const oxlintPath = path.join(oxlintPackageDirectory, 'bin', 'oxlint')
export function runOxlintPluginOnSource({
pluginName,
pluginPath,
rules,
source,
extension = 'tsx'
}) {
const directory = mkdtempSync(path.join(tmpdir(), `orca-${pluginName}-lint-`))
const sourcePath = path.join(directory, `sample.${extension}`)
const configPath = path.join(directory, 'oxlint.json')
try {
writeFileSync(sourcePath, source)
writeFileSync(
configPath,
JSON.stringify({
plugins: [],
categories: {
correctness: 'off',
suspicious: 'off',
pedantic: 'off',
perf: 'off',
style: 'off',
restriction: 'off',
nursery: 'off'
},
jsPlugins: [{ name: pluginName, specifier: pluginPath }],
rules
})
)
const result = spawnSync(
process.execPath,
[oxlintPath, '--config', configPath, '--format', 'json', sourcePath],
{ encoding: 'utf8' }
)
if (result.error) {
throw result.error
}
if (!result.stdout.trim()) {
throw new Error(result.stderr || `${pluginName} did not produce Oxlint output`)
}
return JSON.parse(result.stdout).diagnostics
} finally {
rmSync(directory, { recursive: true, force: true })
}
}