OpenCode plugin to configure ESLint as formatter and LSP when ESLint config is detected
npm install opencode-eslint-formatterAn OpenCode plugin that automatically configures ESLint as the formatter and LSP when an ESLint configuration file is detected in your project.
- Automatically detects ESLint configuration files in your project
- Disables Prettier formatter to avoid conflicts
- Configures ESLint as the code formatter for JavaScript/TypeScript files
- Sets up ESLint language server for real-time linting in your editor
- Fully configurable with enable/disable option
``bash`
bun add opencode-eslint-formatter
or
`bash`
npm install opencode-eslint-formatter
Create a plugin file in your OpenCode configuration directory:
~/.config/opencode/plugin/eslint-formatter.ts (global) or .opencode/plugin/eslint-formatter.ts (per-project):
`typescript
import { createEslintFormatterPlugin } from "opencode-eslint-formatter";
export const EslintFormatter = createEslintFormatterPlugin();
`
`typescript
import { createEslintFormatterPlugin } from "opencode-eslint-formatter";
export const EslintFormatter = createEslintFormatterPlugin({
enable: true // Set to false to disable the plugin
});
`
The plugin:
1. Checks if an ESLint configuration file exists in your project (supports .eslintrc, .eslintrc.json, .eslintrc.js, .eslintrc.cjs, .eslintrc.yaml, .eslintrc.yml, eslint.config.js, eslint.config.mjs, eslint.config.cjs)--fix
2. If found, it modifies the OpenCode configuration to:
- Disable Prettier formatter
- Add ESLint as a formatter with flag
- Configure ESLint language server for real-time linting
When an ESLint configuration is detected, the plugin adds:
`json`
{
"formatter": {
"prettier": {
"disabled": true
},
"lint-formatter": {
"command": ["yarn", "eslint", "--fix", "$FILE"],
"extensions": [".js", ".ts", ".jsx", ".tsx"]
}
},
"lsp": {
"eslint": {
"command": ["vscode-eslint-language-server", "--stdio"],
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
}
- OpenCode with plugin support
- ESLint configuration file in your project
- yarn and eslint installed in your projectvscode-eslint-language-server
- for LSP support (install globally or in your project)
To run tests:
`bash`
bun test
To type-check:
`bash``
bun tsc
MIT