Skip to content

oxfmt: support parser option (with overrides) #17852

Description

@cexbrayat

oxfmt currently relies on hardcoded file extension checks to determine which parser to use. Specifically, for Angular templates, it only uses the angular parser if the file ends in .component.html.

While this was true for a long time in the Angular community, the updated Style Guide in 2025 now recommends to have component templates named user.html instead of user.component.html, and this is now the default in projects generated via Angular CLI.

As files ending in just .html are treated as generic HTML, this causes formatting issues for Angular Control Flow syntax (@if, @for, @switch), which are not valid in standard HTML and are thus aggressively collapsed or incorrectly indented by the generic html parser.

In Prettier, we usually rely on overrides to work around this:

overrides:
  - files: "*.html"
    options:
      parser: angular
  - files: "index.html"
    options:
      parser: html

Would it be possible to have a similar feature in oxfmt?
This would allow users to explicitly map file patterns to specific parsers.

Something like:

{
  "overrides": [
    {
      "files": "*.html",
      "options": {
        "parser": "angular"
      }
    },
    {
      "files": "index.html",
      "options": {
        "parser": "html"
      }
    }
  ]
}

Activity

  1. leaysgur commented on Jan 11, 2026

    @leaysgur
    Member

    I'm a bit skeptical about supporting this as-is.

    The implementation itself isn't difficult, but here are some points I'm considering and want to discuss first:

    If for some reason we were to support an equivalent feature, associations by dprint seems neat.

    https://dprint.dev/config/#associations

    In that case, { [glob]: (linguistLang?ourOriginalId?) }? How about precedence?

    This decision will likely impact the subsequent design of language-specific options. (1.0 milestone work? though)

  2. changed the title [-]oxfmt: support configuration overrides for parser selection[/-] [+]oxfmt: support `parser` option (with `overrides`)[/+] on Jan 20, 2026
  3. garytube commented on Mar 3, 2026

    @garytube

    Hi there,
    we also faced that issue today while refactoring our App.
    A parser option would be helpfule!

  4. edlrod commented on Mar 4, 2026

    @edlrod

    Probably switching back to prettier until this is fixed

  5. luisbytes commented on Mar 6, 2026

    @luisbytes

    When using Ionic with Angular, page templates use the .page.html suffix. In these files, the new Angular control flow syntax is not being formatted correctly. It would be useful to support the parser option within overrides to ensure these files are treated as Angular templates.

  6. pkurcx commented on Mar 10, 2026

    @pkurcx

    I support the request. We switched to an approach without a suffix, which makes the formatter useless for these templates.

  7. zargham-k commented on Mar 10, 2026

    @zargham-k

    We've run into this issue, some components do not follow *.component.html convention, it would be great to have the parser override.

  8. frf-leanix commented on Mar 10, 2026

    @frf-leanix

    I support this request as well, it's currently stopping us from replacing prettier with oxfmt.

  9. pkurcx commented on Mar 10, 2026

    @pkurcx

    Alternatively Issue to introduce custom file extension for templates:
    angular/angular#67545

  10. ZWQ652 commented on Mar 24, 2026

    @ZWQ652

    Has there been any progress on this feature? Without this feature, files in custom formats cannot function

  11. balthild commented on Mar 28, 2026

    @balthild

    Oxfmt currently treats tsconfig.json and .vscode/*.json as plain json rather than jsonc. I need this feature to format the trailing commas in them correctly. (BTW, they're treated as jsonc correctly by oxc's vscode plugin because vscode provided the file type information.)

  12. musjj commented on Apr 12, 2026

    @musjj

    Oxfmt currently treats tsconfig.json and .vscode/*.json as plain json rather than jsonc.

    Yep, hit this issue too. Going to return to prettier until this is fixed...

  13. djarekg commented on Apr 16, 2026

    @djarekg

    I just switched back to prettier also.

  14. 7 remaining items

  15. luisbytes commented on Jul 25, 2026

    @luisbytes

    Are there any plans regarding this matter?

    No concrete plan yet.

    The design concerns I raised in my first comment (kept updated since then) still stand, and feedback on them is still welcome.

    For the main Angular use case, we're also watching angular/angular#67545. If Angular adopts a dedicated extension, we can support it soon, with zero configuration.

    We need this configuration for Ionic's .page.html files; it's not possible to format them in Angular mode. This should be dynamic.

  16. TheAlexLichter commented on Jul 26, 2026

    @TheAlexLichter
    Member

    @luisbytes This is exactly that @leaysgur mentioned in #17852 (comment)

    We are fully aware that there are cases that rely on that option but blindly copying it does not look like the best way.
    Could you (and anybody else who is interested in this option) give feedbacks to the points in the first comments?

  17. pkurcx commented on Aug 3, 2026

    @pkurcx

    As for changing the file extension (angular/angular#67545), I guess that's not going to happen, because they don't seem to understand the idea and have ignored the thread.

    But you are welcome to help. Comment, start new discussion, etc.

    https://discord.com/channels/748677963142135818/1481242010189828168

  18. pkurcx commented on Sep 2, 2026

    @pkurcx

    I agree parser inside overrides.options is the wrong shape. It picks the whole pipeline, not a format option, and in the current resolver every matched file would take the slow override path instead of sharing the cached config.

    The associations idea seems right to me. A top-level map from glob to language, sitting next to overrides and ignorePatterns:

    {
      "associations": {
        "**/*.html": "angular",
        "index.html": "html",
        "**/*.wxml": "html"
      }
    }

    PoC PR: #26257

  19. leaysgur commented on Sep 10, 2026

    @leaysgur
    Member

    Although nothing has been decided yet, I've come up with some other ideas.


    { "angular": true }

    A language-specific option in FormatConfig (e.g. angular: true)

    • Works similar to svelte: true
    • Minimal: classify stays as is, into_outcome swaps html → angular
    • index.html exception via existing overrides to set { angular: false }
      • format() API also follows
    • Easy to deprecate if Angular adopts a dedicated extension
    • Also fits if we add language dedicated option fields?
    • Covers Angular v20 / Ionic *.page.html, but NOT unknown extensions (*.wxml, *.svg);
      • those should be supported as built-in extensions instead, tho

    Thoughts:

    • Easy, explicit
    • Why option affects routing?
      • For now, svelte is in the same category, so feels natural
      • But once we support natively?
    • Justified simply because angular is the only one without a proper extension?
    • Simple enough, other usecases are really demanded?

    { "overrides": [{ "files": "*.html", "language": "angular" }] }

    overrides[].language (sibling of options, not inside it)

    • Reuses files|excludeFiles / config-dir relativity / later-wins precedence, no new concept, no preserve_order
      • Similar mapping from Prettier's overrides[].options.parser
    • Routing + language-specific options in one entry
    • Fast path is kept by skipping entries with empty options
    • classify() + resolve() should be merged into one pass in ConfigResolver

    Thoughts:

    • Feels generic, but also too generic
      • overrides should not be an escape hatch?
    • Possible to format .ts as css, but pointless
    • Granularity of language
      • JS(oxc_formatter) / CSS(oxc_formatter_css) / ...
      • JS(JSX) / TS(TSX) / ...
      • JS / JSX / TS / TSX / ...
      • JS / MJS / CJS / ...
      • And this is used as language dedicated option fields?
    • Existence of this slows down the processing of all files
      • Because validation is required for all paths
  20. pkurcx commented on Sep 10, 2026

    @pkurcx

    I've reshaped the PoC in #26257 to the first idea, overrides[].language.

    Why it's the better shape:

    • excludeFiles gives a real way to fall back to built-in detection.
    • No dependency on JSON object order, so preserve_order is gone.
    • Routing and options live in one entry, e.g. { "files": ["*.html"], "language": "angular", "options": { ... } }.
    • language sits beside options, not inside. It picks the pipeline, it is not a format option.
    • IDs are oxfmt's own (angular, handlebars), not Prettier parser names.
    • Prettier migration is a rename of overrides[].options.parser. (migrate-prettier itself is still blocked on oxfmt: Improve --migrate prettier #18215.)
    • One glob pass per file. A language-only entry keeps the fast path, and nested configs work unchanged.

    Note: files must be an array, so the example reads { "files": ["*.html"], "language": "angular" }.

    Details in the PR comment.

  21. richardweaver commented on Sep 28, 2026

    @richardweaver

    To add to the reasons why this would be beneficial, this isn't just an Angular thing, we have a similar issue with Handlebars templates in *.html files (which is what BigCommerce's Stencil template engine expects).

  22. muuvmuuv commented on Oct 6, 2026

    @muuvmuuv

    We're running into this in an Angular 22 workspace as well, so here's a data point with some numbers, plus a few thoughts on the design questions.

    Our setup: 142 HTML files: 94 *.component.html, 47 *.feature.html (our naming convention for routed feature components) and a single index.html. With Prettier we use overrides: [{ files: "*.html", options: { parser: "angular" } }].

    The Angular formatting itself already works really well. With the same options, all 94 *.component.html come out byte-identical to Prettier, and so do all 47 *.feature.html when we route them through the Angular pipeline via --stdin-filepath x.component.html. Through the HTML pipeline, 28 of them lose the indentation inside control-flow blocks, and some @if { … } @else { … } blocks and multi-line {{ … }} get reflowed like prose. The --stdin-filepath trick only helps on the CLI, since the editor formats through the LSP with the real file path.

    Some thoughts on the design:

    • angular: true (similar to svelte: true) would cover our case completely: *.html as Angular, plus { "files": ["**/index.html"], "options": { "angular": false } } for the one exception. It also seems easy to explain, and easy to retire if Angular ever adopts a dedicated extension.
    • overrides[].language (feat(oxfmt): route files by language via overrides[].language #26257) would additionally help with .page.html, Handlebars and .wxml. We'd be happy with either direction. What would help us most is that the CLI, the LSP and --check pick the same pipeline for a given file.
    • A small thing we noticed along the way: our first attempt was parser inside overrides.options, which oxfmt accepted without any message, and --migrate prettier skips parser quietly as well. Maybe a short hint there, for example pointing to this issue, could help others who try the same. Just an idea, independent of the final design.
  23. leaysgur commented on Oct 8, 2026

    @leaysgur
    Member

    Now that recent heavy tasks are done, I'd like to move this forward.
    (cc: Thanks @pkurcx for the PoC)

    First, a re-evaluation of the ideas so far.

    angular: true

    • Cheapest, and it covers Angular users, who are the majority of requests.
    • But it couples an option with routing.
    • Similar cases already exist
      • .md as MDX in Docusaurus, Cursor's .mdc, WeChat's .wxml, Salesforce's .cmp, each would need its own flag?

    So I decided not to go with it.

    overrides[].language

    • Precedence and affinity with existing configs and Prettier look good.
    • But it still couples options with routing, especially with { language, options } case.
    • Forbidding the combination would be odd too.

    So I can't call it the best either.

    associations

    • As a top-level key, it can be a routing-only concept.
    • Precedence is solved by an array instead of an object, later wins like overrides.
    • For language, use Shiki ids, already used in our codebase (e.g. embedded dispatch name), probably the most familiar ones.

    The final shape looks like this.

    {
      "associations": [
        { "files": ["**/*.html"], "excludeFiles": ["**/index.html"], "language": "angular-html" },
        { "files": ["**/*.mdc"], "language": "markdown" }
      ]
    }
    • Unknown extensions are also supported.
    • Lock files stay excluded.
    • An unknown id is rejected at config load.

    Poc PR: #27437

  24. added a commit that references this issue on Oct 11, 2026
    a495e82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    Priority

    None yet

    Start date

    None yet

    Target date

    None yet

    Effort

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions