0Pricing
JavaScript Academy · Lesson

Linting with ESLint; Prettier formatting

Catch common issues with ESLint and auto-format with Prettier. Keep configs tiny and run via npm scripts.

Why lint & format?

Goal: Keep code clean and consistent.

  • ESLint → catches issues
  • Prettier → formats code
  • Tiny configs; run via npm scripts
  • Beginner-friendly defaults
Linting with ESLint; Prettier formatting — illustration 1

ESLint: catch issues

ESLint enforces rules to catch mistakes and improve style; here we emulate a few simple checks.

// Tiny "lint" demo: simple checks on a string of code
const sample = "const x=1; console.log(x)";

function lint(code) {
  const issues = [];
  if (code.includes("console.log")) {
    issues.push("no-console: avoid console.log in production code");
  }
  if (code.includes("=1;")) {
    issues.push("spacing: add spaces around = for readability");
  }
  if (!code.trim().endsWith(";")) {
    issues.push("semi: missing semicolon");
  }
  return issues;
}

console.log("lint issues:", lint(sample));
Linting with ESLint; Prettier formatting — illustration 2

All lessons in this course

  1. Test mindset — tiny assertions, AAA, red→green→refactor
  2. Linting with ESLint; Prettier formatting
  3. CI basics — run lint/test on every push
← Back to JavaScript Academy