opencode-eslint-formatter
v0.1.0
Published
OpenCode plugin to configure ESLint as formatter and LSP when ESLint config is detected
Downloads
99
Maintainers
Readme
opencode-eslint-formatter
An OpenCode plugin that automatically configures ESLint as the formatter and LSP when an ESLint configuration file is detected in your project.
Features
- 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
Installation
bun add opencode-eslint-formatteror
npm install opencode-eslint-formatterUsage
Basic Usage
Create a plugin file in your OpenCode configuration directory:
~/.config/opencode/plugin/eslint-formatter.ts (global) or .opencode/plugin/eslint-formatter.ts (per-project):
import { createEslintFormatterPlugin } from "opencode-eslint-formatter";
export const EslintFormatter = createEslintFormatterPlugin();With Options
import { createEslintFormatterPlugin } from "opencode-eslint-formatter";
export const EslintFormatter = createEslintFormatterPlugin({
enable: true // Set to false to disable the plugin
});How It Works
The plugin:
- 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) - If found, it modifies the OpenCode configuration to:
- Disable Prettier formatter
- Add ESLint as a formatter with
--fixflag - Configure ESLint language server for real-time linting
Configuration Added
When an ESLint configuration is detected, the plugin adds:
{
"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"]
}
}
}Requirements
- OpenCode with plugin support
- ESLint configuration file in your project
yarnandeslintinstalled in your projectvscode-eslint-language-serverfor LSP support (install globally or in your project)
Development
To run tests:
bun testTo type-check:
bun tscLicense
MIT
