oh-my-customcode 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +287 -0
- package/dist/cli/index.js +13299 -0
- package/dist/index.js +927 -0
- package/package.json +74 -0
- package/templates/.claude/contexts/dev.md +20 -0
- package/templates/.claude/contexts/ecomode.md +63 -0
- package/templates/.claude/contexts/index.yaml +41 -0
- package/templates/.claude/contexts/research.md +28 -0
- package/templates/.claude/contexts/review.md +23 -0
- package/templates/.claude/hooks/hooks.json +185 -0
- package/templates/.claude/hooks/hud/index.yaml +27 -0
- package/templates/.claude/hooks/hud/update-status.sh +32 -0
- package/templates/.claude/hooks/index.yaml +46 -0
- package/templates/.claude/hooks/memory-persistence/pre-compact.sh +37 -0
- package/templates/.claude/hooks/memory-persistence/session-end.sh +64 -0
- package/templates/.claude/hooks/memory-persistence/session-start.sh +41 -0
- package/templates/.claude/hooks/strategic-compact/suggest-compact.sh +50 -0
- package/templates/.claude/install-hooks.sh +100 -0
- package/templates/.claude/rules/MAY-optimization.md +93 -0
- package/templates/.claude/rules/MUST-agent-design.md +107 -0
- package/templates/.claude/rules/MUST-agent-identification.md +108 -0
- package/templates/.claude/rules/MUST-continuous-improvement.md +132 -0
- package/templates/.claude/rules/MUST-intent-transparency.md +199 -0
- package/templates/.claude/rules/MUST-language-policy.md +62 -0
- package/templates/.claude/rules/MUST-orchestrator-coordination.md +266 -0
- package/templates/.claude/rules/MUST-parallel-execution.md +341 -0
- package/templates/.claude/rules/MUST-permissions.md +84 -0
- package/templates/.claude/rules/MUST-safety.md +69 -0
- package/templates/.claude/rules/MUST-sync-verification.md +219 -0
- package/templates/.claude/rules/MUST-tool-identification.md +112 -0
- package/templates/.claude/rules/SHOULD-ecomode.md +145 -0
- package/templates/.claude/rules/SHOULD-error-handling.md +102 -0
- package/templates/.claude/rules/SHOULD-hud-statusline.md +89 -0
- package/templates/.claude/rules/SHOULD-interaction.md +103 -0
- package/templates/.claude/rules/SHOULD-memory-integration.md +114 -0
- package/templates/.claude/rules/SHOULD-pipeline-mode.md +165 -0
- package/templates/.claude/rules/index.yaml +125 -0
- package/templates/.claude/uninstall-hooks.sh +52 -0
- package/templates/CLAUDE.md.en +259 -0
- package/templates/CLAUDE.md.ko +259 -0
- package/templates/agents/index.yaml +237 -0
- package/templates/agents/infra-engineer/aws-expert/AGENT.md +47 -0
- package/templates/agents/infra-engineer/aws-expert/index.yaml +27 -0
- package/templates/agents/infra-engineer/docker-expert/AGENT.md +47 -0
- package/templates/agents/infra-engineer/docker-expert/index.yaml +27 -0
- package/templates/agents/manager/creator/AGENT.md +274 -0
- package/templates/agents/manager/creator/index.yaml +66 -0
- package/templates/agents/manager/gitnerd/AGENT.md +91 -0
- package/templates/agents/manager/gitnerd/index.yaml +55 -0
- package/templates/agents/manager/sauron/AGENT.md +153 -0
- package/templates/agents/manager/sauron/index.yaml +52 -0
- package/templates/agents/manager/supplier/AGENT.md +142 -0
- package/templates/agents/manager/supplier/index.yaml +31 -0
- package/templates/agents/manager/sync-checker/AGENT.md +34 -0
- package/templates/agents/manager/sync-checker/index.yaml +32 -0
- package/templates/agents/manager/updater/AGENT.md +125 -0
- package/templates/agents/manager/updater/index.yaml +31 -0
- package/templates/agents/orchestrator/dev-lead/AGENT.md +116 -0
- package/templates/agents/orchestrator/dev-lead/index.yaml +73 -0
- package/templates/agents/orchestrator/planner/AGENT.md +102 -0
- package/templates/agents/orchestrator/planner/index.yaml +38 -0
- package/templates/agents/orchestrator/qa-lead/AGENT.md +92 -0
- package/templates/agents/orchestrator/qa-lead/index.yaml +40 -0
- package/templates/agents/orchestrator/secretary/AGENT.md +132 -0
- package/templates/agents/orchestrator/secretary/index.yaml +55 -0
- package/templates/agents/qa-team/qa-engineer/AGENT.md +98 -0
- package/templates/agents/qa-team/qa-engineer/index.yaml +59 -0
- package/templates/agents/qa-team/qa-planner/AGENT.md +75 -0
- package/templates/agents/qa-team/qa-planner/index.yaml +47 -0
- package/templates/agents/qa-team/qa-writer/AGENT.md +98 -0
- package/templates/agents/qa-team/qa-writer/index.yaml +44 -0
- package/templates/agents/sw-architect/documenter/AGENT.md +120 -0
- package/templates/agents/sw-architect/documenter/index.yaml +39 -0
- package/templates/agents/sw-architect/speckit-agent/AGENT.md +127 -0
- package/templates/agents/sw-architect/speckit-agent/index.yaml +78 -0
- package/templates/agents/sw-engineer/backend/express-expert/AGENT.md +132 -0
- package/templates/agents/sw-engineer/backend/express-expert/index.yaml +36 -0
- package/templates/agents/sw-engineer/backend/fastapi-expert/AGENT.md +47 -0
- package/templates/agents/sw-engineer/backend/fastapi-expert/index.yaml +27 -0
- package/templates/agents/sw-engineer/backend/go-backend-expert/AGENT.md +47 -0
- package/templates/agents/sw-engineer/backend/go-backend-expert/index.yaml +27 -0
- package/templates/agents/sw-engineer/backend/nestjs-expert/AGENT.md +107 -0
- package/templates/agents/sw-engineer/backend/nestjs-expert/index.yaml +43 -0
- package/templates/agents/sw-engineer/backend/springboot-expert/AGENT.md +103 -0
- package/templates/agents/sw-engineer/backend/springboot-expert/index.yaml +69 -0
- package/templates/agents/sw-engineer/frontend/svelte-agent/AGENT.md +71 -0
- package/templates/agents/sw-engineer/frontend/svelte-agent/index.yaml +41 -0
- package/templates/agents/sw-engineer/frontend/vercel-agent/AGENT.md +67 -0
- package/templates/agents/sw-engineer/frontend/vercel-agent/index.yaml +43 -0
- package/templates/agents/sw-engineer/frontend/vuejs-agent/AGENT.md +71 -0
- package/templates/agents/sw-engineer/frontend/vuejs-agent/index.yaml +48 -0
- package/templates/agents/sw-engineer/language/golang-expert/AGENT.md +47 -0
- package/templates/agents/sw-engineer/language/golang-expert/index.yaml +27 -0
- package/templates/agents/sw-engineer/language/java21-expert/AGENT.md +122 -0
- package/templates/agents/sw-engineer/language/java21-expert/index.yaml +51 -0
- package/templates/agents/sw-engineer/language/kotlin-expert/AGENT.md +47 -0
- package/templates/agents/sw-engineer/language/kotlin-expert/index.yaml +27 -0
- package/templates/agents/sw-engineer/language/python-expert/AGENT.md +47 -0
- package/templates/agents/sw-engineer/language/python-expert/index.yaml +27 -0
- package/templates/agents/sw-engineer/language/rust-expert/AGENT.md +47 -0
- package/templates/agents/sw-engineer/language/rust-expert/index.yaml +27 -0
- package/templates/agents/sw-engineer/language/typescript-expert/AGENT.md +47 -0
- package/templates/agents/sw-engineer/language/typescript-expert/index.yaml +27 -0
- package/templates/agents/sw-engineer/tooling/bun-expert/AGENT.md +73 -0
- package/templates/agents/sw-engineer/tooling/bun-expert/index.yaml +46 -0
- package/templates/agents/sw-engineer/tooling/npm-expert/AGENT.md +160 -0
- package/templates/agents/sw-engineer/tooling/npm-expert/index.yaml +45 -0
- package/templates/agents/sw-engineer/tooling/optimizer/AGENT.md +170 -0
- package/templates/agents/sw-engineer/tooling/optimizer/index.yaml +45 -0
- package/templates/agents/system/memory-keeper/AGENT.md +126 -0
- package/templates/agents/system/memory-keeper/index.yaml +45 -0
- package/templates/agents/system/naggy/AGENT.md +72 -0
- package/templates/agents/system/naggy/index.yaml +35 -0
- package/templates/commands/COMMANDS.md +136 -0
- package/templates/commands/creator/agent.md +121 -0
- package/templates/commands/dev/refactor.md +126 -0
- package/templates/commands/dev/review.md +82 -0
- package/templates/commands/git/branch.yaml +8 -0
- package/templates/commands/git/commit.yaml +4 -0
- package/templates/commands/git/pr.yaml +4 -0
- package/templates/commands/git/status.yaml +4 -0
- package/templates/commands/git/sync.yaml +4 -0
- package/templates/commands/index.yaml +225 -0
- package/templates/commands/intent/explain.md +144 -0
- package/templates/commands/memory/recall.md +164 -0
- package/templates/commands/memory/save.md +128 -0
- package/templates/commands/naggy/add.yaml +8 -0
- package/templates/commands/naggy/done.yaml +8 -0
- package/templates/commands/naggy/list.yaml +4 -0
- package/templates/commands/naggy/priority.yaml +11 -0
- package/templates/commands/naggy/remind.yaml +4 -0
- package/templates/commands/npm/audit.yaml +62 -0
- package/templates/commands/npm/publish.yaml +52 -0
- package/templates/commands/npm/version.yaml +62 -0
- package/templates/commands/optimize/analyze.yaml +34 -0
- package/templates/commands/optimize/bundle.yaml +50 -0
- package/templates/commands/optimize/report.yaml +56 -0
- package/templates/commands/pipeline/list.md +81 -0
- package/templates/commands/pipeline/run.md +127 -0
- package/templates/commands/sauron/quick.yaml +4 -0
- package/templates/commands/sauron/report.yaml +4 -0
- package/templates/commands/sauron/watch.yaml +4 -0
- package/templates/commands/supplier/audit.md +133 -0
- package/templates/commands/supplier/fix.md +121 -0
- package/templates/commands/sync/agents.yaml +4 -0
- package/templates/commands/sync/check.yaml +4 -0
- package/templates/commands/sync/commands.yaml +4 -0
- package/templates/commands/sync/docs.yaml +4 -0
- package/templates/commands/sync/fix.yaml +4 -0
- package/templates/commands/system/help.md +137 -0
- package/templates/commands/system/lists.md +86 -0
- package/templates/commands/system/status.md +163 -0
- package/templates/commands/updater/docs.md +165 -0
- package/templates/commands/updater/external.md +214 -0
- package/templates/guides/aws/common-patterns.md +169 -0
- package/templates/guides/aws/index.yaml +26 -0
- package/templates/guides/aws/well-architected.md +143 -0
- package/templates/guides/claude-code/01-overview.md +42 -0
- package/templates/guides/claude-code/03-tools.md +107 -0
- package/templates/guides/claude-code/04-agent-skills.md +90 -0
- package/templates/guides/claude-code/05-agent-sdk.md +129 -0
- package/templates/guides/claude-code/06-mcp.md +165 -0
- package/templates/guides/claude-code/07-prompt-engineering.md +100 -0
- package/templates/guides/claude-code/08-testing.md +58 -0
- package/templates/guides/claude-code/09-guardrails.md +80 -0
- package/templates/guides/claude-code/10-monitoring.md +89 -0
- package/templates/guides/claude-code/index.yaml +51 -0
- package/templates/guides/docker/compose-best-practices.md +284 -0
- package/templates/guides/docker/dockerfile-best-practices.md +262 -0
- package/templates/guides/docker/index.yaml +26 -0
- package/templates/guides/fastapi/best-practices.md +232 -0
- package/templates/guides/fastapi/index.yaml +21 -0
- package/templates/guides/go-backend/index.yaml +26 -0
- package/templates/guides/go-backend/project-layout.md +243 -0
- package/templates/guides/go-backend/uber-style.md +212 -0
- package/templates/guides/golang/concurrency.md +282 -0
- package/templates/guides/golang/effective-go.md +309 -0
- package/templates/guides/golang/error-handling.md +250 -0
- package/templates/guides/golang/index.yaml +27 -0
- package/templates/guides/index.yaml +101 -0
- package/templates/guides/kotlin/coding-conventions.md +247 -0
- package/templates/guides/kotlin/idioms.md +234 -0
- package/templates/guides/kotlin/index.yaml +26 -0
- package/templates/guides/python/index.yaml +26 -0
- package/templates/guides/python/pep8-style-guide.md +202 -0
- package/templates/guides/python/zen-of-python.md +79 -0
- package/templates/guides/rust/error-handling.md +262 -0
- package/templates/guides/rust/index.yaml +26 -0
- package/templates/guides/rust/ownership.md +180 -0
- package/templates/guides/springboot/best-practices.md +361 -0
- package/templates/guides/springboot/index.yaml +22 -0
- package/templates/guides/typescript/advanced-types.md +225 -0
- package/templates/guides/typescript/index.yaml +26 -0
- package/templates/guides/typescript/type-system.md +219 -0
- package/templates/guides/web-design/accessibility.md +66 -0
- package/templates/guides/web-design/index.yaml +20 -0
- package/templates/guides/web-design/performance.md +102 -0
- package/templates/pipelines/examples/code-review.yaml +66 -0
- package/templates/pipelines/index.yaml +18 -0
- package/templates/pipelines/templates/pipeline-template.yaml +50 -0
- package/templates/skills/backend/fastapi-best-practices/SKILL.md +269 -0
- package/templates/skills/backend/fastapi-best-practices/index.yaml +25 -0
- package/templates/skills/backend/go-backend-best-practices/SKILL.md +337 -0
- package/templates/skills/backend/go-backend-best-practices/index.yaml +26 -0
- package/templates/skills/backend/springboot-best-practices/SKILL.md +356 -0
- package/templates/skills/backend/springboot-best-practices/index.yaml +27 -0
- package/templates/skills/development/go-best-practices/SKILL.md +202 -0
- package/templates/skills/development/go-best-practices/index.yaml +25 -0
- package/templates/skills/development/kotlin-best-practices/SKILL.md +255 -0
- package/templates/skills/development/kotlin-best-practices/index.yaml +27 -0
- package/templates/skills/development/python-best-practices/SKILL.md +221 -0
- package/templates/skills/development/python-best-practices/index.yaml +25 -0
- package/templates/skills/development/react-best-practices/SKILL.md +100 -0
- package/templates/skills/development/react-best-practices/index.yaml +39 -0
- package/templates/skills/development/rust-best-practices/SKILL.md +266 -0
- package/templates/skills/development/rust-best-practices/index.yaml +26 -0
- package/templates/skills/development/typescript-best-practices/SKILL.md +320 -0
- package/templates/skills/development/typescript-best-practices/index.yaml +28 -0
- package/templates/skills/development/vercel-deploy/SKILL.md +73 -0
- package/templates/skills/development/vercel-deploy/index.yaml +30 -0
- package/templates/skills/development/web-design-guidelines/SKILL.md +117 -0
- package/templates/skills/development/web-design-guidelines/index.yaml +34 -0
- package/templates/skills/index.yaml +129 -0
- package/templates/skills/infrastructure/aws-best-practices/SKILL.md +279 -0
- package/templates/skills/infrastructure/aws-best-practices/index.yaml +27 -0
- package/templates/skills/infrastructure/docker-best-practices/SKILL.md +274 -0
- package/templates/skills/infrastructure/docker-best-practices/index.yaml +26 -0
- package/templates/skills/orchestration/intent-detection/SKILL.md +214 -0
- package/templates/skills/orchestration/intent-detection/index.yaml +30 -0
- package/templates/skills/orchestration/intent-detection/patterns/agent-triggers.yaml +333 -0
- package/templates/skills/orchestration/pipeline-execution/SKILL.md +188 -0
- package/templates/skills/orchestration/pipeline-execution/index.yaml +27 -0
- package/templates/skills/system/memory-management/SKILL.md +194 -0
- package/templates/skills/system/memory-management/index.yaml +30 -0
- package/templates/skills/system/result-aggregation/SKILL.md +163 -0
- package/templates/skills/system/result-aggregation/index.yaml +36 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# Kotlin Coding Conventions
|
|
2
|
+
|
|
3
|
+
> Source: https://kotlinlang.org/docs/coding-conventions.html
|
|
4
|
+
|
|
5
|
+
## Source Code Organization
|
|
6
|
+
|
|
7
|
+
### Directory Structure
|
|
8
|
+
|
|
9
|
+
Follow package structure with common root omitted:
|
|
10
|
+
- `org.example.kotlin.network.socket` → `network/socket` subdirectory
|
|
11
|
+
|
|
12
|
+
### Source File Names
|
|
13
|
+
|
|
14
|
+
| Content | File Name |
|
|
15
|
+
|---------|-----------|
|
|
16
|
+
| Single class | `MyClass.kt` |
|
|
17
|
+
| Multiple declarations | `ProcessDeclarations.kt` |
|
|
18
|
+
| Platform-specific | `Platform.jvm.kt` |
|
|
19
|
+
|
|
20
|
+
### Class Layout
|
|
21
|
+
|
|
22
|
+
1. Property declarations and initializer blocks
|
|
23
|
+
2. Secondary constructors
|
|
24
|
+
3. Method declarations
|
|
25
|
+
4. Companion object
|
|
26
|
+
|
|
27
|
+
```kotlin
|
|
28
|
+
class MyClass(val name: String) {
|
|
29
|
+
// 1. Properties
|
|
30
|
+
private val items = mutableListOf<Item>()
|
|
31
|
+
|
|
32
|
+
init {
|
|
33
|
+
// initializer block
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 2. Secondary constructors
|
|
37
|
+
constructor() : this("default")
|
|
38
|
+
|
|
39
|
+
// 3. Methods
|
|
40
|
+
fun doSomething() { }
|
|
41
|
+
|
|
42
|
+
// 4. Companion object
|
|
43
|
+
companion object {
|
|
44
|
+
const val TAG = "MyClass"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Naming Conventions
|
|
50
|
+
|
|
51
|
+
| Element | Style | Example |
|
|
52
|
+
|---------|-------|---------|
|
|
53
|
+
| Packages | lowercase | `org.example.project` |
|
|
54
|
+
| Classes | UpperCamelCase | `DeclarationProcessor` |
|
|
55
|
+
| Functions | lowerCamelCase | `processDeclarations()` |
|
|
56
|
+
| Properties | lowerCamelCase | `declarationCount` |
|
|
57
|
+
| Constants | UPPER_SNAKE_CASE | `MAX_COUNT` |
|
|
58
|
+
| Backing properties | underscore prefix | `_elementList` |
|
|
59
|
+
|
|
60
|
+
### Acronyms
|
|
61
|
+
|
|
62
|
+
- 2 letters: both uppercase (`IOStream`)
|
|
63
|
+
- 3+ letters: capitalize first only (`XmlFormatter`)
|
|
64
|
+
|
|
65
|
+
## Formatting
|
|
66
|
+
|
|
67
|
+
### Indentation
|
|
68
|
+
|
|
69
|
+
```kotlin
|
|
70
|
+
if (elements != null) {
|
|
71
|
+
for (element in elements) {
|
|
72
|
+
// 4 spaces indentation
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Horizontal Whitespace
|
|
78
|
+
|
|
79
|
+
```kotlin
|
|
80
|
+
// Binary operators with spaces
|
|
81
|
+
val sum = a + b
|
|
82
|
+
|
|
83
|
+
// No space around range
|
|
84
|
+
for (i in 0..n) { }
|
|
85
|
+
|
|
86
|
+
// No space around dot
|
|
87
|
+
foo.bar().filter { it > 2 }
|
|
88
|
+
|
|
89
|
+
// Space after control keywords
|
|
90
|
+
if (condition) { }
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Colons
|
|
94
|
+
|
|
95
|
+
```kotlin
|
|
96
|
+
// Type and supertype: space before
|
|
97
|
+
abstract class Foo<out T : Any> : IFoo {
|
|
98
|
+
// Declaration and type: no space before
|
|
99
|
+
abstract fun foo(a: Int): T
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Function Signatures
|
|
104
|
+
|
|
105
|
+
```kotlin
|
|
106
|
+
// Short: single line
|
|
107
|
+
fun foo(a: Int): String = a.toString()
|
|
108
|
+
|
|
109
|
+
// Long: break parameters
|
|
110
|
+
fun longMethodName(
|
|
111
|
+
argument: ArgumentType = defaultValue,
|
|
112
|
+
argument2: AnotherArgumentType,
|
|
113
|
+
): ReturnType {
|
|
114
|
+
// body
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Trailing Commas
|
|
119
|
+
|
|
120
|
+
```kotlin
|
|
121
|
+
class Person(
|
|
122
|
+
val firstName: String,
|
|
123
|
+
val lastName: String,
|
|
124
|
+
val age: Int, // trailing comma
|
|
125
|
+
)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Idiomatic Patterns
|
|
129
|
+
|
|
130
|
+
### Immutability
|
|
131
|
+
|
|
132
|
+
```kotlin
|
|
133
|
+
// Prefer val
|
|
134
|
+
val name = "Kotlin"
|
|
135
|
+
|
|
136
|
+
// Prefer immutable collections
|
|
137
|
+
val items = listOf(1, 2, 3)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Default Parameters
|
|
141
|
+
|
|
142
|
+
```kotlin
|
|
143
|
+
// Prefer over overloads
|
|
144
|
+
fun read(
|
|
145
|
+
b: ByteArray,
|
|
146
|
+
off: Int = 0,
|
|
147
|
+
len: Int = b.size,
|
|
148
|
+
) { }
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Expression Bodies
|
|
152
|
+
|
|
153
|
+
```kotlin
|
|
154
|
+
// Prefer for simple functions
|
|
155
|
+
fun square(x: Int) = x * x
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Conditionals
|
|
159
|
+
|
|
160
|
+
```kotlin
|
|
161
|
+
// Use if for binary
|
|
162
|
+
return if (x) foo() else bar()
|
|
163
|
+
|
|
164
|
+
// Use when for multiple
|
|
165
|
+
return when (x) {
|
|
166
|
+
0 -> "zero"
|
|
167
|
+
1 -> "one"
|
|
168
|
+
else -> "many"
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Functional Operations
|
|
173
|
+
|
|
174
|
+
```kotlin
|
|
175
|
+
// Prefer
|
|
176
|
+
list.filter { it > 10 }
|
|
177
|
+
.map { it * 2 }
|
|
178
|
+
.take(5)
|
|
179
|
+
|
|
180
|
+
// Over manual loops
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Ranges
|
|
184
|
+
|
|
185
|
+
```kotlin
|
|
186
|
+
// Good: open-ended range
|
|
187
|
+
for (i in 0..<n) { }
|
|
188
|
+
|
|
189
|
+
// Avoid
|
|
190
|
+
for (i in 0..n - 1) { }
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Null Safety
|
|
194
|
+
|
|
195
|
+
```kotlin
|
|
196
|
+
// Safe call
|
|
197
|
+
val length = text?.length
|
|
198
|
+
|
|
199
|
+
// Elvis operator
|
|
200
|
+
val name = user?.name ?: "Unknown"
|
|
201
|
+
|
|
202
|
+
// Let for non-null
|
|
203
|
+
user?.let {
|
|
204
|
+
println("Hello, ${it.name}")
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Not-null assertion (use sparingly)
|
|
208
|
+
val name = user!!.name
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Documentation
|
|
212
|
+
|
|
213
|
+
```kotlin
|
|
214
|
+
/**
|
|
215
|
+
* Returns the absolute value of the given [number].
|
|
216
|
+
*/
|
|
217
|
+
fun abs(number: Int): Int = if (number < 0) -number else number
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* A group of *members*.
|
|
221
|
+
*
|
|
222
|
+
* This class has no useful logic; it's just a documentation example.
|
|
223
|
+
*
|
|
224
|
+
* @property name the name of this group.
|
|
225
|
+
* @constructor Creates an empty group.
|
|
226
|
+
*/
|
|
227
|
+
class Group(val name: String) {
|
|
228
|
+
/**
|
|
229
|
+
* Adds a [member] to this group.
|
|
230
|
+
* @return the new size of the group.
|
|
231
|
+
*/
|
|
232
|
+
fun add(member: Member): Int { ... }
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Avoid Redundant Constructs
|
|
237
|
+
|
|
238
|
+
```kotlin
|
|
239
|
+
// Avoid explicit Unit return
|
|
240
|
+
fun foo() { } // not: fun foo(): Unit { }
|
|
241
|
+
|
|
242
|
+
// Avoid semicolons
|
|
243
|
+
val x = 1 // not: val x = 1;
|
|
244
|
+
|
|
245
|
+
// Use simple string templates
|
|
246
|
+
"$name" // not: "${name}"
|
|
247
|
+
```
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# Kotlin Idioms
|
|
2
|
+
|
|
3
|
+
> Source: https://kotlinlang.org/docs/idioms.html
|
|
4
|
+
|
|
5
|
+
## Data Classes
|
|
6
|
+
|
|
7
|
+
```kotlin
|
|
8
|
+
data class Customer(val name: String, val email: String)
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Provides:
|
|
12
|
+
- `equals()` / `hashCode()`
|
|
13
|
+
- `toString()`: `"Customer(name=John, email=john@example.com)"`
|
|
14
|
+
- `copy()` function
|
|
15
|
+
- `componentN()` functions
|
|
16
|
+
|
|
17
|
+
## Default Parameter Values
|
|
18
|
+
|
|
19
|
+
```kotlin
|
|
20
|
+
fun foo(a: Int = 0, b: String = "") { }
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Filtering Collections
|
|
24
|
+
|
|
25
|
+
```kotlin
|
|
26
|
+
val positives = list.filter { it > 0 }
|
|
27
|
+
|
|
28
|
+
// or with explicit type
|
|
29
|
+
val positives = list.filter { x -> x > 0 }
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Checking Element Presence
|
|
33
|
+
|
|
34
|
+
```kotlin
|
|
35
|
+
if ("john@example.com" in emailsList) { }
|
|
36
|
+
if ("jane@example.com" !in emailsList) { }
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## String Interpolation
|
|
40
|
+
|
|
41
|
+
```kotlin
|
|
42
|
+
println("Name: $name")
|
|
43
|
+
println("Age: ${person.age}")
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Instance Checks
|
|
47
|
+
|
|
48
|
+
```kotlin
|
|
49
|
+
when (x) {
|
|
50
|
+
is Foo -> ...
|
|
51
|
+
is Bar -> ...
|
|
52
|
+
else -> ...
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Read-only Collections
|
|
57
|
+
|
|
58
|
+
```kotlin
|
|
59
|
+
val list = listOf("a", "b", "c")
|
|
60
|
+
val map = mapOf("a" to 1, "b" to 2, "c" to 3)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Accessing Maps
|
|
64
|
+
|
|
65
|
+
```kotlin
|
|
66
|
+
val map = mapOf("a" to 1)
|
|
67
|
+
println(map["a"]) // prints 1
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Traversing Maps
|
|
71
|
+
|
|
72
|
+
```kotlin
|
|
73
|
+
for ((k, v) in map) {
|
|
74
|
+
println("$k -> $v")
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Ranges
|
|
79
|
+
|
|
80
|
+
```kotlin
|
|
81
|
+
for (i in 1..100) { } // closed range: 1 to 100
|
|
82
|
+
for (i in 1..<100) { } // half-open: 1 to 99
|
|
83
|
+
for (i in 2..10 step 2) { }
|
|
84
|
+
for (i in 10 downTo 1) { }
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Lazy Property
|
|
88
|
+
|
|
89
|
+
```kotlin
|
|
90
|
+
val p: String by lazy {
|
|
91
|
+
// compute the string
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Extension Functions
|
|
96
|
+
|
|
97
|
+
```kotlin
|
|
98
|
+
fun String.spaceToCamelCase() { }
|
|
99
|
+
"Convert this to camelcase".spaceToCamelCase()
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Singleton
|
|
103
|
+
|
|
104
|
+
```kotlin
|
|
105
|
+
object Resource {
|
|
106
|
+
val name = "Name"
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Instantiate Abstract Class
|
|
111
|
+
|
|
112
|
+
```kotlin
|
|
113
|
+
abstract class MyAbstractClass {
|
|
114
|
+
abstract fun doSomething()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
val myObject = object : MyAbstractClass() {
|
|
118
|
+
override fun doSomething() { }
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## if-not-null Shorthand
|
|
123
|
+
|
|
124
|
+
```kotlin
|
|
125
|
+
// Simple
|
|
126
|
+
val length = files?.size
|
|
127
|
+
|
|
128
|
+
// With else
|
|
129
|
+
val length = files?.size ?: 0
|
|
130
|
+
|
|
131
|
+
// With let
|
|
132
|
+
files?.let {
|
|
133
|
+
println(it.size)
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Return on when
|
|
138
|
+
|
|
139
|
+
```kotlin
|
|
140
|
+
fun transform(color: String): Int {
|
|
141
|
+
return when (color) {
|
|
142
|
+
"Red" -> 0
|
|
143
|
+
"Green" -> 1
|
|
144
|
+
"Blue" -> 2
|
|
145
|
+
else -> throw IllegalArgumentException("Invalid color")
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## try-catch Expression
|
|
151
|
+
|
|
152
|
+
```kotlin
|
|
153
|
+
val result = try {
|
|
154
|
+
count()
|
|
155
|
+
} catch (e: ArithmeticException) {
|
|
156
|
+
throw IllegalStateException(e)
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## if Expression
|
|
161
|
+
|
|
162
|
+
```kotlin
|
|
163
|
+
val y = if (x == 1) {
|
|
164
|
+
"one"
|
|
165
|
+
} else if (x == 2) {
|
|
166
|
+
"two"
|
|
167
|
+
} else {
|
|
168
|
+
"other"
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Builder-style Usage
|
|
173
|
+
|
|
174
|
+
```kotlin
|
|
175
|
+
fun arrayOfMinusOnes(size: Int): IntArray {
|
|
176
|
+
return IntArray(size).apply { fill(-1) }
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Single-expression Functions
|
|
181
|
+
|
|
182
|
+
```kotlin
|
|
183
|
+
fun theAnswer() = 42
|
|
184
|
+
|
|
185
|
+
// equivalent to
|
|
186
|
+
fun theAnswer(): Int {
|
|
187
|
+
return 42
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Call Multiple Methods (with)
|
|
192
|
+
|
|
193
|
+
```kotlin
|
|
194
|
+
class Turtle {
|
|
195
|
+
fun penDown()
|
|
196
|
+
fun penUp()
|
|
197
|
+
fun turn(degrees: Double)
|
|
198
|
+
fun forward(pixels: Double)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
val myTurtle = Turtle()
|
|
202
|
+
with(myTurtle) {
|
|
203
|
+
penDown()
|
|
204
|
+
for (i in 1..4) {
|
|
205
|
+
forward(100.0)
|
|
206
|
+
turn(90.0)
|
|
207
|
+
}
|
|
208
|
+
penUp()
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Configure Object (apply)
|
|
213
|
+
|
|
214
|
+
```kotlin
|
|
215
|
+
val myRectangle = Rectangle().apply {
|
|
216
|
+
length = 4
|
|
217
|
+
breadth = 5
|
|
218
|
+
color = 0xFAFAFA
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Swap Variables
|
|
223
|
+
|
|
224
|
+
```kotlin
|
|
225
|
+
var a = 1
|
|
226
|
+
var b = 2
|
|
227
|
+
a = b.also { b = a }
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## TODO: Marking Incomplete
|
|
231
|
+
|
|
232
|
+
```kotlin
|
|
233
|
+
fun calcTaxes(): BigDecimal = TODO("Waiting for feedback from accounting")
|
|
234
|
+
```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Kotlin Guide
|
|
2
|
+
|
|
3
|
+
metadata:
|
|
4
|
+
name: kotlin
|
|
5
|
+
description: Kotlin language reference documentation
|
|
6
|
+
|
|
7
|
+
source:
|
|
8
|
+
type: external
|
|
9
|
+
origin: kotlinlang.org
|
|
10
|
+
urls:
|
|
11
|
+
- https://kotlinlang.org/docs/coding-conventions.html
|
|
12
|
+
- https://kotlinlang.org/docs/idioms.html
|
|
13
|
+
- https://developer.android.com/kotlin/style-guide
|
|
14
|
+
last_fetched: "2026-01-22"
|
|
15
|
+
|
|
16
|
+
documents:
|
|
17
|
+
- name: coding-conventions
|
|
18
|
+
path: ./coding-conventions.md
|
|
19
|
+
description: Official Kotlin coding conventions
|
|
20
|
+
|
|
21
|
+
- name: idioms
|
|
22
|
+
path: ./idioms.md
|
|
23
|
+
description: Idiomatic Kotlin patterns
|
|
24
|
+
|
|
25
|
+
used_by:
|
|
26
|
+
- kotlin-expert
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Python Guide
|
|
2
|
+
|
|
3
|
+
metadata:
|
|
4
|
+
name: python
|
|
5
|
+
description: Python language reference documentation
|
|
6
|
+
|
|
7
|
+
source:
|
|
8
|
+
type: external
|
|
9
|
+
origin: python.org
|
|
10
|
+
urls:
|
|
11
|
+
- https://peps.python.org/pep-0008/
|
|
12
|
+
- https://peps.python.org/pep-0020/
|
|
13
|
+
- https://google.github.io/styleguide/pyguide.html
|
|
14
|
+
last_fetched: "2026-01-22"
|
|
15
|
+
|
|
16
|
+
documents:
|
|
17
|
+
- name: pep8-style-guide
|
|
18
|
+
path: ./pep8-style-guide.md
|
|
19
|
+
description: PEP 8 - Official Python Style Guide
|
|
20
|
+
|
|
21
|
+
- name: zen-of-python
|
|
22
|
+
path: ./zen-of-python.md
|
|
23
|
+
description: PEP 20 - The Zen of Python
|
|
24
|
+
|
|
25
|
+
used_by:
|
|
26
|
+
- python-expert
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# PEP 8 - Style Guide for Python Code
|
|
2
|
+
|
|
3
|
+
> Source: https://peps.python.org/pep-0008/
|
|
4
|
+
|
|
5
|
+
## Introduction
|
|
6
|
+
|
|
7
|
+
This document gives coding conventions for the Python code comprising the standard library. The key insight is that code is read much more often than it is written. Prioritize readability.
|
|
8
|
+
|
|
9
|
+
## Code Layout
|
|
10
|
+
|
|
11
|
+
### Indentation
|
|
12
|
+
|
|
13
|
+
Use 4 spaces per indentation level.
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
# Aligned with opening delimiter
|
|
17
|
+
foo = long_function_name(var_one, var_two,
|
|
18
|
+
var_three, var_four)
|
|
19
|
+
|
|
20
|
+
# Hanging indent with additional level
|
|
21
|
+
def long_function_name(
|
|
22
|
+
var_one, var_two, var_three,
|
|
23
|
+
var_four):
|
|
24
|
+
print(var_one)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Maximum Line Length
|
|
28
|
+
|
|
29
|
+
- Limit all lines to 79 characters
|
|
30
|
+
- Docstrings/comments: limit to 72 characters
|
|
31
|
+
- Teams may agree on longer lines (up to 99)
|
|
32
|
+
|
|
33
|
+
### Binary Operators
|
|
34
|
+
|
|
35
|
+
Break before binary operators:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
# Correct:
|
|
39
|
+
income = (gross_wages
|
|
40
|
+
+ taxable_interest
|
|
41
|
+
+ (dividends - qualified_dividends))
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Blank Lines
|
|
45
|
+
|
|
46
|
+
- Two blank lines around top-level definitions
|
|
47
|
+
- One blank line between method definitions
|
|
48
|
+
- Extra blank lines sparingly to separate logical sections
|
|
49
|
+
|
|
50
|
+
## Imports
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
# Standard library
|
|
54
|
+
import os
|
|
55
|
+
import sys
|
|
56
|
+
|
|
57
|
+
# Third party
|
|
58
|
+
import numpy as np
|
|
59
|
+
|
|
60
|
+
# Local
|
|
61
|
+
from myproject import mymodule
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Rules:
|
|
65
|
+
- One import per line
|
|
66
|
+
- Absolute imports preferred
|
|
67
|
+
- Avoid wildcard imports
|
|
68
|
+
|
|
69
|
+
## Whitespace
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
# Correct:
|
|
73
|
+
spam(ham[1], {eggs: 2})
|
|
74
|
+
x = 1
|
|
75
|
+
y = 2
|
|
76
|
+
long_variable = 3
|
|
77
|
+
|
|
78
|
+
# Wrong:
|
|
79
|
+
spam( ham[ 1 ], { eggs: 2 } )
|
|
80
|
+
x = 1
|
|
81
|
+
y = 2
|
|
82
|
+
long_variable = 3
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Comments
|
|
86
|
+
|
|
87
|
+
### Block Comments
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
# This is a block comment that
|
|
91
|
+
# spans multiple lines and describes
|
|
92
|
+
# the following code block.
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Inline Comments
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
x = x + 1 # Increment x
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Docstrings
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
def complex(real=0.0, imag=0.0):
|
|
105
|
+
"""Form a complex number.
|
|
106
|
+
|
|
107
|
+
Keyword arguments:
|
|
108
|
+
real -- the real part (default 0.0)
|
|
109
|
+
imag -- the imaginary part (default 0.0)
|
|
110
|
+
"""
|
|
111
|
+
pass
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Naming Conventions
|
|
115
|
+
|
|
116
|
+
| Type | Convention | Example |
|
|
117
|
+
|------|------------|---------|
|
|
118
|
+
| Module | lowercase_underscore | `my_module` |
|
|
119
|
+
| Package | lowercase | `mypackage` |
|
|
120
|
+
| Class | CapWords | `MyClass` |
|
|
121
|
+
| Exception | CapWords + Error | `CustomError` |
|
|
122
|
+
| Function | lowercase_underscore | `my_function` |
|
|
123
|
+
| Variable | lowercase_underscore | `my_var` |
|
|
124
|
+
| Constant | UPPER_UNDERSCORE | `MAX_SIZE` |
|
|
125
|
+
| Method | lowercase_underscore | `my_method` |
|
|
126
|
+
|
|
127
|
+
### Special Naming
|
|
128
|
+
|
|
129
|
+
- `_single_leading`: weak "internal use" indicator
|
|
130
|
+
- `__double_leading`: name mangling in classes
|
|
131
|
+
- `__double_both__`: "magic" methods
|
|
132
|
+
|
|
133
|
+
## Programming Recommendations
|
|
134
|
+
|
|
135
|
+
### Comparisons
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
# Correct:
|
|
139
|
+
if foo is not None:
|
|
140
|
+
if isinstance(obj, int):
|
|
141
|
+
|
|
142
|
+
# Wrong:
|
|
143
|
+
if foo != None:
|
|
144
|
+
if type(obj) is int:
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Sequences
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
# Correct:
|
|
151
|
+
if not seq:
|
|
152
|
+
if seq:
|
|
153
|
+
|
|
154
|
+
# Wrong:
|
|
155
|
+
if len(seq) == 0:
|
|
156
|
+
if len(seq) > 0:
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Exception Handling
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
# Correct:
|
|
163
|
+
try:
|
|
164
|
+
value = collection[key]
|
|
165
|
+
except KeyError:
|
|
166
|
+
return key_not_found(key)
|
|
167
|
+
|
|
168
|
+
# Wrong:
|
|
169
|
+
try:
|
|
170
|
+
value = collection[key]
|
|
171
|
+
except: # Bare except
|
|
172
|
+
return key_not_found(key)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Context Managers
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
# Correct:
|
|
179
|
+
with open('file.txt') as f:
|
|
180
|
+
contents = f.read()
|
|
181
|
+
|
|
182
|
+
# Wrong:
|
|
183
|
+
f = open('file.txt')
|
|
184
|
+
contents = f.read()
|
|
185
|
+
f.close()
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Return Statements
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
# Correct:
|
|
192
|
+
def foo(x):
|
|
193
|
+
if x >= 0:
|
|
194
|
+
return math.sqrt(x)
|
|
195
|
+
else:
|
|
196
|
+
return None
|
|
197
|
+
|
|
198
|
+
# Wrong:
|
|
199
|
+
def foo(x):
|
|
200
|
+
if x >= 0:
|
|
201
|
+
return math.sqrt(x)
|
|
202
|
+
```
|