Skip to content

@prettier/plugin-oxc won't work with embeded angular through eslint-prettier-plugin #754

Closed

Description

@kbrilla

Prettier 3.6.2
there is no way to provide link with @prettier/plugin-oxc in playground but I provided one with TS parser
link

@Component({
  selector: 'app-some',
  template: `
    @if (value) {
      {{ value }}
    }
  `,
})
export class SomeComponent {
  public value = false;
}

will throw on @if unexpected character when running through eslint prettier plugin.

It seems it works when using just prettier but when using those 2 plugins it throws.

Activity

  1. added theissue type on Jul 29, 2025
  2. fisker commented on Aug 3, 2025

    @fisker
    Member

    I'm sorry, I can't reproduce this.

    Log
    E:\oss\forks\prettier>cat test.ts
    @Component({
      selector: 'app-some',
      template: `
        @if (value) {
          {{ value }}
        }
      `,
    })
    export class SomeComponent {
      public value = false;
    }
    
    E:\oss\forks\prettier>yarn debug test.ts --parser=oxc
    @Component({
      selector: "app-some",
      template: `
        @if (value) {
          {{ value }}
        }
      `,
    })
    export class SomeComponent {
      value = false;
    }
    
    E:\oss\forks\prettier>yarn debug test.ts --parser=oxc-ts
    @Component({
      selector: "app-some",
      template: `
        @if (value) {
          {{ value }}
        }
      `,
    })
    export class SomeComponent {
      public value = false;
    }
    

    Can you post more details or share a reproduction step?

  3. kbrilla commented on Aug 5, 2025

    @kbrilla
    ContributorAuthor

    Sure thing! I created reproduction repo:
    https://github.com/kbrilla/prettier-angular-oxc-eslint

    Image
     pnpm exec nx run prettier-angular-oxc-eslint:lint 
    
    > nx run prettier-angular-oxc-eslint:lint
    
    
    Linting "prettier-angular-oxc-eslint"...
    
    /Users/krzysztof.brilla/repos/prettier-angular-oxc-eslint/src/app/nx-welcome.ts
      8:7  error  Parsing error: Unexpected token  prettier/prettier
    
    ✖ 1 problem (1 error, 0 warnings)
    
    ✖ 1 problem (1 error, 0 warnings)
    
    
    ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
    
     NX   Ran target lint for project prettier-angular-oxc-eslint (2s)
    
       ✖  1/1 failed
       ✔  0/1 succeeded [0 read from cache]
    
    
    

    For me it looks like when using @prettier/plugin-oxc inline html is parsed with html parser and not angular parser.

  4. transferred this issue fromprettier/prettieron Aug 5, 2025
  5. added theissue type on Aug 5, 2025
  6. fisker commented on Aug 5, 2025

    @fisker
    Member

    I guess it's an eslint-plugin-prettier issue, transfered.

    Thanks for the reproduction, we'll take a look.

  7. fisker commented on Aug 5, 2025

    @fisker
    Member

    In this case, we are using onDiskFilepath to get the parser

    const { ignored, inferredParser } = await prettier.getFileInfo(
    onDiskFilepath,
    {
    resolveConfig: false,
    withNodeModules: false,
    ignorePath: '.prettierignore',
    ...prettierRcOptions,
    ...eslintFileInfoOptions,
    },
    );
    , which is a .ts file, we get the oxc-ts parser.

    Then we use oxc-ts to parse the template, which is a virtual file prettier-angular-oxc-eslint/src/app/nx-welcome.ts/1_inline-template-nx-welcome.ts-1.component.html.

    This is where the error comes from.

    @JounQin Do you have an idea how to fix it?

    I don't think we should take https://github.com/kbrilla/prettier-angular-oxc-eslint/blob/9012b2938a2c7f037341806c808c047607a922c5/.prettierrc#L5-L10 into count. It should only apply to "real" files.

    Should we ignore virtual files?

  8. JounQin commented on Aug 5, 2025

    @JounQin
    Member

    } else {
    // Similar to https://github.com/prettier/stylelint-prettier/pull/22
    // In all of the following cases ESLint extracts a part of a file to
    // be formatted and there exists a prettier parser for the whole file.
    // If you're interested in prettier you'll want a fully formatted file so
    // you're about to run prettier over the whole file anyway.
    // Therefore running prettier over just the style section is wasteful, so
    // skip it.
    const parserBlocklist = [
    'babel',
    'babylon',
    'flow',
    'typescript',
    'vue',
    'markdown',
    'html',
    'mdx',
    'angular',
    'svelte',
    'pug',
    ];
    if (parserBlocklist.includes(/** @type {string} */ (inferredParser))) {
    return;
    }
    }

    Virtual files are already ignored.

    But in the new case, it's oxc-ts I think?

  9. kbrilla commented on Aug 5, 2025

    @kbrilla
    ContributorAuthor

    Just to make sure, it all does work without @prettier/plugin-oxc in current configuration.

  10. JounQin commented on Aug 5, 2025

    @JounQin
    Member

    We'll need to add oxc related new parsers into parserBlocklist, feel free to raise a PR for them. Similar for hermes plugin.

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

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions