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
698 stars 40 forks source link

`Error while loading rule 'putout/putout': ☝️ Looks like try to put Statement in place of Expression, use 'match' to filter out such cases` on returned assignment #156

Closed ElPrudi closed 1 year ago

ElPrudi commented 1 year ago

I don't know what this error tells me, but it seems putout doesn't deeply check returned assignments (return (x = 5)).

While it can handle this:

return (x = y)

It fails when you want to do something more complex:

return (path = path.at(-1) === '/' ? path : `${path}/`) 
coderaiser commented 1 year ago

Thanks! Just fixed both: message and @putout/plugin-simplify-ternary 🎉. Please re-install 🐊. Is it works for you?

ElPrudi commented 1 year ago

Yes, the error doesn't appear anymore. But the message you committed is broken English. Try more the lines of:

   throw Error(`☝️ Looks like you tried to put a Statement in place of an Expression. Use 'match' to filter out such cases: '${print(nodeFrom, PRINT_OPTIONS)} -> ${print(nodeTo, PRINT_OPTIONS)}'. For code: '${path}'`);

I'd highly suggest that you run deepl to translate all of your error messages to your native language and back. It's pretty reliable and that's how I learned how to write in English.

I'm still closing this issue as the error doesn't appear anymore.

coderaiser commented 1 year ago

I used Looks like a try instead of Looks like you try, because this is definitely not you trying to do something incorrect, this is a case not handled by plugin that can produce incorrect result.

Anyways, thank you!

coderaiser commented 1 year ago

I don't know what this error tells me

Don't know hot much it would be useful 😅, but you can read about difference between Expression and Statement int the Book Of AST😏.