Before adding a dependency to the project please make sure it satisfies the below criteria:
-
Is open-source and has a permissive license [MIT, ISC, Apache, etc.]
-
Is actively maintained
- Check if the author/owner/maintainer is active in the github issues, fixing issues, adding features with new releases etc.
- Merging dependabot PRs should not be classified as activity on a repository.
-
Dependency should be tree-shakable. Check on bundlephobia
-
Should have a low footprint than others that provide same functionality. Check on bundlephobia
This repository conforms with conventional commits and uses commitilint for that. So when making a commit please always perform below steps:
- git add <path/of/file/to/add>
- yarn commit
yarn commit
will start the commitilint wizard which will help you to create a commit message that follows conventional commit guidelines.
You can read the conventional commit specification here.
Note: PRs without proper commit messages might get rejected.
-
PR title should not be same as branch name but should follow the convention commit guidelines.
Invalid PR title:
Add component Button
Valid PR title:
feat(Button): add button component
-
All PRs require at least 1 approval during the review.
-
All feature/bug fix branches should be merged using
Squash and merge
button.
- Create a
release
branch from develop. - Bump the version and commit in the release branch.
- Merge release branch in
main
. DO NOTSquash and merge
. Create a merge commit instead. - Create a release from
main
. - After merging, create a
realign
branch frommain
andSquash and merge
the realign branch indevelop
.
This section of the readme defines the coding conventions and rules that should be followed by all the contributors. This section is more based on taste and style and should not be taken as absolute truth. If you want to modify/add/remove any part of this section then please open a issue on GitHub and start the discussion. Comments and suggestions for improvements are most welcome.
Why do we need conventions?
Most of the time the software once developed is not supported or maintained by the original author and as new members join the team (and others leave) it becomes difficult to maintain the project and discussions like "my style is bette than your style" start. The goal here is to minimize these discussions and lay a solid groundwork for new members to work upon.
These are the 5 base goals that we'll try to achieve when creating a rule or coding convention:
- Consistency - Conventions enforce consistency. If we are doing something bad it is best to do it in a consistent way than to do things in an inconsistent manner. Consistency throughout the project allows reader to focus on the content rather than the structure.
- Bug Reduction - Rules and conventions help us to identify and quash bugs easily.
- Speed of development - Doing things as per given set of rules the speed of development increases as everyone in the team know what X method or Y component will do and how to use it.
- Scalability - With a proper structure we can scale any project easily be it 5 component app or 500.
- Ease of Refactoring - Refactoring a piece of code that was written 3-4 years back becomes easy for new member refactor and add new features.
- Minimize the use of
any
. Read when to usenever
andunknown
here. - Always use
async/await
and neverthen/catch
. - Co-location: Files that belong together should be kept in same folder or at least near each other.
- Always catch and log errors. All the code that can break should be enclosed inside
try/catch
. - Always question the design that you are given. You do not need to blindly implement all the designs provided.
-
Always use functional components.
-
Always try to decompose the components in smaller section. Read
-
A
tsx
file should always export a component with same name as the file. e.g aXYZ.tsx
file should not exportABC
component. -
When creating a component in
design-system
(andpages
), make sure the below requirements are met:- It should be in its own folder.
- A storybook file (
.stories.tsx
) with proper stories defined showing all the available states. Not required forpages
- A test file (
.test.tsx
) with proper and meaningful tests incl. at least one snapshot. A single snapshot test should not be considered as proper testing. - An
index.ts
file that exports the main component and its props. - It is properly categorized as
atom
,molecule
or anorganism
. - It the component requires a child component then keep it in the same folder. This should only be done if the child component will not be re-used anywhere outside of the parent component
-
Component importing: When importing a component refer the below example
// bad import Footer from './Button/Button'; // bad import Button from './Button/index'; // good import Button from './Button';
-
Redux should be used only in the
pages
and only to share the state with the otherpages
. It should never be used to store API results. -
atom
,molecule
or anorganism
should never trigger an API call. -
atom
should never import amolecule
ororganism
,molecule
can importatom
components but not anothermolecule
ororganism
andorganism
can import bothatom
andmolecule
. -
API calls should always have their own method (No nested or multiple API calls inside same method).
// bad const getAllUserData = async () => { const data = await axios.get('/api/v1/user/1'); const profile = await axios.get('/api/v1/user/profile/1'); return { ...data, ...profile }; }; // good const getUserData = async () => { const userData = await axios.get('/api/v1/user/1'); return userData; }; const getUserProfileData = async () => { const profile = await axios.get('/api/v1/user/profile/1'); return profile; }; const getAllUserData = async () => { const data = await getUserData(); const profile = await getUserProfileData(); return { ...data, ...profile }; };
-
pages
should never call an API method directly but via a custom hook created with the help ofreact-query
. -
All the forms should be created using
Formik
. -
When handling complex state update prefer
useReducer
overuseState
.
- Never use
px
always userem
. Read the difference betweenem
andrem
here. - Never use
cursor: pointer
on a normal button. Read here why - Never use
style
prop and try to minimize the use ofsx
prop. Use styled-components (using emotion) as much as possible. - Use
Typography
atom for all text related things. Thesize
prop accepts material-ui variants as well as custom size. - We use emotion global styles together with material-ui themes.
- We use a primary color with varying opacity levels to differentiate between the states (e.g. disabled, active, hover) of a given component.
- If the primary color needs to be changed then that changes the theme and goes to the theme section. Approval from designer is required
- If you need to override color(or other attribute) of a material-ui component then that goes to the Global style section.