|
| 1 | +## General Principles |
| 2 | + |
| 3 | +- Follow existing code style and patterns in the repository |
| 4 | +- Write clear, self-documenting code with descriptive variable and function names |
| 5 | +- Include comments for complex logic or non-obvious behavior |
| 6 | +- Always write tests for new functionality and changes |
| 7 | +- Update documentation for user-facing changes |
| 8 | +- Do not introduce new dependencies without discussion |
| 9 | + |
| 10 | + |
| 11 | +## Structure |
| 12 | + |
| 13 | +The repository is using nx, with the source code under the "packages" directory. |
| 14 | +Use nx to run tests (e.g. npx nx test server-shared). |
| 15 | +Run "npx nx lint" before committing. |
| 16 | + |
| 17 | +## Code Style |
| 18 | + |
| 19 | +### Formatting |
| 20 | + |
| 21 | +- **Indentation:** 2 spaces (TypeScript/JavaScript, shell scripts) |
| 22 | +- **Line length:** 100–120 characters preferred |
| 23 | +- **Braces:** Required for all control blocks, even single-line |
| 24 | +- **Spacing:** |
| 25 | + - One space between keywords and parentheses: `if (condition) {` |
| 26 | + - No trailing whitespace |
| 27 | + - Newline at end of file |
| 28 | +- **Linting:** Use ESLint as configured in each package |
| 29 | +- **Formatting:** Follow Prettier rules if configured |
| 30 | +- Respect `.editorconfig`, `.eslintrc`, `.prettierrc`, and other config files |
| 31 | + |
| 32 | +### Naming Conventions |
| 33 | + |
| 34 | +- **Variables/Functions:** `camelCase` |
| 35 | +- **Classes/Types:** `PascalCase` |
| 36 | +- **Constants:** `UPPER_SNAKE_CASE` |
| 37 | +- **Files:** Lowercase with hyphens (e.g., `user-profile.ts`) |
| 38 | + |
| 39 | +### Comments |
| 40 | + |
| 41 | +- Explain _why_ something is done, not _what_ (the code should be self-explanatory) |
| 42 | +- Use `TODO:` for actionable technical debt |
| 43 | +- Document public functions, classes, and modules |
| 44 | + |
| 45 | +## TypeScript/JavaScript |
| 46 | + |
| 47 | +### General Guidelines |
| 48 | + |
| 49 | +- Use types and interfaces where appropriate |
| 50 | +- Prefer `const` over `let` or `var` |
| 51 | +- Prefer arrow functions for callbacks and functional components |
| 52 | +- Use explicit return types for exported functions |
| 53 | + |
| 54 | +### Example |
| 55 | + |
| 56 | +```typescript |
| 57 | +export function getUserProfile(userId: string): UserProfile { |
| 58 | + if (!userId) { |
| 59 | + throw new Error('User ID required'); |
| 60 | + } |
| 61 | + // TODO: Replace with real data source |
| 62 | + return { id: userId, name: 'Sample User' }; |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +## Frontend Guidelines |
| 67 | + |
| 68 | +### Project Structure |
| 69 | + |
| 70 | +- Use the `react-ui` package for main application logic |
| 71 | +- Place pure, reusable components in the `ui-components` package, documented in Storybook |
| 72 | +- Place and write tests in a separate `tests` folder |
| 73 | + |
| 74 | +### Tech Stack |
| 75 | + |
| 76 | +- **React 18** |
| 77 | +- **Zustand** for state management |
| 78 | +- **react-query v5** for data fetching |
| 79 | +- **shadcn** for UI components |
| 80 | +- **Axios** (use existing wrapper in `api.ts`), use `qs` package for query strings |
| 81 | + |
| 82 | +### Best Practices |
| 83 | + |
| 84 | +- Follow best practices for React hooks |
| 85 | +- Prefer small, composable components |
| 86 | +- Extract helper functions where possible |
| 87 | +- Do not make breaking changes to existing code interfaces (component props, names) without discussion |
| 88 | +- Ensure compliance with strict linter setups (including Sonar) |
| 89 | +- Use `cn` utility to group Tailwind classnames: |
| 90 | + |
| 91 | +```tsx |
| 92 | +<div |
| 93 | + className={cn( |
| 94 | + 'absolute bottom-[-20px] left-1/2 -translate-x-1/2', |
| 95 | + 'w-[118px] h-[24px] flex items-center justify-center', |
| 96 | + 'font-satoshi font-medium text-xs text-blueAccent-500', |
| 97 | + 'border border-solid border-blueAccent-500 rounded-[4px]', |
| 98 | + 'bg-background-800', |
| 99 | + { |
| 100 | + 'pt-2': !someVar |
| 101 | + } |
| 102 | + )} |
| 103 | +> |
| 104 | + {t('Sample output data')} |
| 105 | +</div> |
| 106 | +``` |
| 107 | + |
| 108 | +## Testing |
| 109 | + |
| 110 | +- Use Jest for testing |
| 111 | +- Place unit tests in a `tests` folder alongside the code |
| 112 | +- Run tests using Nx commands: |
| 113 | + |
| 114 | +```bash |
| 115 | +nx test react-ui |
| 116 | +nx test ui-components |
| 117 | +nx test-unit server-api |
| 118 | +nx test engine |
| 119 | +nx lint react-ui |
| 120 | +``` |
| 121 | + |
| 122 | +## Git Workflow |
| 123 | + |
| 124 | +### Commits |
| 125 | + |
| 126 | +- Use imperative mood (e.g., "Fix bug" not "Fixed bug" or "Fixing bug") |
| 127 | +- Keep commits small and focused on a single change |
| 128 | +- Write descriptive commit messages that explain what and why, not how |
| 129 | + |
| 130 | +**Commit message format:** |
| 131 | + |
| 132 | +``` |
| 133 | +Short summary in imperative mood (under 50 chars) |
| 134 | +
|
| 135 | +More detailed explanation if necessary. Wrap at around 72 |
| 136 | +characters. Explain what and why, not how (the code shows that). |
| 137 | +
|
| 138 | +Fixes #issue_number |
| 139 | +``` |
| 140 | + |
| 141 | +### Pull Requests |
| 142 | + |
| 143 | +#### Size and Scope |
| 144 | + |
| 145 | +- Keep PRs focused on a single feature, bug fix, or improvement |
| 146 | +- Break down work into logical, small commits |
| 147 | +- Only include changes related to the issue, no unrelated modifications |
| 148 | + |
| 149 | +#### Title Requirements |
| 150 | + |
| 151 | +- Must start with a capital letter and a real word |
| 152 | +- Must have at least three words |
| 153 | +- Must use imperative mood (e.g., "Add GO support" not "Added GO support") |
| 154 | + |
| 155 | +#### Reference an issue |
| 156 | + |
| 157 | +All PRs must reference a linear issue in their body. |
| 158 | + |
| 159 | +Examples: |
| 160 | +- Fixes OPS-100. |
| 161 | +- Resolves OPS-101. |
| 162 | +- Part of CI-102. |
| 163 | + |
| 164 | +## Additional Resources |
| 165 | + |
| 166 | +- [CONTRIBUTING.md](./CONTRIBUTING.md) - General contribution guidelines |
| 167 | +- [.github/pull_request_template.md](./.github/pull_request_template.md) - PR template |
| 168 | +- [.github/prlint.json](./.github/prlint.json) - PR linting rules |
| 169 | +- [docs.openops.com](https://docs.openops.com) - Official OpenOps documentation |
0 commit comments