Skip to content

Commit 8ecb2fd

Browse files
committed
doc: improve the contribution rules
1 parent 71afd1c commit 8ecb2fd

File tree

1 file changed

+285
-17
lines changed

1 file changed

+285
-17
lines changed

CONTRIBUTING.md

Lines changed: 285 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,292 @@
1-
# Branch conventions
1+
# Contribution rules and git flow
22

3-
- Feature : `feat/your-branch-name`
4-
- Fix : `fix/your-branch-name`
5-
- Refactor : `refact/your-branch-name`
3+
## Branching
64

7-
More on the [Conventional commits](https://www.conventionalcommits.org/en/v1.0.0/)
5+
- Before making any new changes make sure to go back to the `dev` branch pull and create a new branch from there
6+
- Make sure to follow this branch naming convention
7+
- The dev branch is where developers work on
8+
- Always use the dev branch as the base branch of your pull requests
9+
- The main branch is the production branch.
10+
- Change the base branch using other methods like `git rebase` instead of using the pull request merging for the `dev``main`, and `staging`
811

9-
<br>
12+
### Branching model
1013

11-
# Components conventions
14+
A Git branching model defines your [branching strategy](https://www.perforce.com/blog/vcs/best-branching-strategies-high-velocity-development) in Git. It determines when and how developers make changes and commit them back to your codebase.
1215

13-
1. Use `functional components` instead of arrow components
14-
2. For typescript, use `interface` for props, and types if needed.
15-
3. Default exports should happen on top.
16+
Using a Git branching model can expedite the process of delivering feedback to developers. [Git hosting](https://www.perforce.com/git-hosting) solutions don’t come with a branching model out of the box. These Git branching models are branching patterns designed to help overcome challenges. But with Git, you have to build it!
1617

17-
```js
18-
export default function ComponentName() {....}
19-
```
18+
### **Development branch**
2019

21-
4. `Import React from 'react'` should be avoided where possible.
22-
5. Provide comments for all Props, and components. preferrably with this VS code extension : `JSDoc Generator`
23-
6. Assing a PR to its respective issue and the contributor.
24-
7. Add a label depending on the progress of your PR.
20+
Usually the integration branch for feature work and is often the default branch or a named branch. For pull request workflows, the branch where new feature branches are targeted.
21+
22+
- `dev`
23+
24+
### **Production branch**
25+
26+
Used for deploying a release. Branches from, and merges back into, the development branch. In a Gitflow-based workflow it is used to prepare for a new production release.
27+
28+
- `main`
29+
30+
### **Feature branch**
31+
32+
Used for specific feature work or improvements. Generally branches from, and merges back into, the development branch, using pull requests.
33+
They should have the following prefix `ft/`
34+
35+
- `ft/{FEATURE_NAME}`
36+
37+
### **Hotfix branch**
38+
39+
Used to quickly fix a Production branch without interrupting changes in the development branch. In a Gitflow-based workflow, changes are usually merged into the production and development branches.
40+
They should have the following prefix `ht/`
41+
42+
- `ht/{BUG_NAME}`
43+
44+
### **Bugfix**
45+
46+
This branch is used to fix bugs which might be more intensive when it comes to the amount of changes to be done.
47+
They should start with the prefix `bg/`
48+
49+
- `bg/{BUG_NAME}`
50+
51+
### **Release**
52+
53+
Branch used for release tasks and long-term maintenance versions. They are branched from the development branch and then merged into the production branch.
54+
They should start with this prefix `rl/`
55+
56+
- `rl/{VERSION}`
57+
58+
### Commits
59+
60+
- Follow this guideline [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for your commit messages
61+
- Try to create a mid-sized every couple of minutes/hours. But more importantly, try to let commits be logically consistent contributions. That means if you have many changes in lines of code you can split them up into multiple commits but each of those commits should have an independent meaning that is described by the commit message.
62+
63+
### PRs, Code Review
64+
65+
- Once you made the first commit just go ahead and push the changes
66+
- Create a Pull request once you pushed your changes to the repository, you don't have to wait to finish the feature in order to create a pull request you can create it as soon as you have the first commit.
67+
- The name of the PR should follow the same naming convention as the commit messages. ([Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)).
68+
- Eg: `feat: integrate react markdown`
69+
- If a PR is still being worked on add the GitHub tag `Work in progress`
70+
- Before marking a PR as `Ready for review` make sure that the CI (GitHub actions) and the deployment are passing.
71+
- Request code review by adding the code reviewer as a reviewer to your PR
72+
- After requesting for code review make sure to send a discord message to the project channel with the link to the PR and tag the code reviewer
73+
- PRs should cover a set of related changes covering a single feature, bug fix, or other types of changes
74+
75+
### Resolving Conflicts
76+
77+
- Be super careful, involve the others who are working on similar stuff.
78+
- Make sure you understand what you are accepting or refusing.
79+
- Recent changes are not always the relevant ones, always check that you are not dismissing changes that are actually fixing another bug
80+
81+
### Things to avoid in git
82+
83+
- Avoid using the squash commits feature, it tends to bring conflicts especially when people are using other base branches
84+
- Do not use git force push
85+
- Do not merge your PRs unless your code has been reviewed by a code reviewer and the code reviewer has either approved your changes or accepted all the adjustments you have made upon their review.
86+
- Avoid merging other dependencies PRs into the ones you are working on to avoid having duplicate changes into two PRs in case a change is needed to be used in another.
87+
- Avoid committing the `node_modules` folder (or including it in the version history).
88+
89+
## CSS Rules
90+
91+
### Units of measurement
92+
93+
- Use `rem` whenever possible, and avoid using `px` as a measurement unit
94+
- Translate the Figma designs to `rem`, by dividing the pixels by 16 ( `1rem` equal to `16px`)
95+
- Use line-height ratio (which has no measurement) instead of `px`. To calculate it use the line-height in `px` and divide it by the font-size in `px`.
96+
- page margin: convert the left-right padding of the pages to the content width. this is the formula to calculate it:
97+
98+
```js
99+
content_width = ((figma_page_width - padding_of_one_of_the_sides * 2) * 100) / figma_page_width;
100+
101+
content_width = (1264 * 100) / 1920;
102+
```
103+
104+
- When dealing with mobile devices (iOS and Android), in case you would want an element to occupy just the total height minus the address bar. You may consider using `100svh` instead of `100vh` as the CSS height value.
105+
- In tailwind CSS the `h-screen` class should give you a height of `100vh`, however, the `100svh` class is not present. you have to add it manually.
106+
- The image below illustrates how these new dynamic port heights work
107+
![plYwy.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/1d439c55-218c-4867-9e1f-bc6926e42a3b/71e8372e-174c-4077-a9b9-dee520d61fd5/plYwy.png)
108+
- You can read more via this [link](https://css-tricks.com/the-large-small-and-dynamic-viewports/)
109+
110+
## Next.js and JavaScript rules
111+
112+
- Components should be placed inside the`./components` folder
113+
- Define components following the functional component style (not the class component style).
114+
115+
**Example:**
116+
117+
```javascript
118+
export default function Button({ children }) {
119+
return <button>{children}</button>;
120+
}
121+
```
122+
123+
- Component file names should be named in [PascalCase](https://techterms.com/definition/pascalcase). (eg: `SectionWrapper.jsx`)
124+
- File names should be the same as the component. The given name of a component in its definition should be the same as its file name.
125+
- All JS react files including components when they contain HTML (or [JSX](https://reactjs.org/docs/introducing-jsx.html)), should have a file extension of `jsx`
126+
- Avoid having too many line blocks inside a single component instead divide it into multiple smaller components
127+
- A single component should handle a single type of implementation (or functionality) rather than combining different non-related functionalities together.
128+
- When editing a reusable component to adapt it to a certain page or a single usage, make sure to check that the new changes don't break other usages of the component
129+
- When dealing with images in a Next js use [nextjs’ image](https://nextjs.org/docs/api-reference/next/image) component to render and optimize images.
130+
- Integrate fonts using URLs rather than hardcoding them in the project, to avoid effects on the page loading speed which can be heavily affected if you are using a font file included within the project.
131+
- SVG icons and elements should be imported as react components like this
132+
133+
```jsx
134+
import SiteLogo from './assets/logo.svg'
135+
136+
<SiteLogo className={}>
137+
```
138+
139+
They can also be given class names as shown in the above image.
140+
141+
- When dealing with multiple SVGs icons and images in a project, You should try to Keep, the SVG’s content in their own files to reduce the lines of code.
142+
143+
- When you want to apply a class-name conditionally use this [library](https://www.npmjs.com/package/classnames).
144+
- Add comments for every new component created using [JS-doc](https://jsdoc.app/about-getting-started)
145+
146+
```javascript
147+
<div
148+
className={classNames("w-1/3", "bg-primary", {
149+
"text-white": type === "default",
150+
underline: hasLink,
151+
})}
152+
></div>
153+
```
154+
155+
It will allow you to conditionally add classnames without to much syntax and in a more simplified way.
156+
157+
- When making computations(or calculations) inside a component it’s better to them in a [useEffect](https://reactjs.org/docs/hooks-effect.html) or a [useMemo](https://beta.reactjs.org/reference/react/useMemo). to prevent rerunning the calculation on each render
158+
- Do not wrap into a Fragment (`<> </>`) when you only have one child element.
159+
160+
## Naming (file names, functions, etc.)
161+
162+
- File names should be the same as the component
163+
- Component files should be named in PascalCase
164+
- Component file names should be the same as the function name. Both should be written in PascalCase.
165+
- Class files should also be named in PascalCase
166+
- Class and component names are always singular
167+
- Page files, function files, and other files should be named in kebab-case
168+
- Function names should reflect the function's role
169+
- Folders should be named in kebab-case
170+
- Variables should be named in camelCase
171+
- Global constant variables should be named in SNAKE_CASE (all-caps snake case)
172+
- Custom CSS classes should be named in kebab-case and follow the [bem](http://getbem.com/introduction/) style
173+
- When adding custom CSS classes, make sure their name doesn't conflict with any tailwindcss class.
174+
175+
## Tailwind config
176+
177+
> For every classname you add or modify in the config file. always try to follow the original format and style that tailwindcss uses. You can check the default complete configuration of tailwindcss here [https://github.com/tailwindlabs/tailwindcss/blob/master/stubs/defaultConfig.stub.js]
178+
179+
- Make sure all the custom class names added are named in a meaningful and reusable way
180+
- The name of the class should not be bound to where it is used it should instead reflect its role
181+
- It should be named in a way that it can be used across many components without causing confusion as to what it does or what it means
182+
- Eg: Instead of naming a width class of `project-description-tablet` with a value of `25.313rem`, I would use the formula below and add a spacing of `101.252`, and in that case the usage instead of being `md:w-project-description-tablet` would be `md:w-101.252`
183+
> Remark that the new class name no longer reflects which components or part of the project it is used in, it has instead a name that is globalized and can be reused multiple times without causing confusion
184+
- For tailwind to calculate a spacing value name such as `w-1`, `p-2`, `m-3`
185+
- You should take the value in rem and divide it by `0.25`. `VALUE_IN_REM/0.25`
186+
- Conversely, you can take the class name value `my-[value]` (eg: for `w-3` take `3` as value) and multiply it by `0.25` to find the value in rem.
187+
- Alternatively, you can divide by `4` if the value is `px`. however, it is recommended to use values in rem. to convert to rem use `VALUE_IN_PX/16`
188+
- These custom spacing values should be added to the tailwind config under the `spacing` object.
189+
- Custom attributes such as `w-1`, `gap-1`, `space-x-2`, `w-1`, `p-2`, and `m-2` should be customized under the `spacing` attributes in the tailwind config to avoid duplication in different class utilities that need them
190+
- This is a default tailwindcss default config you can use for reference of how to name classes and where to place different values under the config [file](https://github.com/tailwindlabs/tailwindcss/blob/master/stubs/defaultConfig.stub.js)
191+
- When it comes to fraction classnames for measurements such as width. eg: `w-1/2`, These class names should normally be used for percentages.
192+
- These fractions should actually equal the value of the percentage. Meaning that (1/2) \* 100 should equal `50`.
193+
- You should make sure, if you add custom fraction classes that they would give the same value as the one you give it. (as shown above)
194+
- A quick math formula to convert a percentage to a fraction is to divide the percentage by `100` and add a denominator of `100`
195+
For example, if you want to convert 25% to a fraction, you would divide `25` by `100` and get `0.25`. Then you can add a denominator of `100`, to get the fraction `25/100`.
196+
You will have to simplify both the numerator and denominator to the lowest possible value without a floating number. In this example, we will simplify it to 1/4 by dividing both the numerator and denominator by 25.
197+
- You can use this link to help with the [conversion](https://www.calculatorsoup.com/calculators/math/percent-to-fraction-calculator.php)
198+
- Tailwindcss has by default various screen break points which are already defined
199+
200+
```json
201+
screens: {
202+
'sm': '640px',
203+
// => @media (min-width: 640px) { ... }
204+
'md': '768px',
205+
// => @media (min-width: 768px) { ... }
206+
207+
'lg': '1024px',
208+
// => @media (min-width: 1024px) { ... }
209+
210+
'xl': '1280px',
211+
// => @media (min-width: 1280px) { ... }
212+
213+
'2xl': '1536px',
214+
// => @media (min-width: 1536px) { ... }
215+
}
216+
```
217+
218+
- In case you would want to customize them you can checkout this [documentation](https://tailwindcss.com/docs/screens#max-width-breakpoints) or this [one](https://tailwindcss.com/docs/screens#fixed-range-breakpoints)
219+
- Make sure, none of them overlaps with the default or existing breakpoints you can add the max attribute to the breakpoints if you want breakpoint classes to affect only their respective breakpoints.
220+
221+
## Responsiveness
222+
223+
- In case there are some elements that need to be hidden on certain devices, stick to CSS (tailwind classes) to achieve that and avoid using javascript unless that particular use requires it (for reasons like animation issues and so on).
224+
- `hidden` class should do that and a combination of a device prefix should allow you to hide that element on those devices. (eg: `md:hidden`, `xl:hidden` , `lg:hidden`)
225+
226+
## Image optimizations
227+
228+
- Use `webp` format to load images faster and without quality loss.
229+
- This is applicable for images and not icons or logos.
230+
- Use this tool https://cloudconvert.com/webp-converter to convert images to `web`
231+
- Use `SVG` formats for icons and logos and everywhere where it’s applicable instead of `png`
232+
233+
## Icons and special characters
234+
235+
- Opening quote: https://www.compart.com/en/unicode/U+201C
236+
- Closing quote: https://www.compart.com/en/unicode/U+201D
237+
- Soft hyphen: https://www.compart.com/en/unicode/U+00AD
238+
239+
→ You can find more special characters here https://www.compart.com/en/unicode/
240+
241+
→ You can also find icons to use as images or SVGs on this platform https://fontawesome.com/
242+
243+
## QA your own work-results before submitting a PR for review
244+
245+
- Use the browser device inspect tab and check the design on the following devices:
246+
247+
- iPhone 5/SE
248+
- Galaxy S5/Moto G4
249+
- Pixel 2 XL
250+
- iPhone 6/7/8
251+
- iPhone 6/7/8 Plus
252+
- iPhone X, 12, 13 or 14
253+
- iPad
254+
- iPad pro
255+
256+
## Plugins and external libraries (You do not need to go through this section while we are doing CSS combined exercises)
257+
258+
### Which plugins should be installed in the project
259+
260+
- Only use open-source software packages (dependencies) with one of the following licenses:
261+
262+
- Academic Free License
263+
- Apache License
264+
- Apple Public Source License
265+
- Beerware
266+
- Boost Software License
267+
- BSD
268+
- Creative Commons Zero
269+
- CC BY
270+
- CeCILL
271+
- Common Development and Distribution License
272+
- Common Public License
273+
- Cryptix General License
274+
- Educational Community License
275+
- FreeBSD
276+
- ISC license
277+
- LaTeX Project Public License
278+
- MIT license / X11 license
279+
- Mozilla Public License
280+
- Open Software License
281+
- OpenSSL license
282+
- Python Software Foundation License
283+
- Sleepycat License
284+
- Unlicense
285+
- W3C Software Notice and License
286+
- Do What The Fuck You Want To Public License (WTFPL)
287+
- XCore Open Source License, also separate "Hardware License Agreement"
288+
- XFree86 1.1 License
289+
- zlib/libpng license
290+
291+
- Use dependencies with the most downloads, git stars, and forks.
292+
- Make sure that the dependency you are using is still in active development and not archived

0 commit comments

Comments
 (0)