JS Guide
HomeQuestionsSearchResources
Search

Built for developers preparing for JavaScript, React & TypeScript interviews.

ResourcesQuestionsSupport
HomeQuestionsSearchProgress
HomeQuestionstooling
PrevNext
tooling
junior
linting

What is ESLint and why should you use it?

eslint
linting
code-quality
static-analysis
Quick Answer

ESLint is a JavaScript/TypeScript linter that analyzes code for potential errors, style issues, and best practices. It catches bugs before runtime, enforces consistent code style, and can automatically fix many issues. Essential for team projects.

Detailed Explanation

What ESLint Does:

  • Finds potential bugs/errors
  • Enforces coding style
  • Catches problematic patterns
  • Auto-fixes many issues

Why Use ESLint:

  1. Catch errors before runtime
  2. Enforce team style guides
  3. Improve code quality
  4. Reduce code review friction

Configuration:

  • .eslintrc.js or eslint.config.js
  • Extends popular configs
  • Custom rules per project
  • IDE integration

Popular Configs:

  • eslint:recommended
  • plugin:react/recommended
  • @typescript-eslint

Code Examples

ESLint configuration
// eslint.config.js (flat config - new style)
import js from '@eslint/js';
import react from 'eslint-plugin-react';
import typescript from '@typescript-eslint/eslint-plugin';

export default [
  js.configs.recommended,
  {
    files: ['**/*.{js,jsx,ts,tsx}'],
    plugins: {
      react,
      '@typescript-eslint': typescript,
    },
    rules: {
      'no-unused-vars': 'warn',
      'no-console': ['warn', { allow: ['warn', 'error'] }],
      'react/prop-types': 'off',
      '@typescript-eslint/no-explicit-any': 'warn',
    },
  },
];

// .eslintrc.js (legacy config style)
module.exports = {
  env: {
    browser: true,
    es2021: true,
    node: true,
  },
  extends: [
    'eslint:recommended',
    'plugin:react/recommended',
    'plugin:@typescript-eslint/recommended',
  ],
  rules: {
    'no-unused-vars': 'warn',
    'no-console': 'warn',
  },
};

Resources

ESLint Documentation

docs

Related Questions

What is Prettier and how does it differ from ESLint?

junior
formatting

How do you configure TypeScript for a project?

mid
typescript
Previous
What is npm and how do you manage packages with it?
Next
What is Prettier and how does it differ from ESLint?