360 Secure SkillHub
360 安全技能中心

code-quality

该技能是一份代码质量指南,强调生产数据库场景下的正确性、错误处理、断言与无效状态处理,并给出 Rust 模式、条件分支、注释、索引变更、清理和单次辅助函数等规范;不包含自动化检查、脚本或工具。

分类:开发
tursodatabase
热度 0.00
最近更新 2026-10-19 04:25:39

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add tursodatabase/turso/code-quality
兼容性
通用兼容
联网要求
不联网
数据出网
数据不出本机
Metadata
name
code-quality
description
General Correctness rules, Rust patterns, comments, avoiding over-engineering. When writing code always take these into account

Code Quality Guide

Core Principle

Production database. Correctness paramount. Crash > corrupt.

Correctness Rules

  1. No workarounds or quick hacks. Handle all errors, check invariants
  2. Assert often. Never silently fail or swallow edge cases
  3. Crash on invalid state if it risks data integrity. Don't continue in undefined state
  4. Consider edge cases. On long enough timeline, all possible bugs will happen

Rust Patterns

  • Make illegal states unrepresentable
  • Exhaustive pattern matching
  • Prefer enums over strings/sentinels
  • Minimize heap allocations
  • Write CPU-friendly code (microsecond = long time)

If-Statements

Wrong:

if condition {
    // happy path
} else {
    // "shouldn't happen" - silently ignored
}

Right:

// If only one branch should ever be hit:
assert!(condition, "invariant violated: ...");
// OR
return Err(LimboError::InternalError("unexpected state".into()));
// OR
unreachable!("impossible state: ...");

Use if-statements only when both branches are expected paths.

Comments

  • Don't add code comments, except for rust SAFETY comments.

Avoid Over-Engineering

  • Only changes directly requested or clearly necessary
  • Don't add features beyond what's asked
  • Don't add docstrings/comments to unchanged code
  • Don't add error handling for impossible scenarios
  • Don't create abstractions for one-time operations
  • Three similar lines > premature abstraction

Index Mutations

When code involves index inserts, deletes, or conflict resolution, double-check the ordering against SQLite. Wrong ordering causes index inconsistencies. and easy to miss.

Ensure understanding of IO model

Cleanup

  • Delete unused code completely
  • No backwards-compat hacks (renamed _vars, re-exports, // removed comments)

Single-use helpers

If a helper function has no meaning outside of a single use case, move it inside the function that uses it:

fn do_something() {
    
    something_specific();

    fn something_specific() {
    }
}