namshi / coding-standards

To add a newline or not, that is the question!
6 stars 0 forks source link

Pre commit hook for coding styles commands #15

Closed hossam-fares closed 6 years ago

hossam-fares commented 6 years ago

I have added eslint coding style rules drived from google code style and fix it to be prettier compatible

So you only need to do:

 cd YOUR_REPO_DIRECTORY

 wget https://raw.githubusercontent.com/namshi/coding-standards/master/jsSupportFiles/.eslintrc

 curl https://raw.githubusercontent.com/namshi/coding-standards/master/jsSupportFiles/install-precommit-commands.js | node

Running the above command will modify the package.json and install the required dependencies. It will also add the following npm scripts:

lint-staged => This is the actual pre-commit scripts. Whenever you try to commit, it will take the staged files, run eslint and prettier on it, and commit the files.

But if we want to format the existing files, we can run :

npm run eslint YOUR_FILE_OR_DIR npm run prettier YOUR_FILE_OR_DIR

Credit:

Thanks to @shidhincr, we have a very simple way to have code styling fix on pre-commit in this gist https://gist.github.com/shidhincr/3816f8ed5f03c10405892641e60f94d6

cirpo commented 6 years ago

LGTM 👍

hossam-fares commented 6 years ago

Thanks Cirpo

On 11 Feb 2018 7:45 pm, "cirpo" notifications@github.com wrote:

LGTM 👍

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/namshi/coding-standards/pull/15#issuecomment-364761112, or mute the thread https://github.com/notifications/unsubscribe-auth/ABw8xa8n4Mu0iNQZDY-mD4BkGSJ6BdPmks5tTwsagaJpZM4R-QCd .

shidhincr commented 6 years ago

👏

cirpo commented 6 years ago

:D Miss you guys! Keep rocking!

hossam-fares commented 6 years ago

Same here :)