Skip to content
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

Do not print trailing commas in arrow function type parameter lists in ts code blocks #15286

Merged
merged 5 commits into from Aug 24, 2023

Conversation

sosukesuzuki
Copy link
Member

@sosukesuzuki sosukesuzuki commented Aug 23, 2023

Description

Fixes #15282

Checklist

  • I’ve added tests to confirm my change works.
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

// should be printed depends on whether it is `*.ts` or `*.tsx`.
// https://github.com/prettier/prettier/issues/15282
if (node.lang === "ts" || node.lang === "tsx") {
newOptions.filepath = `dummy.${node.lang}`;
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should we print this?

```typescript
const foo = <T>() => {}
```

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for ts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@fisker
Copy link
Sponsor Member

fisker commented Aug 23, 2023

// https://typescript-eslint.io/architecture/parser/#jsx

This link is broken, can you fix it? https://typescript-eslint.io/packages/parser/#jsx

@sosukesuzuki sosukesuzuki merged commit 90fab60 into prettier:main Aug 24, 2023
26 of 27 checks passed
@sosukesuzuki sosukesuzuki deleted the fix-15282 branch August 24, 2023 08:03
@fisker
Copy link
Sponsor Member

fisker commented Aug 24, 2023

@sosukesuzuki

After second thought, maybe we should pretent it's .ts file if there is no options.filepath? When calling prettier.format("const foo = <T>() => {}", {parser: "typescript"}), people may expect it treat as .ts file?

@fisker
Copy link
Sponsor Member

fisker commented Aug 24, 2023

If you agree, we should update this line instead

!(options.filepath && /\.ts$/.test(options.filepath))

medikoo pushed a commit to medikoo/prettier-elastic that referenced this pull request Feb 15, 2024
…n `ts` code blocks (prettier#15286)

* Remove trailing comma for `ts` code blocks

* Add changelog

* Support `typescript`

* Update link

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

Successfully merging this pull request may close these issues.

Prettier prints a trailing comma after type argument list even if the languages is ts in markdown
2 participants