prettier / prettier/prettier

How can I add parentheses and wrap html attribute in single return line component?

Open
#17,289 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
52.3k
Forks
5k
Avg merge
19h 2m
Merged PRs (30d)
117

Description

Input:

export default function ModalDefault({ children }: props) {
    return (
        <div className={'fixed top-72 w-[100px] bg-blue-300/70 h-20'}>
            {children}
        </div>
    );
}

Output:

export default function ModalDefault({ children }: props) {
    return <div className={'fixed top-72 w-[100px] bg-blue-300/70 h-20'}>{children}</div>;
}

Expected output:

export default function ModalDefault({ children }: props) {
    return (
        <div 
            className={'fixed top-72 w-[100px] bg-blue-300/70 h-20'}
        >
            {children}
        </div>
    );
}

Why?

I want to add parentheses automatically and auto wrap every single attributes, but in single html return component, isn't working :,<

{
  "singleQuote": true,
  "semi": true,
  "useTabs": false,
  "tabWidth": 4,
  "trailingComma": "all",
  "printWidth": 200,
  "bracketSpacing": true,
  "bracketSameLine": false,
  "singleAttributePerLine": true,
  "arrowParens": "avoid",
  "endOfLine": "auto"
}

this is my prettierrc file

how can i solve it?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the TSX input in the Prettier playground with the supplied options, especially printWidth 200 and singleAttributePerLine. Compare the actual and expected output, then determine whether the request needs a formatter behavior change or documentation; done means the intended behavior is decided and verified against the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.