dfinity / prettier-plugin-motoko

A code formatter for the Motoko smart contract language.
Apache License 2.0
28 stars 1 forks source link

The setup and use instructions don't work as expected #111

Closed ottodevs closed 1 year ago

ottodevs commented 1 year ago

Hello, there are multiple issues with this prettier plugin, and it is not working as expected with the instructions provided.

I tested both with prettier version 2 and 3.

List of issues:

  1. The plugin needs the package "motoko" to be installed for it to work, without that package, the plugin just returns an error when trying to run prettier.
  2. The .prettierrc config indications with { "plugins": ["motoko"] } don't work at all... the correct config should be: { "plugins": ["node_modules/prettier-plugin-motoko/lib/environments/node.js"] } for it to work (pointing to node_modules path)
  3. The README.md instructions for running npx prettier -- --check **/*.mo and npx prettier -- --write **/*.mo are just wrong, no need to add double -- after prettier command, it returns an error doing so.

I provide an easy and reproducible gif demo showcasing all these errors. Other prettier plugins work as expected without needing to add the deep node_modules path, so I think something is not well configured with this motoko plugin, also the need of the extra motoko dependency looks so weird, if that's just something on my end, I would like to locate the causes to fix them.

demo-min

ottodevs commented 1 year ago

Just an update, I mistakenly thought that motoko package was needed but I was wrong sorry, it seems that just adjusting the prettier config pointing to the node.js path in the package is enough for it to work, but the rest of the issues still seem relevant.

Let me know if you can reproduce them. Thank you.

rvanasa commented 1 year ago

Thanks for pointing out these issues in the readme. It's been an adventure trying to support both Prettier 2 and 3 at the same time, so I appreciate the detailed repro.

Fixing in #112. Due to how recently Prettier 3 was released (and because it's also causing issues in other tools such as the Prettier VS Code extension), I would encourage using Prettier 2.x if possible.

rvanasa commented 1 year ago

Updated the readme (let me know if you continue to run into issues and I'll reopen).

ottodevs commented 1 year ago

Thanks for the quick action!

Just a side note, although the demo shows behavior with prettier 3, I tested both prettier 2 and 3 before creating the issue and both were failing the same way (I pointed out this detail in the issue).

rvanasa commented 1 year ago

That's a good point; I'll do another update to the readme. Prettier used to auto-detect plugins in the node_modules directory (and motoko would resolve to prettier-plugin-motoko), but it seems like that's changed at some point over the past year.