--- name: linting-workflow description: Generic linting workflow for multiple languages with auto-fix and error resolution guidance license: Apache-2.0 compatibility: opencode metadata: audience: developers workflow: code-quality --- ## What I do I provide a generic linting workflow that can be adapted for multiple languages: 1. **Detect Language**: Automatically detect project language (JavaScript/TypeScript, Python, etc.) 2. **Detect Linter**: Identify and configure appropriate linter (ESLint, Ruff, etc.) 3. **Detect Package Manager**: Determine package manager for running linter commands 4. **Run Linting**: Execute linter with appropriate command 5. **Apply Auto-Fix**: Use linter's auto-fix capability when available 6. **Guide Error Resolution**: Provide step-by-step guidance for fixing linting errors 7. **Verify Fixes**: Re-run linting to ensure all errors are resolved 8. **Commit Fixes**: Optionally commit linting fixes as separate commit ## When to use me Use this framework when: - You need to lint code before committing or creating PRs - You want to ensure code follows industry standards and style guidelines - You're building a workflow skill that includes code quality checks - You need linting for multiple languages in a consistent way - You want to integrate linting into automated workflows (PR creation, etc.) This is a **framework skill** - it provides linting logic that other skills extend. ## Core Workflow Steps ### Step 1: Detect Project Language **Purpose**: Determine which language and linter to use **Detection Logic**: ```bash # Check for language indicators if [ -f "package.json" ]; then LANGUAGE="javascript" # Further check TypeScript if [ -f "tsconfig.json" ] || grep -q "typescript" package.json; then LANGUAGE="typescript" fi elif [ -f "pyproject.toml" ] || [ -f "requirements.txt" ] || [ -f "setup.py" ]; then LANGUAGE="python" elif [ -f "go.mod" ]; then LANGUAGE="go" elif [ -f "Gemfile" ]; then LANGUAGE="ruby" else echo "Unable to detect language. Please specify manually." exit 1 fi echo "Detected language: $LANGUAGE" ``` **Language Detection Summary**: | Indicator | Language | Linter | |-----------|----------|---------| | `package.json` + `tsconfig.json` | TypeScript | ESLint | | `package.json` | JavaScript | ESLint | | `pyproject.toml` or `requirements.txt` | Python | Ruff | | `go.mod` | Go | golint, golangci-lint | | `Gemfile` | Ruby | RuboCop | ### Step 2: Detect Linter and Configuration **Purpose**: Identify which linter is available and configured #### JavaScript/TypeScript Linter Detection: ```bash # Check package.json for ESLint if grep -q "\"eslint\"" package.json; then LINTER="eslint" # Check for ESLint config ESLINT_CONFIG="" [ -f ".eslintrc.json" ] && ESLINT_CONFIG=".eslintrc.json" [ -f ".eslintrc.js" ] && ESLINT_CONFIG=".eslintrc.js" [ -f "eslint.config.js" ] && ESLINT_CONFIG="eslint.config.js" [ -f "eslint.config.mjs" ] && ESLINT_CONFIG="eslint.config.mjs" [ -f "eslint.config.ts" ] && ESLINT_CONFIG="eslint.config.ts" echo "Detected linter: ESLint" echo "Config file: $ESLINT_CONFIG" # Check for other linters elif grep -q "\"prettier\"" package.json; then LINTER="prettier" echo "Detected linter: Prettier" elif grep -q "\"stylelint\"" package.json; then LINTER="stylelint" echo "Detected linter: Stylelint" fi ``` #### Python Linter Detection: ```bash # Check for Ruff if grep -q "ruff" pyproject.toml 2>/dev/null || grep -q "ruff" requirements.txt 2>/dev/null; then LINTER="ruff" echo "Detected linter: Ruff" # Check for other linters elif grep -q "flake8" requirements.txt 2>/dev/null; then LINTER="flake8" echo "Detected linter: Flake8" elif grep -q "pylint" requirements.txt 2>/dev/null; then LINTER="pylint" echo "Detected linter: Pylint" elif grep -q "black" requirements.txt 2>/dev/null; then LINTER="black" echo "Detected linter: Black" fi ``` ### Step 3: Detect Package Manager **Purpose**: Determine how to run linter commands **Package Manager Detection**: | Language | Manager | Detection | Run Command | |----------|-----------|------------|-------------| | JavaScript/TypeScript | npm | `package-lock.json` exists | `npm run