Skip to content

Commit 888fee7

Browse files
kakulguptaa7ul
authored andcommitted
Proofing chapter 6 (#24)
1 parent 8786246 commit 888fee7

5 files changed

Lines changed: 48 additions & 49 deletions

File tree

6-conventions-and-code-style/6.0-intro.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Conventions
22

3-
Every team composes of developers who follow different conventions. Hence, often we find that code written by a developer is not easily understood by another developer in the same team. **Not having a proper convention creates dependencies on individuals and makes the project difficult to understand by a newcomer**. Tight dependencies in a software development project can affect the velocity of the team.
3+
Every team is composed of developers who follow different conventions. Hence, we often find that code written by a developer is not easily understood by another developer on the same team. **Not having a proper convention creates dependencies on individuals and makes the project difficult to understand by a newcomer**. Tight dependencies in a software development project can affect the velocity of the team.
44

55
The best way to solve this is by deciding and following code conventions.
66

77
> We strongly believe that NO convention is bad.
8-
> As long as there is some convention and it is followed religiously, its good.
8+
> As long as there is some convention and it is followed religiously, it is good.
99
10-
Code conventions can be as easy as following 4 spaces instead of tabs, or ending a statement always with semicolon, etc. It could also be something more complex like not allowing `setState()`to be invoked on `componentWillMount`of a React Component.
10+
Code conventions can be as easy as following 4 spaces instead of tabs, or always ending a statement with a semicolon, etc. It could also be something more complex like not allowing `setState()` to be invoked on `componentWillMount` of a React Component.
1111

1212
<center>_So if you want your team to code like this guy, set and follow conventions._<center/>
1313
<div style="text-align:center">

6-conventions-and-code-style/6.1-eslint.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Eslint: The guardian of code conventions ⚔️
1+
# ESLint: The guardian of code conventions ⚔️
22

3-
**Eslint** is a tool that allows to maintain code quality and enforce code conventions. Eslint is a static code evaluator. Basically, it means that eslint will not actually run the code but will instead read through the source code to see if all the pre - configured code conventions are followed by the developers.
3+
**ESLint** is a tool that allows us to maintain code quality and enforce code conventions. ESLint is a static code evaluator. Basically, it means that ESLint will not actually execute the code but will instead read through the source code to see if all the preconfigured code conventions are followed by the developers.
44

5-
>Eslint allows to maintain consistent code style throughout the project. Thus, any developer of the team can easily understand the code written by another developer. This can exponentially increase the teams velocity and avoid dependencies. It can prevent human errors and can act as a guardian that maintains code conventions.
5+
>ESLint allows us to maintain consistent code style throughout the project. Thus, any developer on the team can easily understand the code written by another developer. This can exponentially increase the team's velocity and avoid dependencies. It can reduce human errors and can act as a guardian that maintains code conventions.
66
77
### Examples
8-
Apart from code conventions , eslint also spots common mistakes made by developers. For example,
8+
Apart from code conventions, ESLint also spots common mistakes made by developers. For example,
99

1010
```js
1111
var a = 1, b = 2, c = 3, e = 4;
@@ -15,7 +15,7 @@ console.log(a, b, c, d, e);
1515
};
1616
```
1717

18-
The above code will compile fine. But as soon as u run it , it will throw a runtime exception`ReferenceError`
18+
The above code will compile fine. But as soon as you execute it, it will throw a runtime exception `ReferenceError`
1919

2020
```js
2121
test()
@@ -27,21 +27,21 @@ test @ VM206:4
2727
(anonymous) @ VM222:1
2828
```
2929

30-
These mistakes can be easily detected by eslint.
30+
These mistakes can be easily detected by ESLint.
3131

3232
### Installation
3333

34-
It is pretty easy to setup eslint for a project.
34+
It is pretty easy to setup ESLint for a project.
3535

3636
```
3737
yarn add --dev eslint babel-eslint eslint eslint-plugin-react eslint-plugin-react-native
3838
```
3939

40-
This would install eslint and other useful plugins as your dev dependencies.
40+
This would install ESLint and other useful plugins as your dev dependencies.
4141

42-
And then in your `package.json` add a `npm script` as below.
42+
After this, add an `npm script` in your `package.json` as given below.
4343

44-
So now your `package.json` should have
44+
Your `package.json` should now have
4545

4646
```js
4747
{
@@ -61,30 +61,30 @@ So now your `package.json` should have
6161
```
6262
6363
64-
Now you can simply run
64+
You can simply run
6565
6666
```
6767
npm run lint
6868
or
6969
npm run lint:fix
7070
```
7171
72-
`npm run lint` will just run the eslint and show a list of errors that need to be fixed.`npm run lint:fix` will run eslint and attempt to correct the errors it is able to fix automatically.
72+
`npm run lint` will run the ESLint and show a list of errors that need to be fixed. `npm run lint:fix` will run ESLint and attempt to correct the errors it is able to fix automatically.
7373
7474
75-
## Icing on the cake
75+
## The icing on the cake
7676
77-
Most modern editors have support for **eslint **via plugins. The benefit of a text editor eslint plugin is that these plugins suggest correction while we write code itself thus saving a lot of time for the developer.
77+
Most modern editors have support for **ESLint** via plugins. The benefit of a text editor ESLint plugin is that these plugins suggest corrections while we write code, thus saving a lot of time for developers.
7878
79-
A editor configured with eslint would look something like this.
79+
An editor configured with ESLint would look something like this.
8080
8181
<br>
8282
<div style="text-align:center">
8383
<img src="/assets/images/6/6.1/eslint-error-editor.png" style="width: 100%;display:inline-block;vertical-align: middle;margin:0" hspace="40">
8484
</div>
8585
<br>
8686
87-
Also, some of these plugins also support features like **lint on save.** Thus, eslint attempts to run`eslint --fix <current_file>` This fixes all auto fixable lint errors such as incorrect indentation spaces, etc the moment you hit save `(cmd+s)` on a file.
87+
Some of these plugins also support features like **lint on save.** Thus, ESLint attempts to run `eslint --fix <current_file>` the moment you save `(cmd+s)` a file. This fixes all auto-fixable lint errors such as incorrect indentation spaces, adding semicolons at the end of a line, etc.
8888
8989
<br>
9090
<div style="text-align:center">
@@ -93,13 +93,13 @@ Also, some of these plugins also support features like **lint on save.** Thus,
9393
</div>
9494
<br>
9595
96-
We **strongly** recommend to enable this feature.
96+
We **strongly** recommend enabling this feature.
9797
9898
## The `.eslintrc` file
9999
100-
**Eslint** rules can be configured via a configuration file `.eslintrc` which should be placed in the root directory of the project.
100+
**ESLint** rules can be configured via a configuration file `.eslintrc` which should be placed in the root directory of the project.
101101
102-
A sample `.eslintrc` file looks like this :
102+
A sample `.eslintrc` file looks like this:
103103
104104
```js
105105
# "off" or 0 - turn the rule off
@@ -145,17 +145,17 @@ A sample `.eslintrc` file looks like this :
145145
146146
The important area in the above configuration is the rules section. This section controls all the code conventions followed in the project.
147147
148-
Complete list of all the available rules are present here: [http://eslint.org/docs/rules/](http://eslint.org/docs/rules/)
148+
The complete list of all the available rules is present here: [http://eslint.org/docs/rules/](http://eslint.org/docs/rules/)
149149
150150
It can be pretty overwhelming at first to decide which rules should go in. Hence we can start with
151151
152152
```js
153153
"extends": ["eslint:recommended", "plugin:react/recommended"]
154154
```
155155
156-
These should cover all the basic rules needed.
156+
These should cover all the basic rules needed to start your project.
157157
158-
But we recommend you add these also
158+
But we recommend adding these as well
159159
160160
```js
161161
"rules": {
@@ -173,14 +173,14 @@ But we recommend you add these also
173173
},
174174
```
175175
176-
Rest of the rules can be added based on what conventions the team decides to follow in the project.
176+
Rest of the rules can be added based on what conventions the team decides to follow.
177177
178178
179179
## Recommendations
180180
181-
A suggestion would be that we add more of auto-fixable rules as the corrections suggested by these rules can be auto fixed by the editor with eslint plugin while saving the file itself. This would reduce the time that a developer would spend fixing lint than writing actual code.
181+
We would suggest adding more of auto-fixable rules as the corrections suggested by these rules can be fixed by the editor with an ESLint plugin on file save. This would reduce the time that a developer would spend fixing lint errors than writing actual code.
182182
183-
Also we recommend using eslint for spacing/tabs instead of other methods like`.editorconfig`. This way, all the code conventions can be configured via single utility **\(eslint\)**. Also, indentations and spacing can be auto fixed by the editor itself with auto fix on save.
183+
We also recommend using ESLint for spacing/tabs instead of other methods like `.editorconfig`. This way, all the code conventions can be configured via a single utility **\(eslint\)** and the fixes can be made by the editor itself on save.
184184
185185
186186
The code till here can be found on the **branch** [chapter/6/6.1](https://github.com/react-made-native-easy/note-taker/tree/chapter/6/6.1)

6-conventions-and-code-style/6.2-git-pre-hooks.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Git Pre-push/Pre-commit Hooks
22

3-
>Pre-push/Pre-commit hooks are nothing but a couple of commands which you would want to run every time you push/commit something. Now it might not sound that interesting but using them with jest and eslint can protect the code quality of your code at a much, much higher level.
3+
>Pre-push/Pre-commit hooks are nothing but commands which you would want to run every time you push/commit something. It might not sound very interesting, but using them with Jest and ESLint can protect the quality of your code at a much, much higher level.
44
5-
___How you ask?___
5+
___"How?" you ask___
66

7-
Pre hooks run a shell command which you specify and if the command fails with exit status 1, the process will get terminated. We store the shell commands inside `.git/hooks` directory of root of the project. So imagine that __you won't be able to push the code if your tests are failing or your js files are not properly linted.__ That sound's interesting right?
7+
Pre hooks run a shell command which you specify and if the command fails with exit status 1, the process will get terminated. We store the shell commands inside the `.git/hooks` directory of the root of the project. So imagine that __you won't be able to push the code if your tests are failing or your js files are not properly linted.__ That sounds interesting right?
88

99
<br>
1010
<div style="text-align:center">
@@ -13,15 +13,15 @@ Pre hooks run a shell command which you specify and if the command fails with ex
1313
<br>
1414

1515

16-
___Now the next question might be, how do you make sure that everyone adds those commands to the pre-push hooks folder?___
16+
___Your next question might be, how do you make sure that everyone adds those commands to the pre-push hooks folder?___
1717

18-
Don't worry we got that covered as well. Let me introduce you to an awesome NPM module called [`husky`](https://www.npmjs.com/package/husky).
18+
Don't worry, we have that covered as well. Let me introduce you to an awesome NPM module called [`husky`](https://www.npmjs.com/package/husky).
1919

2020
### Using Husky
2121

22-
Just do `npm install --save-dev husky` or `yarn add --dev husky`
22+
Just run `npm install --save-dev husky` or `yarn add --dev husky`
2323

24-
After installing these node-modules, all you need to do is specify which command you would like to execute before pushing/committing your code. And all this can be done within `package.json`. It will make sure to add the commands to your local git hooks folder while setting up (npm install) the machine.
24+
After installing these node-modules, all you need to do is specify which command you would like to execute before pushing/committing your code. And this can be specified within `package.json`. It will make sure to add the commands to your local git hooks folder while setting up (npm install) the machine.
2525

2626

2727
We used husky's `prepush` hook to make sure that every line of code which is being pushed is linted and all the tests pass.
@@ -39,7 +39,7 @@ If you look at the `package.json` file of our boilerplate, you would find this s
3939
}
4040
}
4141
```
42-
As you can see, we are doing `npm run lint` and `npm run test` every time the developer tries to push something. If any of the command fails, developer would not be allowed to push and you which greatly reduces the chances of build failure/PR check failure in CIs.
42+
As you can see, we are doing `npm run lint` and `npm run test` every time the developer tries to push something. If any of the commands fail, the developer would not be allowed to push, greatly reducing the chances of build failure/PR check failure in CIs.
4343

4444
<br>
4545
<div style="text-align:center">
@@ -66,6 +66,6 @@ has_hook_script () {
6666
```
6767
This code is autogenerated by the node module so we don't have to worry about it. If you are not able to find this file, it means that your hooks were not properly installed. Please uninstall and install the module again or do `npm run postinstall`.
6868

69-
>Note: In case windows machine, make sure that you have bash([cygwin](https://www.cygwin.com/)). Prepush hooks will fail if you use command prompt
69+
>Note: In the case of Windows machines, make sure that you have bash([Cygwin](https://www.cygwin.com/)). Prepush hooks will fail if you use Command Prompt
7070
7171
The code till here can be found on the **branch** [chapter/6/6.2](https://github.com/react-made-native-easy/note-taker/tree/chapter/6/6.2)
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Environment variables
22

3-
Since react-native is combines native platform code with JS, you might find it hard to accomplish small tasks like passing environment variables. But don't worry, we got you covered here as well 🙌
3+
Since react-native combines native platform code with JS, you might find it hard to accomplish small tasks like passing environment variables. But don't worry, we have you covered here as well. 🙌
44

5-
### How Environment variables work in react-native?
5+
### How do Environment variables work in react-native?
66

7-
Since the JS code is being executed by the native platform, we cannot directly pass env variables like we used to do in node/web pack projects. So we found an alternative way to accomplish this.
7+
Since the JS code is being executed by the native platform, we cannot directly pass env variables like we used to in node/Webpack projects. So we found an alternative way to accomplish this.
88

99
### How to use Environment variables in RN?
10-
We created an `env.config.js` file which exports an object. The env object can contain the API base url, environment, and even the app fixtures/mock api data, etc (we will discuss this in details in [API mocks](./6.5-axios-and-api-mocks.md) section). And on the CI (travis in our case), we change the contents of the file depending on the build type(Dev, UAT or Prod). Sounds cool right? 🤓
10+
We created an `env.config.js` file which exports an object. The env object can contain the API base URL, environment, and even the app fixtures/mock API data, etc (we will discuss this in details in [API mocks](./6.5-axios-and-api-mocks.md) section). And on the CI (Travis in our case), we change the contents of the file depending on the build type(Dev, UAT or Prod). Sounds cool right? 🤓
1111

1212
<div style="text-align:center">
1313
<img src="/assets/images/6/6.3/env-structure.png" style="width: 50%;display:inline-block;vertical-align: middle;margin:0" hspace="40">
@@ -18,11 +18,11 @@ The app will contain all the env configs inside `environment/` folder. The CI wi
1818

1919
### How to change env config using TravisCI?
2020

21-
The command is pretty simple. All we need to do is copy the contents from one file to another.
21+
The command is pretty simple. All we need to do is copy the contents of one file to another.
2222
```shell
2323
cp app/config/env/prod.env.js app/config/env.config.js
2424
```
25-
Head over to [TravisCI]() chapter to know how and where to put the above mentioned command.
25+
Head over to [TravisCI]() chapter to know how and where to put the above-mentioned command.
2626

2727

2828
The code till here can be found on the **branch** [chapter/6/6.3](https://github.com/react-made-native-easy/note-taker/tree/chapter/6/6.3)

6-conventions-and-code-style/6.4-es7-features.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Speed up development with some and ES7 features.
1+
# Speed up development with some ES7 features.
22

3-
We all have got our hands dirty with ES6 already and we all loved it. React Native supports some of the ES7 features out of the box so no setting up is required to use them. Let me introduce you to some of the ES7 features which will surely help you speed up your development:
3+
We all have got our hands dirty with ES6 already and loved it. React Native supports some of the ES7 features out of the box so no additional setup is required to use them. Let me introduce you to some of the ES7 features which will surely help you speed up your development:
44

55

66
### Class properties instead of constructor
77

8-
We all have used constructor() in our class components and had to use `.bind` while calling class member functions and faced problems accessing `this.setState` or `this.props`. Unfortunately that's how ES6 classes work. I am not gonna explain you why do we need to do all this(there are better resources available online to understand that 😉). But I can tell you a really interesting ES7 feature which you will love. Let me introduce you to <b>ES7 Class instances</b>.
8+
We all have used constructor() in our class components, used `.bind` while calling class member functions and faced problems accessing `this.setState` or `this.props`. Unfortunately, that's how ES6 classes work. I am not going to explain why we need to do all this (there are better resources available online to understand that 😉). But I can tell you a really interesting ES7 feature which you will love. Let me introduce you to <b>ES7 Class instances</b>.
99

1010
By using this feature, you can define class members (`state` for eg.) without the need of `constructor`.
1111

@@ -32,8 +32,7 @@ class SomeComponent extends Component {
3232
```
3333

3434
### Arrow functions instead of class methods
35-
36-
Using the above feature, we can also define arrow functions as class instances and since arrow functions does not have their own scope, the `this` inside arrow function will always point to the class. Therefore you do not need to do binding of `this` inside constructor. And in most of the cases, you would not be required to use constructor at all. In our project, we never used constructor in any of the components 🤘
35+
Using the above feature, we can also define arrow functions as class instances and since arrow functions do not have their own scope, `this` inside arrow function will always point to the class. Therefore you do not need to do binding of `this` inside constructor. And in most of the cases, you would not be required to use constructor at all. In our project, we never used constructor in any of the components 🤘
3736

3837
Before:
3938
```js
@@ -61,7 +60,7 @@ class SomeComponent extends Component {
6160
### Object rest spread
6261
ES6 already supports array spread operator. You can use the same syntax for objects as well. So instead of writing `Object.assign({},a,{b:2})`, we can directly use `{...a, b:2}`.
6362

64-
You might say that there is nothing new in this. But if used well, it can make your react code much more beautiful and clean. Let me show you the code before and after using spread operator.
63+
You might say that there is nothing new in this. But if used well, it can make your React code much more beautiful and clean. Let me show you the code before and after using spread operator.
6564

6665

6766
Before

0 commit comments

Comments
 (0)