{"id":17994662,"url":"https://github.com/noties/stopship","last_synced_at":"2025-04-04T05:24:34.737Z","repository":{"id":57735921,"uuid":"382076200","full_name":"noties/StopShip","owner":"noties","description":"A convenience utility around Android's STOPSHIP functionality with build-in Lint support","archived":false,"fork":false,"pushed_at":"2021-07-01T15:31:13.000Z","size":64,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-09T16:43:04.227Z","etag":null,"topics":["android","lint","stopship"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/noties.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}},"created_at":"2021-07-01T15:22:00.000Z","updated_at":"2024-02-25T18:03:11.000Z","dependencies_parsed_at":"2022-08-24T03:01:05.515Z","dependency_job_id":null,"html_url":"https://github.com/noties/StopShip","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noties%2FStopShip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noties%2FStopShip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noties%2FStopShip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noties%2FStopShip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noties","download_url":"https://codeload.github.com/noties/StopShip/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247125139,"owners_count":20887634,"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":["android","lint","stopship"],"created_at":"2024-10-29T20:15:59.648Z","updated_at":"2025-04-04T05:24:34.715Z","avatar_url":"https://github.com/noties.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StopShip\n\nA convenience utility around Android's `STOPSHIP` functionality with build-in Lint support. \nKotlin and Java supported.\n\n```groovy\nimplementation 'io.noties:stopship:1.0.0'\n```\n\nSome code might be added for runtime debugging or testing purposes. And it must not be shipped.\nImagine mocked credentials, altered behaviour or fake data. These must be removed from the application\nbefore a release.\n \nAndroid Studio comes with a `STOPSHIP` comment and associated Lint rule that would stop build\nif such comment is present. For this to work `STOPSHIP` comment Lint rule must be marked as fatal:\n\n```groovy\n// build.gradle\nandroid {\n  lintOptions {\n    fatal 'StopShip'\n  }\n}\n```\n\nIt is also crucial to create isolated code blocks that are easy to remove. And the removal \nmust not break or alter expected behaviour. This can be done with a truthy `if` condition:\n\n```java\n// STOPSHIP: 01.07.2021 \nif (true) {\n  // the altering code\n  doSomethingBad();\n\n  // It is common to insert an altering behaviour\n  //   before an actual implementation. So STOPSHIP code\n  //   might return, so real code is not executed\n  return\n}\n\ndoSomethingReal();\n```\n\nThis works well until the condition must be set to `false`, in order to temporarily \ndisable the code block. `STOPSHIP` comment is still present, which breaks the build even though\nthe code is not executed. So, the `STOPSHIP` comment is removed. And next time the code is going to\nbe run (by using `true` in the if condition) the `STOPSHIP` comment must be added again. \nThis might be a tedious process with a room for an error. Which can result in a bad _shipping_.\n\n## Kotlin\n\nUsage in Kotlin project:\n\n```kotlin\nimport io.noties.stopship.stopShip\n\nfun someMethod() {\n\n  stopShip {\n    doWhatYouHaveToDo()\n    return  \n  }\n\n  // original method\n}\n```\n\nIn order to disable the StopShip lint rule, just add an underscore before `stopShip` =\u0026gt; `_stopShip`:\n\n```kotlin\nimport io.noties.stopship._stopShip\n\nfun someMethod() {\n\n  _stopShip {\n    // won't be run and Lint won't report the usage\n    doWhatYouHaveToDo()\n    return  \n  }\n\n  // original method\n}\n```\n\n## Java\n\nIn Java there is no way to create a code block with a return functionality as in Kotlin. So\nthe usage is a bit different (if an early return is required):\n\n```java\n// NB! the static import\nimport static io.noties.stopship.StopShip.stopShip;\n\nvoid someMethod() {\n  \n  if (stopShip(() -\u003e {\n    doWhatYouHaveToDo();\n  })) return;\n  \n  // original mettod\n}\n```\n\nDisabling code block is done similarly with an underscore:\n\n```java\nimport static io.noties.stopship.StopShip._stopShip;\n\nvoid someMethod() {\n  \n  if (_stopShip(() -\u003e {\n    // won't be run and Lint won't report the usage\n    doWhatYouHaveToDo();\n  })) return;\n  \n  // original mettod\n}\n```\n\nIf there is no need for an early return, then code can be simplified to:\n\n```java\nstopShip(() -\u003e {\n  doWhatYouHaveToDo();\n});\n```\n\n## Proguard / R8\n\nThe underscored variants can be safely removed with these rules:\n\n```proguard\n-assumenosideeffects class io.noties.stopship.StopShip {\n    public static *** _stopShip(...);\n}\n\n-assumenosideeffects class io.noties.stopship.StopShipKt {\n    public static *** _stopShip(...);\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoties%2Fstopship","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoties%2Fstopship","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoties%2Fstopship/lists"}