plugin-tools icon indicating copy to clipboard operation
plugin-tools copied to clipboard

docs: add guidance on use of prettier

Open sympatheticmoose opened this issue 2 years ago • 5 comments

Given we include prettier config, we should (briefly) explain somewhere what it does and how to enable it.

Perhaps just a reference in the folder structure where we could expand the content to more comprehensively cover what the tool generates.

sympatheticmoose avatar Sep 29 '23 08:09 sympatheticmoose

Can I also suggest setting up CI Workflow to Prettier run over this project before releases?

Our plugin project (based off "plugin-tools") is now getting CI lintting errors. #374 & #383

mountainash avatar Jan 10 '24 12:01 mountainash

Hi @mountainash

Because our templates are not really parseable by prettier we can't run prettier in them directly in Ci as you suggest. What we instead do is invoke prettier after we are done generating the plugin files see here. But we are not doing this after updates so I opened this issue

Our plugin project (based off "plugin-tools") is now getting CI lintting errors. https://github.com/grafana/plugin-tools/pull/374#issuecomment-1884786130 & https://github.com/grafana/plugin-tools/pull/383#discussion_r1447345978

You want to run prettier --write[1] across your whole plugin project and most likely you'll want to setup a pre-commit step for prettier using something like lint-staged or husky or a combination of both. You can see the prettier documentation on the topic and set it up in your project.

We don't set up any pre-commits in the generated plugins to not increase the complexity of the generated project and leave most decisions of style and tooling to the user.

[1] if you use npx you can use npx prettier '**/*.ts' --write and if you use yarn yarn prettier '**/*.ts' --write

academo avatar Jan 10 '24 16:01 academo

Thanks for raising it as an issue.

We already run lintting in our CI (which is how I uncovered these issues in this project 😏)

mountainash avatar Jan 10 '24 16:01 mountainash

@mountainash Linting is not the same as formatting. Formatting usually happens in your local machine with a tool like prettier and most often CI steps exists to enforce everyone commits code well formatted and that follows certain style and coding rules.

I still recommend you run prettier in your project and setup a pre-commit because any code (not only coming from the .config folder generated by create-plugin) will break your linting CI step.

academo avatar Jan 10 '24 16:01 academo

Thanks again for the feedback.

I'm aware of the difference; and we are happy to fix/format our own code... but we try not to fix/reformat the code we don't "own" - it makes more sense to fix it at the (open) source and then everyone benefits.

And personally I'm not a fan of pre-commits (see this video for some reasons why).

mountainash avatar Jan 10 '24 20:01 mountainash