1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 01:36:22 +00:00

updated docs and pull request template

This commit is contained in:
Nguyễn Việt Hưng
2018-10-26 00:06:06 +07:00
parent c5554e8f1e
commit 6cb6cd3f26
3 changed files with 81 additions and 4 deletions

60
docs/code_style.md Normal file
View File

@@ -0,0 +1,60 @@
# Boostnote Code Style
When submitting your PR, please make sure that your code is well tested and follow the code style of Boostnote.
The code style of Boostnote is listed in [`.eslintrc`](.eslintrc). We also have additional code styles that is not mentioned in that file.
## Additional code styles
### Use ES6 Object Destructing
Please use Object Destructing whenever it's possible.
**Example**: Importing from library
```js
// BAD
import Code from 'library'
const subCode = Code.subCode
subCode()
// GOOD
import { subCode } from 'library'
subCode()
```
**Example**: Extract data from react component state
```
// BAD
<h1>{this.state.name}</h1>
// GOOD
const { name } = this.state
<h1>{name}</h1>
```
### Use meaningful name
This is actually not a "code style" but rather a requirement in every projects. Please name your variables carefully.
**Example**: Naming callback function for event
```js
// BAD
<h1 onclick={onClick}>Name</h1>
// GOOD
<h1 onclick={onNameClick}>Name</h1>
```
### Don't write long conditional statement
When writing a conditional statement, if it's too long, cut it into small meaningful variables.
```js
// BAD
if (note.type == 'markdown' && note.index == 2 && note.content.indexOf('string') != -1)
// GOOD
const isSecondMarkdownNote = note.type == 'markdown' && note.index == 2
const isNoteHasString = note.content.indexOf('string') != -1
if (isSecondMarkdownNote && isNoteHasString)
```