# Interview Questions & Cheat Sheet — ESLint and Prettier: Code Quality and Formatting

Source: https://www.skillbyai.com/en/eslint-prettier/eslint-prettier-23

> Review core ESLint and Prettier concepts with a cheat sheet of commands and common interview questions.

## Common interview questions

Why use ESLint? How do Prettier and ESLint differ? How to prevent conflicts? What's a custom rule? How to set up pre-commit hooks?

## Quick reference

Essential commands and config snippets for quick lookup.

```bash
# Install
npm install --save-dev eslint @eslint/js prettier eslint-config-prettier

# Configure (creates eslint.config.js)
npm init @eslint/config@latest
echo '{ "singleQuote": true }' > .prettierrc

# Run
npx eslint .
npx prettier --check .

# Fix
npx eslint . --fix
npx prettier --write .

# Hooks (Husky v9)
npm install --save-dev husky lint-staged
npx husky init
echo "npx lint-staged" > .husky/pre-commit
```

Output:

```
Essential commands for ESLint and Prettier workflow
```

## Remember the essentials

1. ESLint finds errors, Prettier formats. 2. Use eslint-config-prettier to prevent conflicts. 3. Commit configs to git. 4. Use --fix and format on save. 5. Run in CI/CD.

Quick check

**Quiz:** Which config entry should come last so it can turn off formatting rules?

- [ ] A plugin
- [ ] js.configs.recommended
- [x] eslint-config-prettier
- [ ] ignores

*Answer:* eslint-config-prettier. Prettier must be last in extends so it takes precedence and resolves any conflicts with ESLint's formatting rules.
