Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
ESLint is a static code analysis tool that finds and fixes problems in your JavaScript code. It catches bugs, enforces code style, and helps teams maintain consistent code quality across projects.
Detect bugs before runtime
Consistent code formatting
Fix issues automatically
# Install ESLint
npm install --save-dev eslint
# Initialize configuration
npx eslint --init
# You'll be asked:
# 1. How would you like to use ESLint?
# → To check syntax and find problems
# 2. What type of modules?
# → JavaScript modules (import/export)
# 3. Which framework?
# → React / Vue / None
# 4. Does your project use TypeScript?
# → No / Yes
# 5. Where does your code run?
# → Browser / Node
# 6. What format for config file?
# → JavaScript / JSON / YAML
# Run ESLint
npx eslint yourfile.js
# Fix automatically
npx eslint yourfile.js --fix// .eslintrc.js
module.exports = {
env: {
browser: true,
es2021: true,
node: true
},
extends: [
'eslint:recommended', // ESLint's recommended rules
'plugin:react/recommended', // React rules
'plugin:@typescript-eslint/recommended' // TypeScript
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
ecmaFeatures: {
jsx: true
}
},
rules: {
// Customize rules
'no-console': 'warn', // Warn on console.log
'no-unused-vars': 'error', // Error on unused variables
'semi': ['error', 'always'], // Require semicolons
'quotes': ['error', 'single'], // Single quotes only
'indent': ['error', 2], // 2 spaces indentation
'max-len': ['warn', { code: 80 }], // Line length warning
'no-var': 'error', // No var, use let/const
'prefer-const': 'error', // Use const when possible
'eqeqeq': 'error', // Require === instead of ==
'curly': 'error', // Require curly braces
'arrow-body-style': ['error', 'as-needed']
},
settings: {
react: {
version: 'detect' // Auto-detect React version
}
}
};"error"or2Triggers an error. Exits with error code. Blocks CI/CD pipeline.
"warn"or1Shows a warning. Doesn't fail build. Good for style issues.
"off"or0Disables the rule completely. Rule won't run.
Disallow unused variables
"no-unused-vars": "error"Disallow undefined variables
"no-undef": "error"Require === and !== instead of == and !=
"eqeqeq": "error"Warn about console.log statements
"no-console": "warn"Require let or const instead of var
"no-var": "error"Suggest const for variables never reassigned
"prefer-const": "error"# .eslintignore
# Similar to .gitignore
# Dependencies
node_modules/
bower_components/
# Build output
dist/
build/
*.min.js
# Config files
*.config.js
webpack.config.js
# Test coverage
coverage/
# Specific files
public/vendor/
# Inline ignore (in code)
// eslint-disable-next-line no-console
console.log('Debug info');
/* eslint-disable no-console */
console.log('Line 1');
console.log('Line 2');
/* eslint-enable no-console */Install "ESLint" extension - shows errors while you type
Settings: "editor.codeActionsOnSave": {'source.fixAll.eslint': true}Add lint scripts to your project
"lint": "eslint src/", "lint:fix": "eslint src/ --fix"Run ESLint before commits
npx husky add .husky/pre-commit "npm run lint"Run in GitHub Actions, GitLab CI
- run: npm run lintCatch bugs before runtime
Static code analysis
Consistent code across team
Configurable rules
--fix flag repairs issues
Save time fixing manually
Editor, Git hooks, CI/CD
Catch issues everywhere