{"id":41767706,"url":"https://github.com/orangain/ktcodeshift","last_synced_at":"2026-01-25T02:37:09.255Z","repository":{"id":36978210,"uuid":"492115848","full_name":"orangain/ktcodeshift","owner":"orangain","description":"Toolkit for running codemods over multiple Kotlin files inspired by jscodeshift.","archived":false,"fork":false,"pushed_at":"2025-07-20T05:51:54.000Z","size":1917,"stargazers_count":15,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-20T07:31:21.446Z","etag":null,"topics":["ast","codemods","kotlin"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/orangain.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-05-14T04:55:18.000Z","updated_at":"2025-07-20T05:50:34.000Z","dependencies_parsed_at":"2025-03-30T13:22:00.425Z","dependency_job_id":"fd52fc06-a3bb-4ebd-825e-595226193fcb","html_url":"https://github.com/orangain/ktcodeshift","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/orangain/ktcodeshift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orangain%2Fktcodeshift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orangain%2Fktcodeshift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orangain%2Fktcodeshift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orangain%2Fktcodeshift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orangain","download_url":"https://codeload.github.com/orangain/ktcodeshift/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orangain%2Fktcodeshift/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28742548,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T01:40:51.112Z","status":"online","status_checked_at":"2026-01-25T02:00:06.841Z","response_time":113,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["ast","codemods","kotlin"],"created_at":"2026-01-25T02:37:09.178Z","updated_at":"2026-01-25T02:37:09.245Z","avatar_url":"https://github.com/orangain.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ktcodeshift [![Java CI](https://github.com/orangain/ktcodeshift/actions/workflows/java_ci.yaml/badge.svg)](https://github.com/orangain/ktcodeshift/actions/workflows/java_ci.yaml)\n\nktcodeshift is a toolkit for running codemods over multiple Kotlin files inspired\nby [jscodeshift](https://github.com/facebook/jscodeshift). It provides:\n\n- A runner, which executes the provided transform for each file passed to it. It also outputs a summary of how many\n  files have (not) been transformed.\n- A wrapper around [ktast](https://github.com/orangain/ktast), providing a different API. ktast is a Kotlin AST library\n  and also tries to preserve the style of original code as much as possible.\n\n## Setup\n\n### Prerequisites\n\n- Java 11 or later is required.\n\n### macOS\n\n```\nbrew install orangain/tap/ktcodeshift\n```\n\n### Other platforms\n\nDownload the latest archive from [releases](https://github.com/orangain/ktcodeshift/releases) and extract\nit. `ktcodeshift` command is available in the `bin` directory.\n\n## Usage\n\n```\nUsage: ktcodeshift [-dhV] [--extensions=EXT] -t=TRANSFORM_PATH PATH...\n\nApply transform logic in TRANSFORM_PATH (recursively) to every PATH.\n\n      PATH...            Search target files in these paths.\n  -d, --dry              dry run (no changes are made to files)\n      --extensions=EXT   Target file extensions to be transformed (comma\n                           separated list)\n                         (default: kt)\n  -h, --help             Show this help message and exit.\n  -t, --transform=TRANSFORM_PATH\n                         Transform file\n  -V, --version          Print version information and exit.\n```\n\nFor example:\n\n```\nktcodeshift -t RenameVariable.transform.kts src/main/kotlin\n```\n\n## Transform file\n\nA transform file is a Kotlin script file that defines a lambda function `transform: (FileInfo) -\u003e String?`.\nThe `transform` function will be called for each file on the target paths by the ktcodeshift.\n\nThe `transform` function takes an\nargument [FileInfo](https://orangain.github.io/ktcodeshift/latest/api/ktcodeshift-dsl/ktcodeshift/-file-info/index.html)\n,\nwhich has `source: String` and `path: java.nio.file.Path` of the target file, and must return the modified source code\nor null. When the transform function return the null or the same source code as the input, the ktcodeshift does not\nmodify the target file.\n\nThe script filename should end with `.transform.kts`.\n\n```kts\ntransform { fileInfo -\u003e\n    Ktcodeshift\n        .parse(fileInfo.source)\n        .find\u003cNode.Expression.NameExpression\u003e()\n        .filter { n -\u003e\n            parent is Node.Variable \u0026\u0026 n.text == \"foo\"\n        }\n        .replaceWith { n -\u003e\n            n.copy(text = \"bar\")\n        }\n        .toSource()\n}\n```\n\nThe following API documents will be helpful to write a transform file.\n\n- [API document of ktcodeshift](https://orangain.github.io/ktcodeshift/latest/api/ktcodeshift-dsl/ktcodeshift/index.html)\n- [API document of ktast](https://orangain.github.io/ktast/latest/api/ast/ktast.ast/index.html)\n\n### Implicit imports\n\nThe following imports are implicitly available in the transform file:\n\n```kts\nimport ktast.ast.*\nimport ktast.builder.*\nimport ktcodeshift.*\n```\n\n### Annotations\n\nThe following annotations can be used in the transform file:\n\n| Annotation         | Description                                                                                                                                                                    |\n|--------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `@file:Repository` | URL of the repository where the library specified in `@file:DependsOn` is hosted.\u003cbr\u003ee.g.: `@file:Repository(\"https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven\")` |\n| `@file:DependsOn`  | Dependent library of the transform file. \u003cbr\u003ee.g.: `@file:DependsOn(\"org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.3\")`                                                           |\n| `@file:Import`     | Script file path(s) to import into the transform file. \u003cbr\u003ee.g.: `@file:Import(\"./common.transform.kts\")`                                                                      |\n\n\n## Examples\n\nExample transform files are available\nunder the [ktcodeshift-cli/src/test/resources/examples/](ktcodeshift-cli/src/test/resources/examples/) directory. The\n[\\_\\_testfixtures\\_\\_](ktcodeshift-cli/src/test/resources/examples/__testfixtures__) directory also contains pairs of\ntheir input and output.\n\n## Development Tips\n\n### Dumping AST\n\nYou can dump the AST of a Kotlin file using the [ktast.ast.Dumper](https://orangain.github.io/ktast/latest/api/ast/ktast.ast/-dumper/index.html). This is useful to understand the structure of the AST. For example:\n\n```kts\ntransform { fileInfo -\u003e\n    Ktcodeshift\n        .parse(fileInfo.source)\n        .also { println(Dumper.dump(it)) } // This line dumps the AST.\n        .toSource()\n}\n```\n\n### Builder Functions\n\nThe [ktast.builder](https://orangain.github.io/ktast/latest/api/ast/ktast.builder/index.html) package provides a number of builder functions to create AST nodes. The function name corresponds to the class name of the AST node, i.e. `Node.Expression.NameExpression` is created by `nameExpression()` function. Unlike the parameters of the constructor of the AST node class, many of the parameters of the builder functions are optional and have sensible default values.\n\n## Internal\n\n### How to release\n\n1. Create and push a tag with the version, e.g. `git tag 0.1.0 \u0026\u0026 git push --tags`.\n2. CI will publish a release note to GitHub and update the Homebrew formula in the [orangain/homebrew-tap](https://github.com/orangain/homebrew-tap) repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forangain%2Fktcodeshift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forangain%2Fktcodeshift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forangain%2Fktcodeshift/lists"}