Rules and Conventions
In order to enforce a consistent code style and avoid common issues in the codebase, we have a set of rules and conventions that we follow and enforce through the starter.
Typescript
This starter uses TypeScript to provide type safety and avoid common bugs in the codebase. The project configuration is based on Expo config with some updates to support absolute imports.
If you are not familiar with Typescript, you can check this article to learn more about it : Typescript for React Developers
You can find more information about it here.
Naming
We follow kabab-case for naming files and folders as we think itβs the most readable and consistent way to name files and folders in large projects and itβs the most common way to name files and folders in the react native community.
Example of kabab-case naming: my-component.tsx
For naming variables, functions, classes, interfaces, and enums, we follow camelCase as itβs the most common way to name variables in the React community. It is enforced by the linter, as you cannot create a function component without using camelCase.
Linting
Using a linter is a must in any JavaScript project. For starters, we are using ESLint with the React Native community config and some custom rules to ensure that we are following the rules and conventions related to file naming, Tailwind CSS classes, TypeScript types, import order, internationalization files, and more.
Here is the complete ESLint configuration file:
Git Hooks with Husky
The starter comes with a set of git hooks that help us to enforce rules and conventions. Those hooks are configured using Husky. and here is the complete list of the hooks:
pre-commit
As the name suggest, this hook will run before each commit and it will make sure you are not committing directly on the main branch and it will run the linter and typescript checking on the staged files.
post-merge
As the name suggest, this hook will run after each merge and it will check if there is any changed in pnpm-lock.yaml and if there is any, it will run pnpm install
to make sure the dependencies are up to date.
commit-msg
This hook will check if the commit message is following the conventional commit format. If itβs not, the commit will be aborted and will show you what going wrong with your commit message.
We are using commitlint to check if the commit message is following the conventional commit format.
In general, your commit message should follow this format:
Real world examples can look like this:
type
should be one of the following: build, chore, ci ,docs,feat,fix, perf, refactor, revert, style or test.