Pre-commit -Werror does not cover unused imports #425

Open
opened 2026-08-20 19:11:48 +00:00 by mph · 0 comments
Owner

Problem

.git-hooks/pre-commit:36 runs

scala-cli compile --scalac-option -Werror core/

and reports "warnings as errors". The label is narrower than it sounds. -Werror
promotes only warnings the compiler emits, and Scala 3 keeps the whole
-Wunused family off by default. Nothing in it has ever been reported: unused
imports, locals, privates, params, implicits.

The gate has therefore never covered unused code, and the count has drifted.
Measured against main on 2026-08-20:

scala-cli compile --scalac-option -Werror core/               -> clean
... -Werror -Wunused:imports                                 -> 33 unused
                                                                imports,
                                                                19 files

One of the 33 is core/adapters/SessionHooks.scala:7
(import iw.core.output.Output), which is also a layering breach:
core/CLAUDE.md:29 allows adapters/ to import model/ only. The unused-import
gap and that breach are the same finding seen twice, and one cleanup closes both.

Found while working IW-422; recorded in that issue's LESSONS.md. Pre-existing,
unrelated to the herdr backend, and deliberately left out of IW-422's scope
because it touches 19 files and would swamp that diff.

Scope

  • Add the unused-import check to .git-hooks/pre-commit.
  • Clear the 33 unused imports it reports.

Both halves must land together: the flag alone blocks every commit.

Notes for whoever takes it

  • Verify the gate actually fails. scala-cli compile exited 0 while
    printing [error] unused import lines. Confirm the hook rejects a real
    violation before trusting it — otherwise this issue adds a flag that reports
    and does not block.
  • -Wunused:imports vs -Wunused:all was not measured. all also covers
    locals, privates, params and implicits; the count will be larger and some of it
    will be genuine (unused params in interface implementations). Measure both,
    then choose. Do not widen without looking.
  • Consider whether dashboard/ needs the same treatment. Only core/ was
    measured — the hook compiles only core/.

Acceptance

  • The pre-commit hook reports unused imports and blocks a commit that adds one,
    verified against a deliberate violation.
  • core/ compiles clean under the widened flag.
  • core/adapters/SessionHooks.scala no longer imports iw.core.output.
## Problem `.git-hooks/pre-commit:36` runs scala-cli compile --scalac-option -Werror core/ and reports "warnings as errors". The label is narrower than it sounds. `-Werror` promotes only warnings the compiler **emits**, and Scala 3 keeps the whole `-Wunused` family off by default. Nothing in it has ever been reported: unused imports, locals, privates, params, implicits. The gate has therefore never covered unused code, and the count has drifted. Measured against `main` on 2026-08-20: scala-cli compile --scalac-option -Werror core/ -> clean ... -Werror -Wunused:imports -> 33 unused imports, 19 files One of the 33 is `core/adapters/SessionHooks.scala:7` (`import iw.core.output.Output`), which is also a layering breach: `core/CLAUDE.md:29` allows `adapters/` to import `model/` only. The unused-import gap and that breach are the same finding seen twice, and one cleanup closes both. Found while working IW-422; recorded in that issue's `LESSONS.md`. Pre-existing, unrelated to the herdr backend, and deliberately left out of IW-422's scope because it touches 19 files and would swamp that diff. ## Scope - Add the unused-import check to `.git-hooks/pre-commit`. - Clear the 33 unused imports it reports. Both halves must land together: the flag alone blocks every commit. ## Notes for whoever takes it - **Verify the gate actually fails.** `scala-cli compile` exited `0` while printing `[error] unused import` lines. Confirm the hook rejects a real violation before trusting it — otherwise this issue adds a flag that reports and does not block. - **`-Wunused:imports` vs `-Wunused:all` was not measured.** `all` also covers locals, privates, params and implicits; the count will be larger and some of it will be genuine (unused params in interface implementations). Measure both, then choose. Do not widen without looking. - Consider whether `dashboard/` needs the same treatment. Only `core/` was measured — the hook compiles only `core/`. ## Acceptance - The pre-commit hook reports unused imports and blocks a commit that adds one, verified against a deliberate violation. - `core/` compiles clean under the widened flag. - `core/adapters/SessionHooks.scala` no longer imports `iw.core.output`.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
iterative-works/iw-cli#425
No description provided.