Unnecessary new lines injected by typescript parser.
See original GitHub issuePrettier 1.19.1 Playground link
--parser typescript
--print-width 120
Input:
export const Foo = forwardRef((props: FooProps, ref: Ref<HTMLElement>): JSX.Element => {
return <div />;
});
export const Bar = forwardRef((props: BarProps, ref: Ref<HTMLElement>): JSX.Element | null => {
return <div />;
});
users.map((user: User): User => {
return user;
})
Output:
export const Foo = forwardRef(
(props: FooProps, ref: Ref<HTMLElement>): JSX.Element => {
return <div />;
}
);
export const Bar = forwardRef((props: BarProps, ref: Ref<HTMLElement>): JSX.Element | null => {
return <div />;
});
users.map(
(user: User): User => {
return user;
}
);
Expected behavior: Prettier leaves the code as is.
This formatting issue only occurs when using the typescript parser. If you switch over to the babel parser, the code remains untouched.
The extra lines that prettier injects seem overkill, especially for the users.map
example.
It’s interesting though how that functions that have a union return type, don’t get rewritten to a new line.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
TypeScript static code analysis: JavaScript parser failure
TypeScript static code analysis. Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your TYPESCRIPT code.
Read more >ESLint - Configuring "no-unused-vars" for TypeScript
So here's the latest update of my .eslintrc file which works for me :) { "parser": "@typescript-eslint/parser" ...
Read more >Writing custom TypeScript Eslint rules with unit tests for ...
After reading this article you will know how to create a custom Eslint rule in Typescript for Angular project and how to test...
Read more >How to fix Definition for rule typescript-eslint no-use-before ...
I am new to eslint and I cannot figure out how to solve this issue. The beginning of my imports is always underlined...
Read more >Prettier 2.1: new --embedded-language-formatting option and ...
Fix inconsistent parsing of injected expressions in ... technically necessary to do this for strings which are not on the first line of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If this is considered a bug, I would be happy to work on a fix
~I’m keen to work on it as well. I’m not sure if it is deemed a bug or not 🤷♂️~
I didn’t see the label come through via email 🤦♂️