TOPIC 53/6020 MINNOT STARTED

Keeping test code clean: linting, formatting, hooks and review

Use a linter, a formatter, a type check, a git hook and a short review list so Playwright test code stays tidy and mistakes such as a missing await are caught before they run.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: a workshop where each tool has a hook. You see at once which hook is empty. In a messy workshop you lose ten minutes, and you may grab the wrong tool because it looks the same.

Tom and Leo both write tests for Daily List, a to-do list app. After a few weeks the files look different. One test sleeps for five seconds. Another forgot a small word, await, so it moves on too early.

What it is: Playwright is a free program, made by Microsoft, that drives real browsers from test code. This topic is about keeping that test code tidy. A linter reads code and warns about risky habits. A rewrites spaces and line breaks into one style. A reads TypeScript without running it and reports values used the wrong way. A git hook is a script git runs by itself, for example just before a commit. A code review is a teammate reading the change. Continuous integration (CI) is the shared run that starts when code is pushed. The machines catch the same small slips. People judge whether the test is worth having.

Why it matters: a missing await can pass on a fast laptop and fail on a slow build. A fixed pause makes every run slow and still fails on a bad day. If the linter flags both before the commit, Mei reviews the idea, not the noise.

A tidy file can still test the wrong thing. Someone must still ask what the test proves.

Kept simple: other tools can do these jobs. This lesson uses the ones Playwright's own docs name, plus a formatter.

(SYNTHETIC / TRAINING ONLY: Daily List and every person named here are invented.)

PLAIN WORDS · 2 in this section
playwright
a free Microsoft tool that drives a browser for tests
typescript
JavaScript with added labels for the kinds of data

PICTURE IT

The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.

THE REAL JOB Keeping test code tidy and catching small slips automatically, so people can spend their review on the ideas.

  1. Format
  2. Lint and type check
  3. Hook on commit
  4. Review
Tidy by machine, judged by people

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
The hook on the wall for each toolThe agreed style the formatter enforces
Seeing a missing tool at a glanceThe linter and type check marking a slip
The door lock that stops you leaving with a messThe git hook that blocks a bad commit
The foreman walking roundThe code review

WHERE THIS PICTURE STOPS

  • A tidy workshop does not make a good chair. Clean test code can still test the wrong thing.
  • A wall hook is always there. A git hook can be skipped on one computer.
  • A foreman can see the whole job. A rule only sees what it was told to look for.

HOOK

Tidy by machine, judged by people.

REMEMBER IT THIS WAY

A rule of thumb: if you see this, think that.

If a slip is small and a rule can spot it, let the formatter, linter or catch it. Keep the review for the ideas.

What each part of the trick stands for
In the trickWhat it stands for
Formattertidies the layout
Linterwarns about risky habits
Git hookstops a messy commit

A rule only sees what it was told to look for, so clean test code can still test the wrong thing.

TELL A FRIEND

It is like a workshop where each tool has a hook on the wall, so a missing one shows at once.

OFTEN MIXED UP WITH Best practices and anti-patterns. The best-practices lesson says what good tests look like. This lesson shows the tools that help keep them that way.

Sources & standards — 6 sources
  1. Market practice

    eslint-plugin-playwright (npm package page) ↗ — npm registry page for a community package · The package adds Playwright rules to ESLint; the no-wait-for-timeout rule flags page.waitForTimeout and is in the recommended set (search excerpt, page not opened)

    Describes lint rules for Playwright tests. Community-maintained package, not made by the Playwright team. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number; read at the time of writing. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  2. Market practice

    Husky and lint-staged guide (Better Stack Community) ↗ — Better Stack · A pre-commit hook runs lint-staged on staged files only; if a task fails the commit is blocked (search excerpt, page not opened)

    Practitioner tutorial on git hooks. Commands change between versions, so read the current tool documentation. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number; read at the time of writing. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  3. Market practice

    Best practices (Playwright documentation) ↗ — Microsoft (Playwright) · Test what the user sees, keep tests isolated, prefer role and text locators, use web-first assertions that retry, use TypeScript and ESLint to catch errors early, and run tsc --noEmit in the pipeline (search excerpt, page not opened)

    Recommends user-facing locators such as role-based ones over Cascading Style Sheets (CSS) or XPath, web-first assertions that retry, and avoiding fixed waits. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail. A second search on 2026-10-20 returned this page for its title and matched the described content; the page was still not opened (search excerpt, page not opened).

  4. Market practice

    Auto-waiting (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Says Playwright runs actionability checks (visible, stable, enabled, receives events) before an action and fails with a timeout error if they do not pass in time. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  5. Market practice

    eslint-playwright ↗ — raw.githubusercontent.com · Reviewed 6 November 2026: Installation/usage and selected await/assertion/wait rules only. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Installation/usage and selected await/assertion/wait rules only · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Installation/usage and selected await/assertion/wait rules only. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  6. Market practice

    no-floating-promises | typescript-eslint ↗ — typescript-eslint.io · Reviewed 6 November 2026: no-floating-promises introduction, prerequisites, handled forms and examples only. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    no-floating-promises introduction, prerequisites, handled forms and examples only · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: no-floating-promises introduction, prerequisites, handled forms and examples only. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

PRACTISE AND KEEP

Sources for this topic — 6 sources
  1. Market practice

    eslint-plugin-playwright (npm package page) ↗ — npm registry page for a community package · The package adds Playwright rules to ESLint; the no-wait-for-timeout rule flags page.waitForTimeout and is in the recommended set (search excerpt, page not opened)

    Describes lint rules for Playwright tests. Community-maintained package, not made by the Playwright team. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number; read at the time of writing. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  2. Market practice

    Husky and lint-staged guide (Better Stack Community) ↗ — Better Stack · A pre-commit hook runs lint-staged on staged files only; if a task fails the commit is blocked (search excerpt, page not opened)

    Practitioner tutorial on git hooks. Commands change between versions, so read the current tool documentation. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number; read at the time of writing. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  3. Market practice

    Best practices (Playwright documentation) ↗ — Microsoft (Playwright) · Test what the user sees, keep tests isolated, prefer role and text locators, use web-first assertions that retry, use TypeScript and ESLint to catch errors early, and run tsc --noEmit in the pipeline (search excerpt, page not opened)

    Recommends user-facing locators such as role-based ones over Cascading Style Sheets (CSS) or XPath, web-first assertions that retry, and avoiding fixed waits. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail. A second search on 2026-10-20 returned this page for its title and matched the described content; the page was still not opened (search excerpt, page not opened).

  4. Market practice

    Auto-waiting (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Says Playwright runs actionability checks (visible, stable, enabled, receives events) before an action and fails with a timeout error if they do not pass in time. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  5. Market practice

    eslint-playwright ↗ — raw.githubusercontent.com · Reviewed 6 November 2026: Installation/usage and selected await/assertion/wait rules only. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Installation/usage and selected await/assertion/wait rules only · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Installation/usage and selected await/assertion/wait rules only. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  6. Market practice

    no-floating-promises | typescript-eslint ↗ — typescript-eslint.io · Reviewed 6 November 2026: no-floating-promises introduction, prerequisites, handled forms and examples only. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    no-floating-promises introduction, prerequisites, handled forms and examples only · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: no-floating-promises introduction, prerequisites, handled forms and examples only. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.