From 39f4a5991a4b9b614a9fe2a56f13f9f8800c3943 Mon Sep 17 00:00:00 2001 From: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> Date: Sat, 22 Nov 2025 22:08:52 +0800 Subject: [PATCH] Add cursor rules --- .cursor/rules/general.mdc | 71 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .cursor/rules/general.mdc diff --git a/.cursor/rules/general.mdc b/.cursor/rules/general.mdc new file mode 100644 index 00000000..daf16b4b --- /dev/null +++ b/.cursor/rules/general.mdc @@ -0,0 +1,71 @@ +--- +description: "Project-wide coding standards and tooling rules for Kotlin, Rust, C++, C, and Java (Gradle)." +globs: + - "**/*.kt" + - "**/*.rs" + - "**/*.cpp" + - "**/*.c" + - "**/*.java" +alwaysApply: true +--- + +# Project Coding Standards + +## Universal Rules +- Role: You are an expert senior engineer. Always generate maintainable, secure, performant, and idiomatic code. +- Prefer readability over cleverness. Keep changes focused and minimal. +- Follow SOLID, clean architecture, immutability-first, modular design. +- Remove unused imports, dead code, commented-out blocks, TODOs, debug logs. +- Use descriptive naming; avoid magic numbers. +- Document non-obvious logic and unsafe operations. + +## Formatting & Tooling +- Formatters to apply automatically on save or pre-commit: `ktlint`, `detekt`, `rustfmt`, `cargo clippy`, `clang-format`, `clang-tidy`, `spotless`. +- Pre-commit hooks should run: `ktlint --format`, `cargo fmt`, `clang-format -i`, `gradle spotlessApply`. +- CI must enforce formatting and linting; any violation should fail the build. + +## Kotlin (files matching `**/*.kt`) +- Target Kotlin version 1.9. +- Use `val` over `var` by default. +- Use data classes and sealed classes for value types. +- Use structured concurrency with coroutines; avoid `GlobalScope`. +- Avoid forced unwraps (`!!`); prefer safe calls (`?.`) and Elvis (`?:`) operators. +- Prefer extension functions for utilities. +- Tests must be written using JUnit 5. + +## Rust (files matching `**/*.rs`) +- Use Rust edition 2024. +- Replace `unwrap()` and `expect()` in production code with `Result` + `?` propagation. +- Avoid unnecessary `.clone()`; use borrowing and lifetimes properly. +- Avoid `unsafe` blocks unless strictly necessary, and document why. +- Always run `cargo fmt` and `cargo clippy`. + +## C++ (files matching `**/*.cpp`, `**/*.hpp`) +- Use C++23 standard. +- Avoid raw pointers; prefer `std::unique_ptr`, `std::shared_ptr`, `std::optional`. +- Use RAII for resource management. +- Prefer STL algorithms over manual loops. +- Avoid macros and global mutable state. +- Tests should be written using Google Test or equivalent. + +## C (files matching `**/*.c`, `**/*.h`) +- Use C23 standard where possible. +- Check return values of all system/library calls. +- Avoid global mutable state. +- Use `const` correctness in declarations. +- Leverage static analysis tools: `cppcheck`, `valgrind`. +- Use header/implementation separation properly. + +## Java + Gradle (files matching `build.gradle.kts`, `**/*.java`) +- Target Java version 21 (or higher if project permits). +- Use Gradle Kotlin DSL for build scripts. +- Prefer `record` for simple data carriers. +- Use `Optional` and `Stream` responsibly; prefer immutability. +- Build must be reproducible and minimal: avoid unnecessary plugins. +- Use `spotless` for formatting and `checkstyle` for static analysis. + +## Testing Rules +- For each new module, write unit tests. +- Test naming convention: `should_when`. +- Tests must be fast, deterministic, not rely on network/external I/O (use mocks as needed). +- Aim for coverage: critical paths ≥ 90%, overall modules ≥ 70%. \ No newline at end of file