8000 Prettier setting in config file in the repo now apply to all contributors code automatically by AyanDas348 · Pull Request #204 · lugenx/ecohabit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Prettier setting in config file in the repo now apply to all contributors code automatically #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

AyanDas348
Copy link
@AyanDas348 AyanDas348 commented May 23, 2023

#94 Prettier setting in config file in the repo now apply to all contributors code automatically
-Added script in ./git/hooks/pre-commit:
Run Prettier on all staged files
npx prettier --write --config .prettierrc.json --ignore-path .gitignore --ignore-unknown .
-Made the script an executable file using:
For windows: icacls .git/hooks/pre-commit /grant:r "%USERNAME%":F
For Unix systems(Linux, macOS): git update-index --chmod=+x .git/hooks/pre-commit

@AyanDas348 AyanDas348 requested a review from lugenx as a code owner May 23, 2023 20:40
@lugenx
Copy link
Owner
lugenx commented May 23, 2023

@AyanDas348 , thank you again, can you help me to understand where the script is exactly?

@AyanDas348
Copy link
Author

@lugenx under ./git/hooks/pre-commit. The folder is hidden by default so you might need to turn on hidden folders in editors like VS Code to access it. It basically runs a script that says that before committing it will make changes to the files and folders in the folder:

  • --write: This flag tells Prettier to format the files in-place, meaning it will modify the files directly with the formatted code.
  • --config .prettierrc.json: This flag specifies the configuration file for Prettier. In this case, it's .prettierrc.json
  • --ignore-path .gitignore: This flag specifies the path to the .gitignore file. Prettier will ignore any files or directories listed in the .gitignore file.
  • --ignore-unknown: This flag tells Prettier to ignore any unknown file types instead of throwing an error.
  • .: The dot (.), Prettier will format all the files in the current directory and its subdirectories.

@lugenx
Copy link
Owner
lugenx commented May 23, 2023

thank you for the explanation, @AyanDas348. you're right that the .git folder exists on our local machines and doesn't get pushed to GitHub. doesn't this means that the pre-commit hook you've created currently only runs on your machine?

@AyanDas348
Copy link
Author

@lugenx Whenever any contributor/users clone this repository they will also get the hooks from ./git/hooks cloned into their directory. When they commit it will apply the prettier changes as mentioned in .prettierrc.json file. I have made the pre-commit an executable so it runs when contributors make a commit.

@AyanDas348
Copy link
Author

Hey @lugenx did you have the chance to take a look at this PR?

@lugenx
Copy link
Owner
lugenx commented May 26, 2023

hey, @AyanDas348 didn't have a chance yet unfortunately. i should have some time today or tomorrow. thank you for your patience.

@lugenx lugenx requested a review from tsimian May 26, 2023 13:24
@lugenx
Copy link
Owner
lugenx commented May 26, 2023

hi @AyanDas348 ,

I cloned your branch, and this is how the .git/hooks folder looks like:
image

And this is the inside of precommit-sample file:
image

can you help me find out your script?

Thank you

@AyanDas348
Copy link
Author

Hey @lugenx I have noticed my script has not been cloned. There is some issue with making the pre-commit hook executable and cloned. I'll look into this and start working out a new solution. Thanks for your patience.

@AyanDas348
Copy link
Author

I will close the pull request and open a new one when I have resolved it. I'll make sure to reclone the repo on a different system to test if the pre-commit hook is working or not.

@AyanDas348 AyanDas348 closed this May 26, 2023
@lugenx
Copy link
Owner
lugenx commented May 26, 2023

sounds good, @AyanDas348 , thank you so much for looking into this, if you have any questions or just want to discuss while figuring this out, you can reach out to me or @tsimian in our discord chat. you can join the discord server through the link in the readme file if you didn't already.

@AyanDas348
Copy link
Author

Thanks @lugenx I'll join the discord and let you know if I have a working solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0