xiaohongshu
xiaohongshu
linting-workflow
Generic linting workflow for multiple languages with auto-fix and error resolution guidance
Full skill instructions
I provide a generic linting workflow that can be adapted for multiple languages:
Use this framework when:
This is a framework skill - it provides linting logic that other skills extend.
Purpose: Determine which language and linter to use
Detection Logic:
# 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 |
Purpose: Identify which linter is available and configured
# 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
# 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
Purpose: Determine how to run linter commands
Package Manager Detection:
| Language | Manager | Detection | Run Command |
|---|---|---|---|
| JavaScript/TypeScript | npm | package-lock.json exists | npm run <script> |
| JavaScript/TypeScript | yarn | yarn.lock exists | yarn <script> |
| JavaScript/TypeScript | pnpm | pnpm-lock.yaml exists | pnpm run <script> |
| Python | Poetry | pyproject.toml exists | poetry run <script> |
| Python | pip | requirements.txt exists | python -m <script> or <script> |
Implementation:
# Detect package manager
if [ -f "package-lock.json" ]; then
PKG_MANAGER="npm"
RUN_CMD="npm run"
elif [ -f "yarn.lock" ]; then
PKG_MANAGER="yarn"
RUN_CMD="yarn"
elif [ -f "pnpm-lock.yaml" ]; then
PKG_MANAGER="pnpm"
RUN_CMD="pnpm run"
elif command -v poetry &>/dev/null && [ -f pyproject.toml ]; then
PKG_MANAGER="poetry"
RUN_CMD="poetry run"
else
PKG_MANAGER="pip"
RUN_CMD="" # Direct command
fi
echo "Package manager: $PKG_MANAGER"
Purpose: Build the appropriate command to run the linter
JavaScript/TypeScript (ESLint):
# Run ESLint with package manager
if [ "$PKG_MANAGER" = "npm" ]; then
LINT_CMD="npm run lint"
LINT_FIX_CMD="npm run lint -- --fix"
elif [ "$PKG_MANAGER" = "yarn" ]; then
LINT_CMD="yarn lint"
LINT_FIX_CMD="yarn lint --fix"
elif [ "$PKG_MANAGER" = "pnpm" ]; then
LINT_CMD="pnpm run lint"
LINT_FIX_CMD="pnpm run lint --fix"
else
# Direct ESLint command
LINT_CMD="npx eslint ."
LINT_FIX_CMD="npx eslint . --fix"
fi
echo "Lint command: $LINT_CMD"
echo "Auto-fix command: $LINT_FIX_CMD"
Python (Ruff):
# Run Ruff with package manager
if [ "$PKG_MANAGER" = "poetry" ]; then
LINT_CMD="poetry run ruff check ."
LINT_FIX_CMD="poetry run ruff check . --fix"
else
# Direct Ruff command
LINT_CMD="ruff check ."
LINT_FIX_CMD="ruff check . --fix"
fi
echo "Lint command: $LINT_CMD"
echo "Auto-fix command: $LINT_FIX_CMD"
Purpose: Execute linter to check code quality
Implementation:
# Run linter
echo ""
echo "🔍 Running linter..."
echo ""
$LINT_CMD
# Capture exit code
LINT_EXIT_CODE=$?
if [ $LINT_EXIT_CODE -eq 0 ]; then
echo ""
echo "✅ No linting errors found!"
else
echo ""
echo "❌ Linting errors found (exit code: $LINT_EXIT_CODE)"
fi
Linting Output Categories:
| Category | Description |
|---|---|
| Syntax Errors | Invalid syntax that prevents code from running |
| Style Violations | Code doesn't follow style guidelines |
| Potential Bugs | Code patterns that may cause bugs |
| Deprecation Warnings | Use of deprecated features |
| Type Errors (TypeScript) | Type mismatches or missing type definitions |
| Missing Docstrings | Functions/classes without documentation (industry best practice) |
Purpose: Use linter's auto-fix capability to resolve fixable errors
Implementation:
if [ $LINT_EXIT_CODE -ne 0 ]; then
read -p "Apply auto-fix for linting errors? (y/n): " APPLY_FIX
if [ "$APPLY_FIX" = "y" ]; then
echo ""
echo "🔧 Applying auto-fix..."
echo ""
# Run auto-fix command
$LINT_FIX_CMD
# Capture exit code
FIX_EXIT_CODE=$?
if [ $FIX_EXIT_CODE -eq 0 ]; then
echo ""
echo "✅ Auto-fix applied successfully!"
else
echo ""
echo "⚠️ Auto-fix completed with errors (exit code: $FIX_EXIT_CODE)"
echo "Some errors may require manual fixing."
fi
# Re-run linting to check remaining errors
echo ""
echo "🔍 Re-running linter to check remaining errors..."
echo ""
$LINT_CMD
fi
fi
Auto-Fix Capabilities:
| Linter | Auto-Fix | What It Fixes |
|---|---|---|
| ESLint | --fix | Style violations, unused variables, simple syntax issues |
| Prettier | --write | Formatting, indentation, quotes |
| Ruff | --fix | Style violations, unused imports, simple refactorings |
| Black | Direct | Formatting, indentation, line length |
Purpose: Show user which files and lines have linting errors
Implementation:
# Get linting errors (language-specific)
if [ "$LINTER" = "eslint" ]; then
# ESLint JSON output
$LINT_CMD --format json > /tmp/lint-results.json
cat /tmp/lint-results.json | jq -r '.[] | "\(.filePath):\(.message) at line \(.line)"'
elif [ "$LINTER" = "ruff" ]; then
# Ruff output
$LINT_CMD --output-format concise
fi
# Summary
echo ""
echo "📊 Linting Error Summary:"
echo ""
echo "Total errors: <count>"
echo "Files affected: <count>"
echo "Most common error: <error type>"
Purpose: Provide step-by-step guidance for fixing common linting errors
Common Error Categories:
| Error Type | Description | Fix |
|---|---|---|
| Unused variables | Variables defined but never used | Remove or use variable |
| Missing semicolons | Missing semicolons in JavaScript | Add semicolons |
| Unused imports | Imports not used in file | Remove import |
| React hooks violations | Incorrect React hook usage | Fix hook dependencies/rules |
| No-unused-vars | Variables declared but not used | Remove or use variable |
| prefer-const | Variables could be const | Change let to const |
| Error Type | Description | Fix |
|---|---|---|
| F401 | Unused imports | Remove unused import |
| F841 | Unused variables | Remove or use variable |
| E501 | Line too long | Break long lines |
| W291 | Trailing whitespace | Remove trailing spaces |
| E722 | Missing docstring | Add function docstring |
| F821 | Redefinition of variable | Rename variable |
Resolution Guidance Template:
For each error found:
1. **File: <file>**
Line: <line number>
Error: <error message>
2. **Recommended Fix:**
<step-by-step fix instructions>
3. **Example:**
```<language>
# Before (incorrect)
<code>
# After (corrected)
<code>
### Step 9: Re-Verify After Manual Fixes
**Purpose**: Re-run linting after user manually fixes errors
**Implementation**:
```bash
echo ""
read -p "Have you manually fixed the errors? Re-run linting? (y/n): " RE_RUN
if [ "$RE_RUN" = "y" ]; then
echo ""
echo "🔍 Re-running linter..."
echo ""
$LINT_CMD
if [ $? -eq 0 ]; then
echo ""
echo "✅ All linting errors resolved!"
else
echo ""
echo "⚠️ Some errors remain. Please review and fix."
fi
fi
Purpose: Commit linting fixes as separate commit (optional)
Implementation:
# Check if there are changes to commit
GIT_STATUS=$(git status --porcelain)
if [ -n "$GIT_STATUS" ]; then
echo ""
read -p "Commit linting fixes? (y/n): " COMMIT_FIXES
if [ "$COMMIT_FIXES" = "y" ]; then
git add .
git commit -m "Fix linting errors"
echo ""
echo "✅ Linting fixes committed"
fi
else
echo ""
echo "No changes to commit."
fi
Commit Message Options:
| Context | Commit Message |
|---|---|
| General fixes | Fix linting errors |
| ESLint fixes | Fix ESLint errors |
| Ruff fixes | Fix Ruff linting errors |
| Specific fixes | Fix <error type> errors |
Purpose: Verify all public functions, classes, and methods have proper docstrings
Implementation:
echo ""
echo "📝 Checking docstrings..."
echo ""
# Check for undocumented functions/classes
UNDOC_COUNT=0
MISSING_DOCSTRINGS=()
for file in $(git diff --name-only HEAD~1..HEAD); do
case "$file" in
*.py)
UNDOC=$(grep -c 'def ' "$file" - $(grep -c '"""' "$file"))
FUNCTIONS=$(grep -c 'def ' "$file")
;;
*.java)
UNDOC=$(grep -c 'public.*(' "$file" - $(grep -c '/\*\*' "$file"))
METHODS=$(grep -c 'public.*(' "$file")
;;
*.ts|tsx)
UNDOC=$(grep -c 'function' "$file" - $(grep -c '/\*\*' "$file"))
FUNCTIONS=$(grep -c 'function ' "$file")
;;
*.cs|csx)
UNDOC=$(grep -c 'public.*(' "$file" - $(grep -c '///' "$file"))
METHODS=$(grep -c 'public.*(' "$file")
;;
esac
if [[ $UNDOC -gt 0 ]]; then
UNDOC_COUNT=$((UNDOC_COUNT + UNDOC))
MISSING_DOCSTRINGS+=("$file")
fi
done
if [[ $UNDOC_COUNT -gt 0 ]]; then
echo ""
echo "❌ Found $UNDOC_COUNT undocumented items:"
for item in "${MISSING_DOCSTRINGS[@]}"; do
echo " - $item"
done
echo ""
echo "💡 Consider using 'docstring-generator' skill to add missing documentation"
else
echo ""
echo "✅ All functions/classes have docstrings!"
fi
Docstring Check Results:
Language-Specific Docstring Standards:
| Language | Docstring Format | Key Tags/Sections |
|---|---|---|
| Python | PEP 257 (Google, NumPy, Sphinx) | Args, Returns, Raises |
| Java | Javadoc | @param, @return, @throws, @see |
| TypeScript | JSDoc/TSDoc | @param, @returns, @throws, @type |
| C# | XML Documentation Comments | <summary>, <param>, <returns>, <exception> |
ESLint Configuration Files (in priority order):
eslint.config.ts / eslint.config.mjs / eslint.config.js (ESLint 9+).eslintrc.json.eslintrc.js.eslintrc.yamlpackage.json (in eslintConfig field)Common ESLint Rules:
no-unused-vars: Detect unused variablesno-console: Detect console statementsprefer-const: Suggest using const over leteqeqeq: Enforce === instead of ==no-var: Require let/const instead of varRuff Configuration Files:
pyproject.toml (in [tool.ruff] section).ruff.tomlruff.tomlCommon Ruff Rules:
F401: Unused importsF841: Unused variablesE501: Line too long (> 88 characters)W291: Trailing whitespaceE722: Missing docstringsI001: Import orderingIssue: Linter is not installed or not found in PATH
Solution:
# JavaScript/TypeScript: Install ESLint
npm install --save-dev eslint
# Python: Install Ruff
pip install ruff
# Or with Poetry
poetry add --group dev ruff
Issue: Linter cannot find configuration file
Solution:
# Verify config file exists
ls -la | grep -E "(eslint|ruff|pylint)"
# Create default config if missing
# ESLint
cat > .eslintrc.json <<EOF
{
"extends": "eslint:recommended",
"rules": {}
}
EOF
# Ruff
cat > pyproject.toml <<EOF
[tool.ruff]
line-length = 88
target-version = "py311"
EOF
Issue: Large number of linting errors at once
Solution:
Issue: --fix flag doesn't resolve errors
Solution:
Issue: Linting fixes conflict with other uncommitted changes
Solution:
# Stage only linting fixes
git add <files-with-linting-fixes>
# Commit linting fixes separately
git commit -m "Fix linting errors"
Before linting:
After linting:
After committing fixes:
# JavaScript/TypeScript
npm run lint # Run linter
npm run lint -- --fix # Run linter with auto-fix
npm install --save-dev eslint # Install ESLint
npx eslint . # Run ESLint directly
# Python
poetry run ruff check . # Run Ruff with Poetry
poetry run ruff check . --fix # Run Ruff with auto-fix
ruff check . # Run Ruff directly
pip install ruff # Install Ruff
# Git
git add . # Stage changes
git commit -m "Fix linting" # Commit changes
git status # Check git status
Language-specific linting skills that use this framework:
python-ruff-linter: Python-specific Ruff linting guidancejavascript-eslint-linter: JavaScript/TypeScript-specific ESLint guidanceSupporting framework skills:
pr-creation-workflow: For running linting before PR creationtest-generator-framework: For ensuring code quality before testingxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience