Skip to content

formatter: Diff with Prettier (when arrow function line length === max line len?) #24416

Description

@justingrant

Input

/** Open Fluidd (the console UI hosted on each machine) in a new browser tab. **/
const MachineConsoleLink = ({ ipAddress }: { ipAddress: string | undefined }) =>
  ipAddress ? (
    <a target={"_blank"} rel="noreferrer" href={`http://${ipAddress}`}>
      {ipAddress}
    </a>
  ) : (
    "--"
  );

Config

{}

Oxfmt output

Oxfmt version: latest

/** Open Fluidd (the console UI hosted on each machine) in a new browser tab. **/
const MachineConsoleLink = ({ ipAddress }: { ipAddress: string | undefined }) =>
  ipAddress ? (
    <a target={"_blank"} rel="noreferrer" href={`http://${ipAddress}`}>
      {ipAddress}
    </a>
  ) : (
    "--"
  );

Oxfmt playground link

https://playground.oxc.rs/?t=formatter&formatterPanels=output%2Cprettier&options=%7B%22run%22%3A%7B%22lint%22%3Atrue%2C%22formatter%22%3Atrue%2C%22transform%22%3Afalse%2C%22isolatedDeclarations%22%3Afalse%2C%22whitespace%22%3Afalse%2C%22mangle%22%3Afalse%2C%22compress%22%3Afalse%2C%22scope%22%3Atrue%2C%22symbol%22%3Atrue%2C%22cfg%22%3Afalse%7D%2C%22parser%22%3A%7B%22extension%22%3A%22tsx%22%2C%22allowReturnOutsideFunction%22%3Atrue%2C%22preserveParens%22%3Atrue%2C%22allowV8Intrinsics%22%3Atrue%2C%22semanticErrors%22%3Atrue%7D%2C%22linter%22%3A%7B%7D%2C%22formatter%22%3A%7B%22useTabs%22%3Afalse%2C%22tabWidth%22%3A2%2C%22endOfLine%22%3A%22lf%22%2C%22printWidth%22%3A80%2C%22singleQuote%22%3Afalse%2C%22jsxSingleQuote%22%3Afalse%2C%22quoteProps%22%3A%22as-needed%22%2C%22trailingComma%22%3A%22all%22%2C%22semi%22%3Atrue%2C%22arrowParens%22%3A%22always%22%2C%22bracketSpacing%22%3Atrue%2C%22bracketSameLine%22%3Afalse%2C%22objectWrap%22%3A%22preserve%22%2C%22singleAttributePerLine%22%3Afalse%7D%2C%22transformer%22%3A%7B%22target%22%3A%22es2015%22%2C%22useDefineForClassFields%22%3Atrue%2C%22experimentalDecorators%22%3Atrue%2C%22emitDecoratorMetadata%22%3Atrue%2C%22optimizeEnums%22%3Atrue%2C%22optimizeConstEnums%22%3Atrue%7D%2C%22isolatedDeclarations%22%3A%7B%22stripInternal%22%3Afalse%7D%2C%22codegen%22%3A%7B%22normal%22%3Atrue%2C%22jsdoc%22%3Atrue%2C%22annotation%22%3Atrue%2C%22legal%22%3Atrue%7D%2C%22compress%22%3A%7B%7D%2C%22mangle%22%3A%7B%22topLevel%22%3Atrue%2C%22keepNames%22%3Afalse%7D%2C%22controlFlow%22%3A%7B%22verbose%22%3Afalse%7D%2C%22inject%22%3A%7B%22inject%22%3A%7B%7D%7D%2C%22define%22%3A%7B%22define%22%3A%7B%7D%7D%7D&code=%2F**+Open+Fluidd+%28the+console+UI+hosted+on+each+machine%29+in+a+new+browser+tab.+**%2F%0Aconst+MachineConsoleLink+%3D+%28%7B+ipAddress+%7D%3A+%7B+ipAddress%3A+string+%7C+undefined+%7D%29+%3D%3E%0A++ipAddress+%3F+%28%0A++++%3Ca+target%3D%7B%22_blank%22%7D+rel%3D%22noreferrer%22+href%3D%7B%60http%3A%2F%2F%24%7BipAddress%7D%60%7D%3E%0A++++++%7BipAddress%7D%0A++++%3C%2Fa%3E%0A++%29+%3A+%28%0A++++%22--%22%0A++%29%3B

Prettier output

Prettier version: X.Y.Z

/** Open Fluidd (the console UI hosted on each machine) in a new browser tab. **/
const MachineConsoleLink = ({
  ipAddress,
}: {
  ipAddress: string | undefined;
}) =>
  ipAddress ? (
    <a target={"_blank"} rel="noreferrer" href={`http://${ipAddress}`}>
      {ipAddress}
    </a>
  ) : (
    "--"
  );

Prettier playground link

No response

Additional notes

Not sure if this is caused by the merged line being exactly 80 chars (the line length limit) and Prettier might be including space delimiter in that calculation, which would yield 81 chars?

It seems like oxc is correct here and Prettier has a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-formatter-prettier-diffArea - Formatter difference with PrettierF-lang-jsFormatter - oxc_formatter(_js) related

    Type

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions