{"id":13513235,"url":"https://github.com/ubie-oss/kotlin-coding-style","last_synced_at":"2026-04-09T01:33:01.677Z","repository":{"id":113939921,"uuid":"154499650","full_name":"ubie-oss/kotlin-coding-style","owner":"ubie-oss","description":"Kotlin coding style @ Ubie, Inc","archived":false,"fork":false,"pushed_at":"2018-10-25T06:49:59.000Z","size":8,"stargazers_count":64,"open_issues_count":2,"forks_count":3,"subscribers_count":19,"default_branch":"master","last_synced_at":"2024-05-21T10:19:18.965Z","etag":null,"topics":["codestyle","kotlin"],"latest_commit_sha":null,"homepage":"https://www.company.dr-ubie.com/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ubie-oss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-10-24T12:45:03.000Z","updated_at":"2022-02-22T06:47:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"80691dab-f962-4cf4-bcc8-7e37cb57f0b3","html_url":"https://github.com/ubie-oss/kotlin-coding-style","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ubie-oss%2Fkotlin-coding-style","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ubie-oss%2Fkotlin-coding-style/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ubie-oss%2Fkotlin-coding-style/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ubie-oss%2Fkotlin-coding-style/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ubie-oss","download_url":"https://codeload.github.com/ubie-oss/kotlin-coding-style/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246403961,"owners_count":20771526,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codestyle","kotlin"],"created_at":"2024-08-01T04:00:47.761Z","updated_at":"2026-04-09T01:33:01.625Z","avatar_url":"https://github.com/ubie-oss.png","language":null,"funding_links":[],"categories":["Android development"],"sub_categories":[],"readme":"# Kotlinコーディングスタイル\n\nあくまでガイドラインです。\nあなたは状況に応じて原則を破ることができますが、その判断は慎重に、そしてコメント等でその判断に至った背景や理由を語ってください。\n\nスタイルは[ktlint](https://github.com/shyiko/ktlint)に従ってください。\nただし、人間がいくつか気をつけることがあります。\n\n## シンプルに保つ\n\n重要な原則です。\n難しいことはしないで、常にシンプルになるよう心がけてください。\n\n例えば、ネストした制御構文は人類には難しすぎるコードです。\n副作用の扱いも慎重に。\n\npublicな拡張関数の導入には注意が必要です。\n\n## テストコードは極めて素直に\n\nテストコードでは、DRYにすることに躍起にならないでください。\n同じコードを繰り返してもかまいません。\n素直に、愚直に、単純に。まして何かを抽象化するメリットはほぼないでしょう。\n\n* 処理の塊を見つけてもメソッド化する必要はないかもしれません\n* リテラルに名前を付ける必要はないかもしれません。何度も同じリテラルを記述しましょう\n\n## 型を明記する\n\n型を明記してください。\nただし、次の場合は例外です。\n\n* ローカル変数の型\n* テストコード\n* Single-expression functionでなく戻り値の型が`Unit`の関数\n\n## Single-expression function\n\nSingle-expression functionは、そのシグネチャから式の開始までを同じ行に書く必要があります。\n`=`や式の開始が、シグネチャの次の行から始まる場合はSingle-expression functionの使用を諦めてください。\n\n```kotlin\n// OK\nfun printHelloWorld(): Unit = println(\"Hello, world!\")\n\n// OK\nfun newPerson(\n    name: String,\n    age: Int\n): Person = Person(\n    name,\n    age\n)\n\n// NG\nfun findUserByName(name: String): User? =\n    userRepository.findUserByName(name)\n\n// OK\nfun findUserByName(name: String): User? {\n    return userRepository.findUserByName(name)\n}\n```\n\n## NotNull変換\n\n`!!`は使わずに`requireNotNull`を使用してください。\n\n## lateinitは使用しない\n\nフレームワークの都合上やむを得ない場合を除き、`lateinit`は使用しないでください。\n\n## ブレースは省略しない\n\n制御構文においてブレース（`{}`）は省略しないでください。\nただし、下記の場合を除きます。\n\n* `return`, `break`, `continue`, `throw`のみを本体に含む場合\n* else-if\n\n```kotlin\n// OK\nif ( ... ) {\n} else if ( ... ) {\n}\n\n// also OK\nif ( ... ) {\n} else {\n    if ( ... ) {\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fubie-oss%2Fkotlin-coding-style","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fubie-oss%2Fkotlin-coding-style","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fubie-oss%2Fkotlin-coding-style/lists"}