Uh oh!
There was an error while loading. Please reload this page.
Docs: Recommend switch expressions in AGENTS.md code style - #17357
Conversation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| - Comments and Javadocs should describe the current behavior or contract, not how it changed over time. | ||
| - `} else {` on same line. Minimize variable scope. `try-with-resources` for all `AutoCloseable`. | ||
| - Prefer method references over lambdas. Wrap lines at the highest semantic level. | ||
| - Prefer switch expressions (`case X -> ...`) over statement switches; an exhaustive enum switch needs no `default`. |
There was a problem hiding this comment.
The current line only tells the agent half of it ("enum switch needs no default") and could lead an agent to strip the default from a String switch.
Something like this might be complete:
Prefer switch expressions (case X -> ...) over statement switches. An exhaustive enum switch needs no default. For String/non-exhaustive switches, the required default should throw an informative error (e.g. Unsupported X), not a generic one.
There was a problem hiding this comment.
Good catch on the risk of over-generalizing. I want to keep the bullet terse to match the surrounding style, and I'd rather leave the informative-error-message advice out of this one since it's really about exception messages, not switches. Pushed a tighter version:
Prefer switch expressions (
case X -> ...) over statement switches. Exhaustive enum switches need nodefault; others must have one.
WDYT?
Uh oh!
There was an error while loading. Please reload this page.
This is surfaced by @gaborkaszab in his review comment.