ecohabit icon indicating copy to clipboard operation
ecohabit copied to clipboard

Prettier auto formatting

Open itegika opened this issue 1 year ago • 3 comments

Hi there!

This PR aims to enable Prettier code formatting on every commit using a pre-commit hook.

  1. Devs can't commit changes in hidden .git folder due to security reasons
  2. To address this and avoid each dev to do pre-commit hook copy-paste and setups locally (and in time project will grow and more hooks will be used), one widely used approach is to create in root directory a hidden folder to keep there those hooks, make them executables, config custom git hooks path. This PR is an implementation of pre-commit hook with that approach.
  3. After cloning repo other devs needs only to set the path for git hooks to use that new hooks folder (readme file updated with instruction).

I'll be glad to answer any further questions. Thanks!

itegika avatar Aug 04 '23 12:08 itegika

This PR aims to enable Prettier code formatting on every commit using a pre-commit hook

itegika avatar Aug 05 '23 04:08 itegika

hey @itegika,

thanks for the PR on automating prettier formatting.

here's where I'm pausing though: our main hiccup was ensuring devs didn't have to manually adjust settings to avoid unnecessary diffs. but with the current solution, we're still asking them to manually set a custom path using git config core.hooksPath .git-hooks. so, we still end up with a manual step, which was our initial challenge.

got any ideas on streamlining this part? I'm trying to brainstorm some solutions on my end as well.

cheers for diving into this!

lugenx avatar Aug 28 '23 00:08 lugenx

Thanks for your comment @lugenx

I explored various options while working on this PR. The criteria for a good solution included simplicity, predictable output, and flexibility.

While options like a postinstall script or a custom post-clone hook were considered, they come with limitations in some cases. Depending on the package manager devs may use or the way they clone the repo, manual setting may still be required. To unify the setup for all, we would need to restrict the tools and workflows devs can use when working on the project. Another option is Dockerizing the app (should only be pursued if it aligns with the project's needs) but formatting automation should't be the main reason for that.

The current approach simplifies the setup from multiple steps to just one: setting up the path once, after cloning the repo, reducing the chances of errors in the process. Therefore, I believe that providing clear instructions in our Readme and having devs set up the hooks path is a simple, predictable solution that remains compatible with various workflows and tools.

If any of you, @lugenx @tsimian @vishwaszadte @rcamach7, have alternative solutions in mind, I'd appreciate hearing them

itegika avatar Sep 10 '23 08:09 itegika