-
Notifications
You must be signed in to change notification settings - Fork 4
CityCatalyst Coding Standards
Cephas Chapa edited this page Aug 15, 2023
·
6 revisions
To ensure uniformity of our code base the following standards should be applied.
- Indenting and Formatting:
- Choose an indentation style (e.g., 2 spaces or 4 spaces) and stick with it throughout the project.
- Use consistent line breaks and spacing for improved readability.
- Naming Conventions:
- Follow consistent naming conventions for variables, functions, classes, and components.
- Use meaningful and descriptive names that convey the purpose and functionality of the code element.
- For TypeScript, consider using camelCase for variables and functions, and PascalCase for classes and components.
- Type Annotations:
- Make full use of TypeScript's static type system to catch errors early.
- Always annotate function parameters and return types with appropriate type definitions.
- Use interfaces or type aliases for complex data structures.
- Imports and Exports:
- Use explicit import and export statements for better clarity.
- Organize imports alphabetically and group them by external dependencies, internal modules, and relative imports.
- Components and Containers:
- Separate your components into presentational (dumb) components and container (smart) components.
- Presentational components focus on rendering UI and receive data via props.
- Container components handle data logic and interact with Redux, state, or context.
- State Management:
- If using Redux, structure your store with actions, reducers, and selectors.
- Use async actions and middleware for handling asynchronous operations.
- Consider using the Redux Toolkit to simplify store setup and reduce boilerplate.
- File Structure:
- Organize your files and folders logically to promote easy navigation.
- Group related components, styles, and tests in the same directory.
- Code Comments:
- Write clear and concise comments explaining complex logic, algorithms, or code decisions.
- Avoid unnecessary comments that simply repeat what the code is doing.
- Testing:
- Write unit tests and integration tests for your components and functions.
- Use a testing library like Jest along with testing utilities like React Testing Library.
- Linting and Formatting Tools:
- Use ESLint and Prettier to enforce coding standards and formatting rules.
- Configure them to automatically format code and catch potential issues.
- Code Reviews:
- Conduct regular code reviews to ensure adherence to coding standards.
- Encourage team members to provide constructive feedback during reviews.
- Documentation:
- Maintain a README file with project setup instructions, architecture overview, and any other necessary information.
- Document important decisions, libraries used, and any coding guidelines that may not be obvious.