Back to the ridge
06/Base camp/open source/2020 — 2021

Checkstyle

The Java style checker that has been failing builds since 2001 — 9k stars, 4.2k forks, 378 committers. I rewrote how it understands indentation, starting with lambdas: an issue open since 2016.
9k
stars · 4.2k forks; in build pipelines since 2001
378
people have ever committed to it
5 years
the age of the lambda issue the rewrite closed

Context

Checkstyle is the Java style checker that has sat in build pipelines since 2001. When a Java project fails CI on a formatting rule, this is usually what said so — 9,000 stars, 4,200 forks, and a very long memory of every convention anyone ever argued about.

I worked almost entirely on one module. Indentation is the hardest one, because it has to hold an opinion about whitespace for every shape the Java grammar allows, and every shape it gets wrong is a false positive in somebody's build.

What I did

Re-implemented indentation handling for lambdas. The issue had been open since 2016 — lambdas can wrap, nest, sit inside an argument list or a method chain, and the old handler had no coherent model of any of it. The rewrite gave it one.

Then the rest of the grammar, one shape at a time: annotation array initialisers, the `new` keyword and its children, non-list children of if/else/for/while/switch/case, array-initialisation right braces, and forceStrictCondition so it stops disagreeing with individual array elements.

And the change that made all of them cheaper — moving the checks to log a DetailAST rather than a raw line number, so a violation knows which node produced it. That went into Indentation, LambdaParameter, NoLineWrap and MissingSwitchDefault.

Alongside the module: adding braceAdjustment support so a single checker can satisfy both google-java-format and a switch-block convention, generating the diff report against the main branch rather than a stale one, and adding new projects to the no-exception regression suite so the next person's change is tested against more real code than mine was.

Outcome

28 pull requests merged. The lambda work closed a five-year-old issue, and the indentation module now agrees with the Google Java Style Guide on shapes it used to argue with.

checkstyle.org
checkstyle.org

In public

Selected pull requests. Every one of them can be read.