This document outlines the coding style and conventions to be followed when contributing to the Fundable Stellar project. Adhering to these guidelines ensures consistency and readability across the codebase.
- Follow Existing Conventions: When in doubt, look at the existing code in the file or related files and follow its patterns.
- Write Clear and Readable Code: Write code that is easy for other developers to understand. Favor clarity over brevity.
- Keep it Simple: Avoid unnecessary complexity.
We use Prettier for automatic code formatting and ESLint for identifying and reporting on patterns in JavaScript.
All TypeScript/JavaScript code is formatted using Prettier. It's recommended to set up your editor to format on save. A .prettierrc file should be present in the project with the configuration.
Example .prettierrc:
{
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
}ESLint helps us to prevent bugs and ensure code quality. The configuration can be found in eslint.config.mjs (or similar). Please ensure your contributions have no ESLint errors.
- Variables and Functions: Use
camelCase.const myVariable = '...';function doSomething() { ... }
- Classes, Interfaces, and React Components: Use
PascalCase.class MyClass { ... }interface UserProfile { ... }function UserProfile() { ... }
- Constants: Use
UPPER_SNAKE_CASEfor constants that are hardcoded and reused across the application.const MAX_RETRIES = 3;
We follow the principles of Atomic Design to structure our React components. This helps in creating a scalable and maintainable component library.
Reusable components are located in the src/components directory and are categorized into the following levels:
-
Atoms: The smallest, indivisible UI elements. These are the building blocks of your application.
- Location:
src/components/atoms - Examples:
Button,Input,Label,Icon
- Location:
-
Molecules: Simple groups of atoms that form a functional unit.
- Location:
src/components/molecules - Examples:
SearchForm(composed of anInputand aButton),SocialLinks
- Location:
-
Organisms: More complex components that consist of molecules and/or atoms. These form distinct sections of an interface.
- Location:
src/components/organisms - Examples:
Header,Footer,Sidebar
- Location:
Components that are specific to a particular page or route should not be placed in the global components directory. Instead, they should be located in a modules folder within the page's directory.
- Location:
src/app/(pages)/<page-name>/modules - Example: For a user profile page at
src/app/(pages)/profile/page.tsx, a specific component likeProfileHeaderwould be located atsrc/app/(pages)/profile/modules/ProfileHeader.tsx.
Organize imports at the top of the file in the following order:
- React imports
- External library imports
- Internal module imports (from the same project)
- Relative imports
- Use comments to explain why something is done, not what is being done. The code should be self-explanatory about what it does.
- Use
// TODO:for planned work. - Use
// FIXME:for code that needs to be fixed.
For Rust code, we adhere to the standard Rust conventions, enforced by rustfmt and clippy.
All Rust code is formatted using rustfmt. Ensure you have it installed (rustup component add rustfmt) and run cargo fmt before committing your changes.
Clippy is used to catch common mistakes and improve your code. Run cargo clippy to check your code for lints.
- Variables and Functions: Use
snake_case.let my_variable = 10;fn do_something() { ... }
- Structs, Enums, and Traits: Use
PascalCase.struct MyStruct { ... }enum MyEnum { ... }
- Constants: Use
UPPER_SNAKE_CASE.const MAX_VALUE: u32 = 100;
- Use doc comments (
///) to document all public functions, structs, and enums. Explain what the item does, its parameters, and what it returns. - This documentation is used to generate the contract's API reference.