JS: a test spec can opt into the style its own source is written in - #8681
Merged
knutwannheden merged 1 commit intoAug 27, 2026
Merged
Conversation
A spec that formats its output is measured against the built-in defaults, so a fixture indented with tabs comes back indented with four spaces and the expectation cannot be written as the file reads. Declaring a style meant hand-building a NamedStyles marker and overriding the spec's parser. withDetectedStyle samples the file and attaches what it finds, wired per spec via beforeRecipe. It stays opt-in to match Java, where RewriteTest never autodetects and a test asks for a style with spec.parser(JavaParser.fromJavaVersion().styles(...)). Applying it to every spec instead would diverge from that and change what 9 existing tests are measured against, 8 of them in format.test.ts, which feed deliberately messy input and assert canonical output.
knutwannheden
deleted the
template.apply-normalises-spliced-argument-style
branch
August 27, 2026 16:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A JS test fixture indented with tabs comes back indented with four spaces from any recipe that formats, so the expectation cannot be written the way the file reads:
This is the documented style resolution — constructor styles, then
NamedStylesmarkers on the source file, then IntelliJ defaults — working as specified. A barejavascript()/typescript()spec carries no style marker, so it lands on the defaults. InstrumentingAutoformatVisitorconfirms it: the source file is found,markers:[],useTabCharacter=false, indentSize=4. The style-marker code lives only in thenpm()generator, which samples all specs together; a spec standing on its own never reaches it.Declaring a style was already possible, but only by hand-building a
NamedStylesmarker and overriding the spec'sparser.withDetectedStylesamples the file and attaches what it finds, wired per spec:Why opt-in
Applying it to every spec was the first version and is wrong. Java is the reference:
RewriteTesthas no style handling at all, and a test asks for one withspec.parser(JavaParser.fromJavaVersion().styles(...)). That makes the existing JS behaviour symmetric rather than broken —npm()≈ project parsing and autodetects, a bare spec ≈ a bare Java test and does not. Automatic detection also changes what 9 existing tests are measured against, 8 of them informat.test.ts, which feed deliberately messy input and assert canonical output; autodetecting from that input is self-defeating.Full detection rather than indentation alone, since an explicit opt-in is a request for the file's style, and no guard against an existing marker, since a caller that asks should get what it asked for.
Tests
One test,
a spec opting into its own style keeps the tabs it is written with, pins the whole path — sample, attach,getStylelookup, formatter. It fails without thebeforeRecipeline (tabs become four spaces), so it catches a marker the lookup cannot find as well as a detector that reads the wrong indent.autodetect.test.tscovers the detector's output but never that the marker is consumed. Full JS suite: 1629 passed, 0 failed, no existing test moved.