Skip to content

fix(lines-before-block): Switch to a whitelist of punctuators #1385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2025

Conversation

LukeAbby
Copy link
Contributor

A follow up to #1383. Sorry for another PR in quick succession along the same lines. However I was thinking about the solution and I wasn't happy with having to maintain a list of punctuators that are checked. Specifically I began to feel like the default should be checking. I also added some more tests to cover some interesting cases I thought of.

@brettz9
Copy link
Collaborator

brettz9 commented May 10, 2025

No worries—thanks for the enhancements. Are the new changes also compatible with prettier?

@LukeAbby
Copy link
Contributor Author

LukeAbby commented May 10, 2025

Yes! Or rather, it's equally as compatible as it was before. Unfortunately Prettier really isn't keen on this rule with intersections specifically. I stress tested with unions and it seemed to be fine with everything I could throw at it.

Normally Prettier formats long intersections in a quite ugly way so for my repo I figure the solution is to relent and split it out into sub-types. The main incompatibilities by far and away was the lines this rule were trying to add at the beginning of functions arguments which was fixed by my last PR and is still solved.

As for the intersection incompatibility that's still there, normally Prettier tries to format intersections as type Intersect = { ... } /** Documentation */ & { ... }. It won't let you add a line before /** but it doesn't usually matter because of ignoreSameLine. However I did however find one example in my repo that boiled down to this:

    type ABC = Pick<
      {
        prop: number;
      },
      "prop"
    > &
      /**
       * Documentation.
       */
      Pick<
        {
          otherProp: string;
        },
        "otherProp"
      >;

It won't allow a newline before the /** here either. However this documentation was "useless". It never shows up anywhere because it's attached to a random item in an intersection. Therefore I just switched it to a regular multiline comment.

Therefore only remaining thing I know of that this rule could do to support Prettier better would be an option to add & to the list of punctuators to ignore. I'm not so keen on that though because the code still looks ugly and addressing the root cause seems better. I don't think it'd be harmful or anything to add though, I just wouldn't use it in my repo.

@brettz9 brettz9 merged commit 0a30832 into gajus:main May 10, 2025
5 checks passed
Copy link

🎉 This issue has been resolved in version 50.6.14 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants