coderaiser / putout

šŸŠ Pluggable and configurable JavaScript Linter, code transformer and formatter, drop-in ESLint superpower replacement šŸ’Ŗ with built-in support for js, jsx, typescript, flow, markdown, yaml and json. Write declarative codemods in a simplest possible way šŸ˜
https://putout.cloudcmd.io/
MIT License
712 stars 40 forks source link

Closing arrow bracket (>) inside React components should not be transformed into `>` automatically #216

Closed Jabher closed 4 months ago

Jabher commented 4 months ago

> inside React components is transformed into > automatically and uncontrolled, however, this behaviour causes troubles with other tools, such as prettier.

E.g. (Putout 35.37.1 is used in this example)

const putout = require("putout");

const { code } = putout(`
export default () => (<div>press here -&gt;</div>);
export const Component = () => (<div>&lt;- press here -&gt;</div>);
`);
console.log(code);

produces

export default () => (
    <div>press here -></div>
);

export const Component = () => (
    <div>&lt;- press here -&gt;</div>
);

I understand that this is semi-correct behaviour and is generally handled by various transforms, but e.g. prettier+typescript that is embedded in my pipeline crashes on this transformation with this error:

SyntaxError: Unexpected token. Did you mean `{'>'}` or `&gt;`?

I can see that this transform gets disabled in case when pair of braces is used, so I guess this is some explicit internal behavior.

I recommend to move it to separate transformation (maybe enabled-by-default) so it can be optionally disabled to preserve compatibility with other linting tools in pipeline.

I'm currently replacing all &gt;s in my code with {">"}, but I hope it can be fixed in a future.

coderaiser commented 4 months ago

Thanks, just fixed in @putout/printer v9.9.0šŸŽ‰. Is it works for you?