Cursor Kotlin 编码规范

Model: qwen-max | ¥0.15/call
AI工具GPT-4.1智能助手CursorKotlin

Cursor Kotlin 编码规范:来自 PatrickJS/awesome-cursorrules (40k stars) 的 kot,适用于各类文档与内容的智能化处理。

Calls: 1

Skill Documentation

Cursor Kotlin 编码规范

摘要

Cursor Kotlin 编码规范:来自 PatrickJS/awesome-cursorrules (40k stars) 的 kot,适用于各类文档与内容的智能化处理。

**文件来源:** PatrickJS/awesome-cursorrules → `rules/kotlin-springboot-best-practices-cursorrules-prompt-file.mdc`

**原仓库:** https://github.com/PatrickJS/awesome-cursorrules

**评分:** ⭐ 仓库 40k stars (社区最权威 Cursor rules 合集)

这个 skill 是干什么的?

把 `kotlin-springboot-best-practices-cursorrules-prompt-file.mdc` 这条 Cursor 编码规则打包成可调用的 AI skill,帮你把代码生成统一到一致的标准上。

> Cursor rules for Kotlin Springboot Best Practices.

🤖 Agent 使用说明

👤 用户需要做什么?

适用场景

原始规则内容

globs: **/*
alwaysApply: false
---
# Kotlin Coding Best Practices for Spring Boot Development

## Project Structure and Organization

1.	Group your source code into clearly defined packages like controller, service, repository, and model to separate concerns and improve maintainability.
2.	Organize your file system so that each directory mirrors the Kotlin package name (e.g. put com.myapp.users under src/main/kotlin/com/myapp/users).
3.	Name each Kotlin file after the primary class or concept it contains to make the codebase easier to navigate and understand.
4.	Avoid vague file names like Utils.kt; instead, use concise and meaningful names that reflect the purpose of the file’s contents.
5.	Place your Spring Boot application entry point in the root package and structure sub-packages by layer or feature to help Spring scan and organize components efficiently.

## Coding Style and Conventions

1.	Use PascalCase for class and object names, camelCase for functions and variables, and UPPER_SNAKE_CASE for constants to follow Kotlin naming conventions and improve readability.
2.	Declare variables using `val` by default, and only use `var` when mutation is necessary to promote safer, more predictable code.

val maxConnections = 10 // immutable reference

var currentUsers = 0 // mutable, try to avoid if possible

3.	Limit the scope of variables to where they are actually used—inside functions or smaller blocks—to avoid accidental misuse and make code easier to follow.
4.	Format your code consistently using 4-space indentation, proper spacing around operators and commas, and short, focused functions to improve clarity and maintainability.
5.	Write clear and expressive code instead of clever one-liners; break complex logic into intermediate variables or well-named functions to improve readability.
6.	Name classes, functions, and variables descriptively to convey intent, and avoid vague suffixes like '-Manager' or '-Helper' that don’t add meaning.
7.	Keep property getters and setters simple and free of heavy logic; if complex behavior is needed, move it into a separate method to keep property access predictable.

## Idiomatic Kotlin Usage

1.	Use data class to define DTOs and entities so you get useful methods like `equals()` and `copy()` without writing boilerplate code.
2.	Replace overloaded constructors with default and named parameters to simplify function calls and make them more expressive.

// Kotlin – use default parameters

fun createConnection(host: String, secure: Boolean = true) { … }

createConnection("example.com") // uses default secure=true

createConnection(host = "test.com", secure = false) // named arg for clarity

3.	Use `when` expressions instead of long `if-else` chains to write cleaner, more readable conditional logic that clearly handles each case.
4.	Create extension functions instead of utility classes to add reusable behavior to existing 

...(完整内容在原仓库)...

数据来源

联系方式

有问题或建议,在本 skill 下留言。

FAQ

这个 skill 是干什么的?

把 `kotlin-springboot-best-practices-cursorrules-prompt-file.mdc` 这条 Cursor 编码规则打包成可调用的 AI skill,帮你把代码生成统一到一致的标准上。

> Cursor rules for Kotlin Springboot Best Practices.

👤 用户需要做什么?
  • [ ] 知道这条规则适合用在什么场景(参考下面"适用场景")
  • [ ] 把规则原文内容应用到 IDE 项目的 `.cursor/rules/` 目录(直接复制 .mdc 文件)
  • [ ] 调本 skill 时说清楚你的代码任务(语言/框架/目标)
  • [ ] 输出后人工 review 风格是否符合预期