From 2d9140032ef7eff781d4c79f407287844cbd52cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kunall=20Banerjee=20=E2=9C=8C=EF=B8=8F?= Date: Wed, 2 Aug 2017 07:22:09 -0400 Subject: [PATCH] Add a section on Git hooks (#66) * initial commit adding git hooks under section 7 (code style) * add a section on code style check within the editor * add a section on using prettier with pre-commit hooks using husky * update links * reformat section to follow existing flow * :ok_hand: make changes and update links * follow current text format and remove redundant point --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 2f0ce15..4a40ead 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ If you want to share a best practice, or think one of these guidelines should be - [Testing](#testing) - [Structure and Naming](#structure-and-naming) - [Code style](#code-style) + - [Some code style guidelines](#code-style-check) + - [Enforcing code style standards](#enforcing-code-style-standards) - [Logging](#logging) - [API](#api) - [API design](#api-design) @@ -393,6 +395,9 @@ Having a good guideline for creating commits and sticking to it makes working wi ![Code style](/images/code-style.png) + +### 7.1 Some code style guidelines + * Use stage-2 and higher JavaScript (modern) syntax for new projects. For old project stay consistent with existing syntax unless you intend to modernise the project. _Why:_ @@ -451,6 +456,22 @@ Having a good guideline for creating commits and sticking to it makes working wi _Why:_ > It makes it more natural to read the source code. + +### 7.2 Enforcing code style standards + +* Have your editor notify you about code style errors. Use [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier) and [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) with your existing ESLint configuration. [read more...](https://github.com/prettier/eslint-config-prettier#installation) + +* Consider using Git hooks + + _Why:_ + > Git hooks greatly increase a developer's productivity. Make changes, commit and push to staging or production environments without the fear of breaking builds. [read more...](http://githooks.com/) + +* Use Prettier with a precommit hook + + _Why:_ + > While `prettier` itself can be very powerful, it's not very productive to run it simply as an npm task alone each time to format code. This is where `lint-staged` (and `husky`) come into play. Read more on configuring `lint-staged` [here](https://github.com/okonet/lint-staged#configuration) and on configuring `husky` [here](https://github.com/typicode/husky). + + ## 8. Logging