Skip to content

Commit 8d16fac

Browse files
authored
feat(#144): add OpenCode plugin for automatic Python linting (#145)
* feat(#144): add OpenCode plugin for automatic Python linting (ruff + ty) * feat(#144): add debug logging to Python linter plugin
1 parent ac70240 commit 8d16fac

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

‎.opencode/plugin/python-linter.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { Plugin } from "@opencode-ai/plugin"
2+
3+
export const PythonLinterPlugin: Plugin = async ({ $, directory }) => {
4+
return {
5+
event: async ({ event }) => {
6+
// Only process file.edited events for Python files
7+
if (event.type !== "file.edited") {
8+
return
9+
}
10+
11+
const file = (event as { type: "file.edited"; file: string }).file
12+
13+
if (!file.endsWith('.py')) {
14+
return
15+
}
16+
17+
console.log(`[python-linter] Linting: ${file}`)
18+
19+
try {
20+
// Run ruff check with auto-fix
21+
await $`cd ${directory} && ruff check --fix ${file}`.quiet()
22+
console.log(`[python-linter] ruff check: OK`)
23+
} catch (e) {
24+
// ruff may not be installed or may have unfixable errors - continue
25+
console.log(`[python-linter] ruff check: skipped (${e instanceof Error ? e.message : 'not installed'})`)
26+
}
27+
28+
try {
29+
// Run ruff format
30+
await $`cd ${directory} && ruff format ${file}`.quiet()
31+
console.log(`[python-linter] ruff format: OK`)
32+
} catch (e) {
33+
// ruff format may not be installed - continue
34+
console.log(`[python-linter] ruff format: skipped`)
35+
}
36+
37+
try {
38+
// Run ty type checker
39+
await $`cd ${directory} && ty check ${file}`.quiet()
40+
console.log(`[python-linter] ty check: OK`)
41+
} catch (e) {
42+
// ty may not be installed - continue
43+
console.log(`[python-linter] ty check: skipped`)
44+
}
45+
}
46+
}
47+
}

‎opencode.personal.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"instructions/tool-preferences.md",
1010
"instructions/context7-library-documentation.md"
1111
],
12+
"plugin": [
13+
"file://.opencode/plugin/python-linter.ts"
14+
],
1215
"agent": {
1316
"project-manager": {
1417
"description": "Pure orchestrator that coordinates specialists but never executes code - read-only tools and delegation only",

‎opencode.work.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"instructions/postgres-mcp-databases.md",
1313
"instructions/rollbar-mcp-integration.md"
1414
],
15+
"plugin": [
16+
"file://.opencode/plugin/python-linter.ts"
17+
],
1518
"permission": {
1619
"bash": {
1720
"pulumi up*": "deny",

0 commit comments

Comments
 (0)