A Contribution Guideline shall facilitate the foundation for a collaborative ground for every contributor working on Swapr codebase(s).
We use ZenHub, an agile project management which is tightly integrated with GitHub. Contact one of the core contributors to invite you to the ZenHub board.
- Every task needs have an estimated ticket
- If you see something during work which is out of scope of the ticket:
- make a new ticket or reopen a ticket if exists.
- finish the current ticket first.
- If not depending on the other ticket, make a new branch from the dev branch, not the branch you are working on.
- No ticket is needed, but a branch, if you can do it under one hour. If you see that it takes longer, make a ticket with estimate.
- You can restimate your tickets if you see its much more work. But do not use it to track hours. It's NOT time tracking.
- One ticket, one branch.
- If the ticket involes subtasks
- Create a parent ticket
- Branch out from parent ticket and merge from subtickets
- Merge parent ticket to
develop
- Use /feature/, /bug/, or /chore/ (chore to fix typo and little stuff)
- Avoid working on the
main
branch unless absolutely necessary. Branch names should be named after what they do. - sub-branch like "Feature/stufspecial/otherstuff" should not happen. You can work for yourself in this structur, but please don't get others to work in your sub-branch (It's a sign that something is off. We add to much complexity to non complex stuff. The interface software is still a simple interface)
Some more toughts on branches see Phil Hord's answer on Stack Overflow.
- PRs should target
develop
branch, - A subtask PR should target parent branch.
- Draft PRs should be used when a PR is Work In Progress (WIP).
- If you make a PR from
feature/stufspecial/otherstuff
tofeature/stufspecial/
you should pull it yourself. - After a PR is merged, the branch can be deleted after two weeks.
At Swapr, we are using React to build the frontend.
A General Component is a React Component that is primitive. A General Component should come with bare minimum styles and configurations. It, however, can be extended as per view/page requirements.
- Directory:
src/components
- Component:
src/components/<ComponentName>/index.tsx
- Unit tests:
src/components/<ComponentName>/index.spec.tsx
- styled-components functions must be stored in the same file
A Page is a single page
- Directory
src/pages/<PageName>/components
- Directory
src/hooks
- Layout
src/hooks/use<HookName>.tsx
- Unit Tests
src/hooks/use<HookName>.spec.tsx
- Directory
src/assets
- SVG in
src/assets/svg
- Directory
src/state/<stateDomain>
- State domain directory
src/state/<stateDomain>
actions.ts
hooks.ts
reducer.ts
selectors.ts
updator.ts
- Directory
src/styles
- Theme in
src/styles/themes.ts
- Global Style (from styled-components) in
src/Global.tsx
- Google fonts in
src/styles.fonts.css
TypeScript interfaces that are used in more than one place should be stored here.
At DXdao, everyone thrives to write high-quality code. And such as every Contributor should follow best practices to achieve their goals.
Use two space to intend code. Lint code using Prettier. Configurations are stored in .prettierrc
IDE of choice should be able to format file upon saving file.
Except for external modules, all internal files must avoid default exports in ES6.
Good
// GoodExport.ts
export function GoodExport() {
return 'I am exported using export'
}
// index.ts
import { GoodExport } from './GoodExport.ts'
Bad
// NoSoGoodExport.ts
export function NoSoGoodExport() {
return 'I am exported using export'
}
// index.ts
import VeryGoodExport from './NoSoGoodExport.ts'
As you can see, with the second example, the imported name can be dynamic. Please avoid this.
Good
// Externals
import React from 'react'
// Components
import { Container } from 'src/components/Container'
import { CardBody } from 'src/components/CardBody'
import { Card } from 'src/components/Card'
// Layouts
import { Center } from 'src/layouts/Center'
export function IndexView() {
return (
<Center minHeight="100%">
<Container>
<Card>
<CardBody>Hello world</CardBody>
</Card>
</Container>
</Center>
)
}
- Use
TitleCase
for Components - Use `
Use camelCase
for variables and functions
Use CAPITAL_CASE
for constants.
The code base uses Jest and Cypress for e2e tests
Each Component/function/file should be accompanied with approriate tests.