This project uses ESLint and Prettier to maintain consistent code quality and formatting across the codebase, regardless of the IDE or editor used (VSCode, WebStorm, Sublime, etc.).
- ESLint: Code linting and quality checking
- Prettier: Code formatting
- EditorConfig: Base editor configuration
- Husky: Git hooks management
- lint-staged: Run linters on staged files
VSCode:
- ESLint (
dbaeumer.vscode-eslint) - Prettier (
esbenp.prettier-vscode) - EditorConfig (
editorconfig.editorconfig)
WebStorm/IntelliJ:
- ESLint (built-in, enable in preferences)
- Prettier (built-in, enable in preferences)
- EditorConfig (built-in support)
ESLint v9 flat configuration with:
- Node.js environment settings
- Prettier integration
- Code quality rules
- Ignores for
node_modules,dist, etc.
Prettier formatting rules:
- Tab indentation (width: 4)
- 100 character line width
- Trailing commas
- Arrow parentheses avoidance
EditorConfig for basic editor settings:
- UTF-8 encoding
- LF line endings
- Tab indentation
- Trim trailing whitespace
- Insert final newline
VSCode-specific settings:
- Auto-format on save
- ESLint auto-fix on save
- Prettier as default formatter
# Check for linting errors
npm run lint
# Fix auto-fixable linting errors
npm run lint:fix# Format all files
npm run format
# Check if files are formatted correctly (CI)
npm run format:check# Lint entire project
npm run lint
# Lint specific file
npx eslint path/to/file.js
# Lint and fix
npx eslint path/to/file.js --fix# Format entire project
npm run format
# Format specific file
npx prettier --write path/to/file.js
# Check formatting without modifying
npx prettier --check "**/*.js"VSCode:
- Install recommended extensions
- Settings are already configured in
.vscode/settings.json - Code will auto-format on save
- ES Lint errors will show in Problems panel
WebStorm:
- Enable ESLint:
Preferences → Languages & Frameworks → JavaScript → Code Quality Tools → ESLint → Enable - Enable Prettier:
Preferences → Languages & Frameworks → JavaScript → Prettier → Enable - Enable "Run eslint --fix on save"
- Enable "On save" for Prettier
Git hooks automatically run linting and formatting before each commit.
- lint-staged runs on staged files
- Prettier formats all staged files (and auto-fixes formatting)
- ESLint checks for code quality issues
- If ANY linting error is found, the commit is blocked and errors are displayed
- You must fix the errors manually and try committing again
.husky/pre-commit:
npx lint-stagedpackage.json (lint-staged section):
{
"lint-staged": {
"*.js": ["eslint", "prettier --write"],
"*.{json,md,yml,yaml}": ["prettier --write"]
}
}# Skip pre-commit hooks (NOT RECOMMENDED)
git commit --no-verify -m "Emergency commit"| Rule | Description | Auto-fix |
|---|
| Type | Convention | Example |
|---|---|---|
| Files/Folders | kebab-case |
user-controller.js, utils/ |
Note: We strictly enforce
kebab-casefor all file and folder names.
| no-console | Allow console statements | N/A |
| no-unused-vars | Prevent unused variables (prefix with _ to ignore) | ❌ |
| prefer-const | Use const for variables that are never reassigned | ✅ |
| no-var | Disallow var, use let or const | ✅ |
| eqeqeq | Require === and !== instead of == and != | ❌ |
| curly | Require curly braces for all control statements | ✅ |
| no-param-reassign | Prevent reassigning function parameters | ❌ |
| prefer-arrow-callback | Prefer arrow functions for callbacks | ✅ |
| prettier/prettier | Enforce Prettier formatting | ✅ |
Single line:
// eslint-disable-next-line no-console
console.log("This is allowed");Entire file:
/* eslint-disable no-console */
console.log("File-wide exception");Specific rule for function:
/* eslint-disable no-param-reassign */
function modifyParam(obj) {
obj.modified = true;
}
/* eslint-enable no-param-reassign */Unused variables (prefix with underscore):
const { name, _unusedField } = user; // _unusedField won't trigger error- Indentation: Tabs (width: 4)
- Line width: 100 characters
- Quotes: Double quotes (auto)
- Semicolons: Automatic
- Trailing commas: Always
- Arrow parens: Avoid when possible
Before:
function example(a, b, c) {
const result = { name: "John", age: 30 };
if (a == b) return result;
}After:
function example(a, b, c) {
\tconst result = { name: 'John', age: 30 };
\tif (a === b) {
\t\treturn result;
\t}
}name: Code Quality
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "20"
- run: npm ci
- run: npm run lint
- run: npm run format:checkVSCode:
- Check ESLint extension is installed
- Check "ESLint" appears in status bar
- Reload window:
Cmd/Ctrl + Shift + P→ "Reload Window" - Check output:
View → Output → Select "ESLint"
WebStorm:
File → Invalidate Caches → Restart- Verify ESLint is enabled in preferences
- Check "ESLint" in bottom status bar shows green checkmark
VSCode:
- Verify
.vscode/settings.jsonexists - Check
editor.formatOnSaveistrue - Ensure Prettier extension is installed
- Check file is in workspace (not just opened externally)
WebStorm:
- Enable "Actions on Save" in preferences
- Check "Reformat code" is enabled
- Verify Prettier is set as default formatter
# Reinstall husky
rm -rf .husky
npm run prepare
# Make hook executable
chmod +x .husky/pre-commit
# Test manually
.husky/pre-commitSome errors require manual fixing:
- Unused variables - Remove or prefix with
_ ==vs===- Change to strict equality- Parameter reassignment - Refactor code
- Undefined variables - Import or define them
# See which errors can be auto-fixed
npm run lint -- --fix-dry-run✅ Always run linting before committing (automated via pre-commit)
✅ Fix linting errors, don't disable rules unless absolutely necessary
✅ Use consistent formatting across all files
✅ Review lint errors carefully - they often catch real bugs
✅ Keep IDE extensions updated for best compatibility
✅ Follow the configured style guide (tabs, line width, etc.)
✅ Prefix unused parameters with _ to avoid errors
✅ Use strict equality (===) instead of loose (==)
.
├── eslint.config.js # ESLint configuration (v9 flat config)
├── .prettierrc # Prettier formatting rules
├── .editorconfig # Base editor settings
├── .vscode/
│ ├── settings.json # VSCode project settings
│ └── extensions.json # Recommended extensions
├── .husky/
│ └── pre-commit # Pre-commit hook script
└── package.json
└── lint-staged # Staged files configuration
None required - all configuration is file-based.
ESLint v9 uses flat config (eslint.config.js) instead of .eslintrc.*:
- ✅ Configuration is JavaScript (more flexible)
- ✅ Single config file (no cascading)
- ✅ Better performance
- ✅ Ignores defined in config (no
.eslintignoreneeded)
-
Install dependencies:
npm install --save-dev eslint eslint-config-prettier eslint-plugin-prettier husky lint-staged
-
Copy configuration files:
eslint.config.js.prettierrc.editorconfig.vscode/directory
-
Initialize git hooks:
npm run prepare
-
Fix existing code:
npm run lint:fix npm run format
Edit eslint.config.js:
rules: {
// Add your custom rules
'no-console': 'warn', // Change to warning instead of off
'max-len': ['error', { code: 120 }], // Increase max line length
}Edit .prettierrc:
{
"tabWidth": 2, // Change to 2 spaces
"useTabs": false, // Use spaces instead of tabs
"printWidth": 120 // Increase line width
}For questions or issues, contact: team@thecodebucket.com