Skip to content

Commit dee8bbf

Browse files
authored
Merge pull request #27 from EdgeApp/paul/updates
Update conventions
2 parents 29cfb98 + f7eeec8 commit dee8bbf

File tree

3 files changed

+94
-49
lines changed

3 files changed

+94
-49
lines changed

code/javascriptCode.md

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,12 @@
11
# [<](README.md) &nbsp; JavaScript Code Conventions
22

3-
* [File Names](#file-names)
43
* [Comments](#comments)
54
* [Exports](#exports)
65

76
&nbsp;
87

98
----
109

11-
## File Names
12-
13-
* Postfix the names of index files with the name of its parent directory
14-
15-
```javascript
16-
// incorrect
17-
src/
18-
components/
19-
MyComponent/
20-
index.js // <--
21-
MyComponent.js
22-
styles.js
23-
// correct
24-
src/
25-
components/
26-
MyComponent/
27-
indexMyComponent.js // <--
28-
MyComponent.js
29-
styles.js
30-
```
31-
32-
----
33-
3410
[Back to the top](#--javascript-code-conventions)
3511

3612
&nbsp;
@@ -51,24 +27,6 @@ const denomination = {
5127
}
5228
```
5329

54-
* Break more than double nested array dereferences into multiple lines
55-
56-
```javascript
57-
// incorrect
58-
59-
// correct
60-
61-
```
62-
63-
* Break more than double nested or function calls into multiple lines
64-
65-
```javascript
66-
// incorrect
67-
68-
// correct
69-
70-
```
71-
7230
----
7331

7432
[Back to the top](#--javascript-code-conventions)

code/react.md

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,87 @@
11
# [<](README.md) &nbsp; React Conventions
22

3-
* [TODO](#todo)
3+
* [Component Exports](#component-exports)
4+
* [Hooks](#hooks)
5+
* [Component Patterns](#component-patterns)
46

57
&nbsp;
68

79
----
810
&nbsp;
911

10-
## TODO
12+
## Component Exports
13+
14+
Components should be exported using the following pattern:
15+
16+
### Preferred Pattern
17+
18+
```typescript
19+
export const ComponentName: React.FC<Props> = props => {
20+
// component implementation
21+
}
22+
```
23+
24+
[Back to the top](#--react-conventions)
25+
26+
&nbsp;
1127

1228
----
1329

30+
## Hooks
31+
32+
### useHandler
33+
34+
Prefer `useHandler` over `useCallback` for event handlers and async functions:
35+
36+
```typescript
37+
import { useHandler } from '../../hooks/useHandler'
38+
39+
const handleAction = useHandler(async () => {
40+
// async handler implementation
41+
})
42+
```
43+
44+
This hook provides better TypeScript inference and handles async functions more gracefully than `useCallback`.
45+
46+
### Custom Hooks
47+
48+
Custom hooks should be placed in `src/hooks/` and follow the `use*` naming convention:
49+
50+
```typescript
51+
// src/hooks/useMyHook.ts
52+
export const useMyHook = () => {
53+
// hook implementation
54+
}
55+
```
56+
57+
[Back to the top](#--react-conventions)
58+
59+
&nbsp;
60+
61+
----
62+
63+
## Component Patterns
64+
65+
### Functional Components
66+
67+
Use functional components with hooks instead of class components:
68+
69+
```typescript
70+
// preferred
71+
export const MyComponent: React.FC<Props> = props => {
72+
const theme = useTheme()
73+
const dispatch = useDispatch()
74+
// component implementation
75+
}
76+
77+
// avoid (unless necessary for legacy code)
78+
export class MyComponent extends React.Component<Props> {
79+
// class component implementation
80+
}
81+
```
82+
83+
### Error Handling
84+
85+
Use proper error boundaries and avoid throwing errors in render methods. Handle errors gracefully within components.
86+
1487
[Back to the top](#--react-conventions)

git/commit.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,23 @@ Put your commits in some sort of logical order, for example:
171171
3. Implement the feature
172172
4. Remove old code that was replaced
173173

174-
> Renaming files or variables should always happen in their own commits, separate from any code changes.
175-
>
176-
> – <cite>Paul Puey</cite>
174+
Renaming files or variables should always happen in their own commits, separate from any code changes.
175+
176+
### Work-in-Progress Commits
177+
178+
When working on a feature that is not yet complete, you may use "WIP" as a prefix in the commit message:
179+
180+
```bash
181+
# acceptable for incomplete work
182+
git commit -m "WIP Theme server in Settings"
183+
```
184+
185+
However, WIP commits should be cleaned up before creating a pull request. Use interactive rebase to either:
186+
- Complete the work and update the commit message
187+
- Split the WIP commit into logical, complete commits
188+
- Remove the WIP prefix once the work is complete
189+
190+
WIP commits are useful for saving progress but should not be included in pull requests unless the PR is explicitly marked as a draft for early feedback.
177191

178192
### Clean Commit Principles
179193

@@ -212,7 +226,7 @@ If it’s complex:
212226
#### Joining commits
213227

214228
- Use the "fixup" or "f" command to join two commits keeping the first commit message
215-
- Use the "squash" or "s" command to join two commits and edit the commit message
229+
- Use the "squash" or "s" command to join two commits and edit the commit message
216230
- Use “fixup!” “squash!” in your commit message and add `--autosquash` to your rebase command to tell git to automatically use these commands in your rebase.
217231

218232
#### Editing commits
@@ -221,4 +235,4 @@ If it’s complex:
221235
- Make sure to run `yarn precommit && git rebase --continue` before commiting changes.
222236
- You can even create whole new commits in this mode (omit `--amend`!
223237

224-
[Back to the top](#--commit-rules)
238+
[Back to the top](#--commit-rules)

0 commit comments

Comments
 (0)