| name | javascript-eslint-linter |
| description | Ensure JavaScript/TypeScript code follows industry standards using ESLint linter with linting-workflow framework Use when this capability is needed. |
| metadata | {"author":"darellchua2"} |
What I do
I implement JavaScript/TypeScript-specific ESLint linting by extending the linting-workflow framework:
- Detect JavaScript/TypeScript Environment: Identify JavaScript or TypeScript project (npm, yarn, pnpm)
- Detect ESLint Linter: Check if ESLint is installed and configured
- Delegate to Linting Workflow: Use
linting-workflow for core linting functionality
- Provide JavaScript-Specific Guidance: Help interpret ESLint error codes (no-unused-vars, semi, eqeqeq, etc.)
- Ensure JavaScript Best Practices: Guide on JavaScript/TypeScript style standards and conventions
When to use me
Use this workflow when:
- Writing or modifying JavaScript/TypeScript code that needs to follow industry standards
- Before committing JavaScript/TypeScript changes to ensure code quality
- When you see ESLint linting errors and need help fixing them
- Setting up a new JavaScript/TypeScript project with proper linting configuration
- You want to ensure code quality in automated workflows
Framework: This skill extends linting-workflow for generic linting, adding JavaScript/TypeScript-specific ESLint guidance.
Steps
Step 1: Detect JavaScript/TypeScript Environment
Verify this is a JavaScript/TypeScript project:
ls *.js *.jsx *.ts *.tsx 2>/dev/null
[ -f package.json ] && [ -f package-lock.json ]
Step 2: Detect ESLint Configuration
Check for ESLint in project:
grep -q "eslint" package.json
[ -f .eslintrc.json ] || [ -f .eslintrc.js ] || [ -f .eslintrc.yaml ] || [ -f eslint.config.js ] || [ -f eslint.config.ts ] || [ -f eslint.config.mjs ]
Step 3: Detect TypeScript
Check if this is a TypeScript project:
if [ -f tsconfig.json ]; then
PROJECT_TYPE="typescript"
else
PROJECT_TYPE="javascript"
fi
echo "Project type: $PROJECT_TYPE"
Step 4: Detect Package Manager
Check for package manager:
if [ -f package-lock.json ]; then
PKG_MANAGER="npm"
LINT_CMD="npm run lint"
LINT_FIX_CMD="npm run lint -- --fix"
elif [ -f yarn.lock ]; then
PKG_MANAGER="yarn"
LINT_CMD="yarn lint"
LINT_FIX_CMD="yarn lint --fix"
elif [ -f pnpm-lock.yaml ]; then
PKG_MANAGER="pnpm"
LINT_CMD="pnpm run lint"
LINT_FIX_CMD="pnpm run lint --fix"
fi
echo "Package manager: $PKG_MANAGER"
Step 5: Delegate to Linting Workflow
Use linting-workflow framework for:
- Language detection (JavaScript/TypeScript)
- Linter detection (ESLint)
- Package manager detection (npm/yarn/pnpm)
- Running linting with appropriate commands
- Auto-fix application
- Error resolution guidance
- Verification and re-running
Step 6: JavaScript-Specific ESLint Error Guidance
Common ESLint Error Codes:
| Error Code | Description | Common Fix |
|---|
| no-unused-vars | Variables/imports defined but not used | Remove or use variable/import |
| semi | Missing semicolons | Add semicolons to statements |
| eqeqeq | Use == instead of === | Change == to === |
| no-console | Console statements found | Remove console.log/console.error |
| prefer-const | Variable could be const | Change let to const |
| no-undef | Undefined variable used | Define variable or import |
| quotes | Inconsistent quote style | Use consistent quotes (' or ") |
| indent | Incorrect indentation | Fix indentation level |
| no-trailing-spaces | Trailing whitespace | Remove trailing spaces |
| comma-dangle | Trailing comma in object/array | Remove trailing comma |
| no-extra-semi | Extra semicolon | Remove extra semicolon |
Error Resolution Template:
For each ESLint error found:
1. **File**: <file>
Line: <line>
Column: <column>
Error: <error message>
Code: <no-unused-vars | semi | eqeqeq | etc.>
2. **ESLint Rule Explanation**:
<Description of what ESLint is checking>
3. **Recommended Fix**:
<Step-by-step fix instructions>
4. **Example**:
```javascript
// Before (incorrect)
<code>
// After (corrected)
<code>
- Apply Fix:
## Best Practices
**Refer to `linting-workflow` for general linting best practices.**
JavaScript/TypeScript-specific best practices:
- **ESLint Configuration**: Use ESLint with appropriate plugins for your project
- **TypeScript**: Use `@typescript-eslint/parser` and `@typescript-eslint/eslint-plugin` for TypeScript projects
- **Prettier Integration**: Use eslint-config-prettier for formatting
- **Airbnb Style Guide**: Follow Airbnb JavaScript/TypeScript Style Guide (common industry standard)
- **React Rules**: Use eslint-plugin-react and eslint-plugin-react-hooks for React projects
- **Import Order**: Use eslint-plugin-import for consistent import ordering
- **Accessibility**: Use eslint-plugin-jsx-a11y for React accessibility
- **No Var**: Prefer const/let over var
- **Arrow Functions**: Use arrow functions where appropriate
- **Template Literals**: Use template literals instead of string concatenation
- **Destructuring**: Use destructuring for object/array access
- **ESLint Config**: Configure ESLint in package.json or separate config file
## Common ESLint Issues
### ESLint Not Detected
**Issue**: ESLint is not installed or not found in package.json
**Solution**: Install ESLint:
```bash
# With npm
npm install --save-dev eslint
# With yarn
yarn add --dev eslint
# With pnpm
pnpm add -D eslint
TypeScript ESLint Configuration
Issue: ESLint not configured for TypeScript
Solution: Install TypeScript ESLint packages:
npm install --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin
cat > .eslintrc.json <<EOF
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"plugins": ["@typescript-eslint"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"]
}
EOF
React ESLint Configuration
Issue: ESLint not configured for React
Solution: Install React ESLint packages:
npm install --save-dev eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y
cat > .eslintrc.json <<EOF
{
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended"
],
"plugins": ["react", "react-hooks", "jsx-a11y"],
"rules": {
"react/prop-types": "off",
"react/react-in-jsx-scope": "off"
}
}
EOF
Prettier Integration
Issue: Formatting conflicts between ESLint and Prettier
Solution: Install eslint-config-prettier:
npm install --save-dev eslint-config-prettier eslint-plugin-prettier
cat > .eslintrc.json <<EOF
{
"extends": ["prettier"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error"
}
}
EOF
Troubleshooting Checklist
Before linting:
After linting:
Related Commands
npm run lint
npm run lint -- --fix
npm install --save-dev eslint
yarn lint
yarn lint --fix
yarn add --dev eslint
pnpm run lint
pnpm run lint --fix
pnpm add -D eslint
npx eslint .
npx eslint . --fix
npx eslint . --rule 'no-unused-vars: error'
npx eslint . --fix
npm install --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin
npm install --save-dev eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y
npm install --save-dev eslint-config-prettier eslint-plugin-prettier
Converted and distributed by TomeVault — claim your Tome and manage your conversions.