This document outlines the coding style and conventions used in the snap-7715-permissions project.
- Use UTF-8 encoding for all files
- Use 2 spaces for indentation
- Use camelCase for variables, functions, and method names
- Use camelCase for file names
- Use JSDoc comments for public APIs
- Include descriptions for parameters and return values
- Document thrown exceptions
Example:
/**
* Description of the function.
*
* @param options - The options object.
* @param options.param1 - Description of param1.
* @returns Description of the return value.
* @throws When something goes wrong.
*/- Use descriptive error messages
- Prefer custom error classes for specific error types
- Handle errors appropriately
- Use errors as defined in https://docs.metamask.io/snaps/how-to/communicate-errors/
- Use Jest for unit and integration tests
- Name test files with
.test.tssuffix - Group related tests with
describeblocks - Use clear and descriptive test names with
itstatements - Use mocks for external dependencies
Example:
describe('MyFunction', () => {
it('returns the expected result when given valid input', () => {
// Arrange
const input = 'valid input';
// Act
const result = myFunction(input);
// Assert
expect(result).toBe('expected output');
});
});- Organize code by feature or domain
- Keep files focused on a single responsibility
- Use barrel exports (index.ts files) sparingly, and with named exports, to simplify imports
- Separate interfaces/types into their own files when they become large
- Create feature branches from
main - Use descriptive commit messages
- All pull requests must be linked to an open issue
- Pull requests should target the
mainbranch
/packages: Contains all the project packages/scripts: Contains build and utility scripts/docs: Project documentation/external: External dependencies
- Use Yarn as the package manager
- Pin dependency versions where appropriate
- Follow the Single Responsibility Principle
- Write pure functions when possible
- Use async/await for asynchronous code
- Use descriptive variable names
- Keep functions small and focused
- Use TypeScript's type system to prevent bugs
- Document complex logic with comments
- Write tests for all new functionality