Welcome to the Code Style and Contribution Guidelines for LobeHub. This guide will help you understand our code standards and contribution process, ensuring code consistency and smooth project progression.
In LobeHub, we use the [@lobehub/lint](https://github.com/lobehub/lobe-lint) package to maintain a unified code style. This package incorporates configurations for `ESLint`, `Prettier`, `remarklint`, and `stylelint` to ensure that our JavaScript, Markdown, and CSS files adhere to the same coding standards.
We use ESLint to check for issues in our JavaScript code. You can find the `.eslintrc.js` file in the project's root directory, which contains our extensions and custom rules for the ESLint configuration of `@lobehub/lint`.
To ensure your code aligns with the project's standards, run ESLint before committing your code.
### Prettier
Prettier is responsible for code formatting to maintain consistency. Our Prettier configuration can be found in `.prettierrc.js`, imported from `@lobehub/lint`.
For Markdown files, we use remarklint to ensure consistent document formatting. You can find the corresponding configuration file in the project.
### stylelint
We utilize stylelint to standardize the style of our CSS code. In the configuration file for stylelint, we have made some custom rule adjustments based on `@lobehub/lint` configuration.
You don't need to manually run these checks. The project is configured with husky to automatically run lint-staged when you commit code, which will check if your committed files comply with the above standards.
When committing code, please use gitmoji to label your commit messages. This helps other contributors quickly understand the content and purpose of your submission.
Gitmoji commit messages use specific emojis to represent the type or intent of the commit. Here's an example:
We use semantic release to automate version control and release processes. When a PR is merged into the main branch, the system automatically determines whether to publish a new version based on the gitmoji prefix in commit messages:
- Commits with `✨ feat` or `🐛 fix` prefixes will **trigger a new release**
- For minor changes that don't need a release, use prefixes like `💄 style` or `🔨 chore`
To ensure consistency in commit messages, we use `commitlint` to check the format of commit messages. You can find the relevant rules in the `.commitlintrc.js` configuration file.
Before committing your code, ensure that your commit messages adhere to our standards.
LobeHub has comprehensive unit tests (Vitest) and E2E tests (Cucumber + Playwright), which run automatically via GitHub Actions CI on every PR. Before submitting a PR or requesting a merge, make sure all tests pass.
You can run specific test files locally to verify:
```bash
# Run specific test (never run bun run test — full suite is very slow)
bunx vitest run --silent='passed-only' '[file-path]'
```
For more testing details, see the [Testing Guide](/docs/development/basic/test).
Use the branch naming format: `username/type/description`
```bash
git checkout -b yourname/feat/add-voice-input
git checkout -b yourname/fix/message-duplication
git checkout -b yourname/docs/update-api-guide
```
**3. Make changes**
Follow the [code style guidelines](/docs/development/basic/contributing-guidelines#code-style) above. Run linters before committing:
```bash
pnpm lint:ts # TypeScript/JavaScript
pnpm lint:style # CSS/styles
bun run type-check # Type checking
```
**4. Commit with gitmoji**
```bash
git commit -m "✨ feat: add voice input support"
git commit -m "🐛 fix: resolve message duplication in group chat"
git commit -m "📝 docs: update installation guide"
```
**5. Open a Pull Request**
<Callout type={'warning'}>
Always target the **`canary`** branch — not `main`. `canary` is the active development branch.
PRs to `main` will be redirected.
</Callout>
Fill out the PR template in `.github/PULL_REQUEST_TEMPLATE.md`:
```markdown
## Description
Clear description of what this PR does.
## Type of Change
- [ ] ✨ New feature
- [ ] 🐛 Bug fix
- [ ] 📝 Documentation
- [ ] ♻️ Refactoring
## Checklist
- [ ] Code follows project style guidelines
- [ ] Tests added/updated
- [ ] Documentation updated
- [ ] All tests pass
## Related Issues
Fixes #123
```
**PR titles with `✨ feat:` or `🐛 fix:` automatically trigger a new release.** Use other prefixes for changes that don't need a release.
**6. Code review**
Automated checks run on every PR: ESLint, TypeScript type check, Vitest unit tests, E2E tests, and build. Address review feedback by pushing additional commits to the same branch.