ESLint and Prettier interview questions

33 questions from the ESLint and Prettier: Code Quality and Formatting course, each with the correct answer and an explanation. Try to answer before you open the answer.

Module 1: Getting Started

1. What is the main difference between ESLint and Prettier?

  1. They do the same thing.
  2. ESLint catches errors; Prettier formats code.
  3. Prettier catches errors; ESLint formats code.
  4. They are the same tool
Show answer

Answer: ESLint catches errors; Prettier formats code.

ESLint is a linter (quality checker), Prettier is a code formatter. They complement each other.

Lesson: Introduction to Code Quality Tools

Module 2: Foundation & Setup

2. What does `npm init @eslint/config` do?

  1. Asks setup questions and creates a config file
  2. Only installs Prettier
  3. Deletes node_modules
  4. Runs your tests
Show answer

Answer: Asks setup questions and creates a config file

It scaffolds an ESLint configuration.

Lesson: Installation & Project Setup

3. In an ESLint 9 flat config, what does the `files` key do?

  1. Limits a config object to matching files
  2. Installs plugins
  3. Deletes files
  4. Sets Prettier options
Show answer

Answer: Limits a config object to matching files

Each config object can target specific globs.

Lesson: ESLint Flat Config Basics

4. What does 'printWidth' control in Prettier?

  1. Number of spaces per indent.
  2. Quote style.
  3. Maximum line length before wrapping.
  4. The size of the config file
Show answer

Answer: Maximum line length before wrapping.

'printWidth' sets the character limit per line (default 80). Longer lines wrap automatically.

Lesson: Prettier Configuration

5. Why install eslint-config-prettier?

  1. To make Prettier faster.
  2. To enable new ESLint rules.
  3. To make Prettier run first
  4. To prevent ESLint and Prettier from conflicting over formatting.
Show answer

Answer: To prevent ESLint and Prettier from conflicting over formatting.

eslint-config-prettier disables ESLint rules that conflict with Prettier, ensuring they work harmoniously.

Lesson: Integrating ESLint and Prettier

Module 3: Core Concepts

6. What does severity 'error' mean?

  1. Blocks the build; must be fixed.
  2. Just a warning, doesn't block build.
  3. The rule is disabled.
  4. The rule only runs on Fridays
Show answer

Answer: Blocks the build; must be fixed.

'error' severity prevents the build from succeeding until the issue is resolved.

Lesson: Understanding ESLint Rules

7. What does eslint-plugin-react check?

  1. Only JavaScript syntax errors.
  2. React-specific code like JSX and component patterns.
  3. Performance issues.
  4. Only HTML templates
Show answer

Answer: React-specific code like JSX and component patterns.

eslint-plugin-react provides rules for React-specific patterns, hooks, and best practices.

Lesson: Popular ESLint Plugins

Module 4: Configuration Deep Dive

8. How do you apply different rules to test files in flat config?

  1. Add a config object with a files pattern
  2. Use the env key
  3. Rename the files
  4. Use .eslintignore only
Show answer

Answer: Add a config object with a files pattern

Later matching objects override earlier ones.

Lesson: Targeting Files, Globals & Overrides

9. What does the 'endOfLine' option do?

  1. Sets the line length.
  2. Determines quote style.
  3. Controls line ending style (LF vs CRLF) for cross-platform consistency.
  4. The editor theme
Show answer

Answer: Controls line ending style (LF vs CRLF) for cross-platform consistency.

'endOfLine' prevents line-ending conflicts in Git. 'lf' is standard for most projects; 'crlf' for Windows-only teams.

Lesson: Prettier Advanced Options

Module 5: Code Quality & Best Practices

10. What does 'no-undef' rule catch?

  1. Variables that are never used.
  2. Functions without return statements.
  3. Missing semicolons only
  4. Variables used without being defined.
Show answer

Answer: Variables used without being defined.

'no-undef' prevents runtime errors by catching undefined variable references before the code runs.

Lesson: Common Code Quality Issues

11. Why commit .prettierrc to git?

  1. So all team members format code identically.
  2. To speed up Prettier.
  3. To disable Prettier for some files.
  4. To hide the config from CI
Show answer

Answer: So all team members format code identically.

Shared .prettierrc ensures consistent formatting across the team, eliminating style arguments in code reviews.

Lesson: Formatting Standards & Team Consistency

Module 6: Practical Applications

12. Can --fix solve all ESLint violations?

  1. Yes, it fixes everything.
  2. No, some issues require manual review.
  3. Only for semicolon issues.
  4. Only comments
Show answer

Answer: No, some issues require manual review.

--fix handles many issues but leaves complex or context-dependent problems for human judgment.

Lesson: Fixing Issues Automatically

13. What does formatOnSave do?

  1. Prevents saving if there are linting errors.
  2. Uploads the file to the cloud.
  3. Formats the file automatically when you save it.
  4. Deletes unused files
Show answer

Answer: Formats the file automatically when you save it.

'formatOnSave' is convenient for developers who want Prettier to run without manual commands.

Lesson: Integration with Editor / IDE

Module 7: Advanced Quality Control

14. What does lint-staged do?

  1. Lints all files in the repo.
  2. Stages files automatically.
  3. Installs Node
  4. Runs linters only on files staged for commit.
Show answer

Answer: Runs linters only on files staged for commit.

lint-staged improves speed by checking only changed files, not the entire codebase.

Lesson: Pre-commit Hooks & Husky

15. When should you write a custom ESLint rule?

  1. When your codebase has unique conventions standard rules don't cover.
  2. For all projects.
  3. Only for large teams.
  4. To disable core rules
Show answer

Answer: When your codebase has unique conventions standard rules don't cover.

Custom rules automate enforcement of architectural or style decisions unique to your team.

Lesson: Custom ESLint Rules

Module 8: Integration & CI/CD

16. Why run linting in CI?

  1. To speed up development.
  2. To prevent bad code from merging into main.
  3. To reduce file size.
  4. To shorten file names
Show answer

Answer: To prevent bad code from merging into main.

CI linting is a safety net that catches issues automated tools might miss and enforces standards.

Lesson: CI/CD Pipeline Integration

17. Why create a shared ESLint config package?

  1. To slow down development.
  2. To reduce code.
  3. To ensure all team projects follow the same standards.
  4. To rename branches
Show answer

Answer: To ensure all team projects follow the same standards.

Shared configs maintain consistency across your organization and make onboarding new projects trivial.

Lesson: Team Setup & Shared Configurations

18. What does the --cache flag do?

  1. Stores config in memory.
  2. Increases memory usage.
  3. Uploads lint results
  4. Caches linting results to skip unchanged files on next run.
Show answer

Answer: Caches linting results to skip unchanged files on next run.

--cache significantly speeds up linting by skipping files that haven't changed since the last lint run.

Lesson: Reporting & Performance

Module 9: Advanced Topics

19. How should you upgrade ESLint in a team?

  1. Test locally, fix issues gradually, use --max-warnings during transition.
  2. Upgrade immediately on all machines.
  3. Never upgrade, stay on old versions.
  4. Delete eslint.config.js
Show answer

Answer: Test locally, fix issues gradually, use --max-warnings during transition.

Gradual migration prevents disruption and gives the team time to adapt to new rules.

Lesson: Migrating Between ESLint Versions

20. How do you debug ESLint config issues?

  1. Guess and try random configs.
  2. Use DEBUG=eslint* or eslint --print-config to see active rules.
  3. Restart the editor.
  4. Disable all plugins permanently
Show answer

Answer: Use DEBUG=eslint* or eslint --print-config to see active rules.

Debug output and --print-config help you see which rules are active and why issues occur.

Lesson: Debugging Linting Issues

Module 10: Final Review & Mastery

21. What's a best practice for team adoption?

  1. Enforce all rules as errors immediately.
  2. Disable most rules.
  3. Start with warn, gradually move to error as team adapts.
  4. Skip CI checks
Show answer

Answer: Start with warn, gradually move to error as team adapts.

Gradual enforcement reduces resistance and allows the team to adjust their workflow progressively.

Lesson: Best Practices & Anti-patterns

22. Should you use example configs as-is?

  1. Yes, always copy them exactly
  2. No, adapt them to your project
  3. Only on Fridays
  4. It never matters
Show answer

Answer: No, adapt them to your project

Examples are starting points. Your team's standards and project-specific needs should drive configuration choices.

Lesson: Real-world Project Examples

23. Which config entry should come last so it can turn off formatting rules?

  1. A plugin
  2. js.configs.recommended
  3. eslint-config-prettier
  4. ignores
Show answer

Answer: eslint-config-prettier

Prettier must be last in extends so it takes precedence and resolves any conflicts with ESLint's formatting rules.

Lesson: Interview Questions & Cheat Sheet

24. If a rule isn't applying, what should you check first?

  1. Restart the editor only
  2. Delete the config and start over
  3. Use npx eslint --print-config on the file
  4. Uninstall ESLint
Show answer

Answer: Use npx eslint --print-config on the file

--print-config shows the effective configuration ESLint is using, revealing if a rule is active or disabled.

Lesson: Troubleshooting & Common Gotchas

25. What is a good next step in mastering code quality?

  1. Stop using linters
  2. Use defaults for everything forever
  3. Ignore CI
  4. Apply ESLint and Prettier to your next project
Show answer

Answer: Apply ESLint and Prettier to your next project

The best way to master these tools is to use them. Start with a simple setup and refine it over time based on your team's needs.

Lesson: Summary & Next Steps

26. What is ESLint's main job?

  1. Compile code
  2. Deploy apps
  3. Find problems and enforce code-quality rules
  4. Minify CSS
Show answer

Answer: Find problems and enforce code-quality rules

Prettier handles formatting.

Lesson: Summary & Next Steps

27. What does Prettier do?

  1. Finds undefined variables
  2. Runs tests
  3. Bundles files
  4. Formats code consistently
Show answer

Answer: Formats code consistently

It rewrites code to one consistent style.

Lesson: Summary & Next Steps

28. Which file holds ESLint 9's default configuration?

  1. eslint.config.js
  2. package-lock.json
  3. .eslintrc.json
  4. .prettierrc
Show answer

Answer: eslint.config.js

Flat config is the default since ESLint 9.

Lesson: Summary & Next Steps

29. Where should eslint-config-prettier go in your config?

  1. First
  2. Last
  3. It does not matter
  4. In .gitignore
Show answer

Answer: Last

Later entries override earlier formatting rules.

Lesson: Summary & Next Steps

30. What does severity 'error' do?

  1. Only warns
  2. Disables the rule
  3. Fails the lint run
  4. Fixes the code
Show answer

Answer: Fails the lint run

Errors cause a non-zero exit code.

Lesson: Summary & Next Steps

31. What does lint-staged do?

  1. Lints the whole repo
  2. Stages files automatically
  3. Installs Husky
  4. Runs linters on staged files only
Show answer

Answer: Runs linters on staged files only

It keeps pre-commit hooks fast.

Lesson: Summary & Next Steps

32. Why run lint and format checks in CI?

  1. To block problem code from merging
  2. To make builds slower
  3. To delete files
  4. To rename branches
Show answer

Answer: To block problem code from merging

CI enforces rules for everyone.

Lesson: Summary & Next Steps

33. How should a team adopt new rules?

  1. Enable all as errors at once
  2. Start with warn and tighten gradually
  3. Disable lint
  4. Skip CI
Show answer

Answer: Start with warn and tighten gradually

Gradual rollout reduces friction.

Lesson: Summary & Next Steps

← Back to the course