{"id":13533074,"url":"https://github.com/rajasegar/codeshift","last_synced_at":"2025-08-21T13:32:47.211Z","repository":{"id":35078224,"uuid":"204283460","full_name":"rajasegar/codeshift","owner":"rajasegar","description":"A Ruby CLI to transform source code using ASTs - A Ruby Codemod","archived":false,"fork":false,"pushed_at":"2023-02-28T10:15:56.000Z","size":42,"stargazers_count":47,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-10T10:12:02.120Z","etag":null,"topics":["codemod","codemods","gem","ruby-gem"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/rajasegar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-08-25T11:12:25.000Z","updated_at":"2024-10-20T13:00:14.000Z","dependencies_parsed_at":"2024-01-13T20:56:19.463Z","dependency_job_id":"3c82b7c7-2cfc-40ee-80bd-17d3bf8a237b","html_url":"https://github.com/rajasegar/codeshift","commit_stats":{"total_commits":37,"total_committers":5,"mean_commits":7.4,"dds":"0.10810810810810811","last_synced_commit":"74aacd94fe54010451c827e82e3a4821ae7dd385"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fcodeshift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fcodeshift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fcodeshift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fcodeshift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rajasegar","download_url":"https://codeload.github.com/rajasegar/codeshift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230516183,"owners_count":18238352,"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":["codemod","codemods","gem","ruby-gem"],"created_at":"2024-08-01T07:01:16.359Z","updated_at":"2024-12-20T00:08:36.091Z","avatar_url":"https://github.com/rajasegar.png","language":"Ruby","readme":"# Codeshift\n\n[![Gem Version](https://badge.fury.io/rb/codeshift.svg)](https://badge.fury.io/rb/codeshift)\n[![Build Status](https://travis-ci.org/rajasegar/codeshift.svg?branch=master)](https://travis-ci.org/rajasegar/codeshift) \n![](https://ruby-gem-downloads-badge.herokuapp.com/codeshift?type=total\u0026style=plastic\u0026color=brightgreen\u0026total_label=)\n[![Coverage Status](https://coveralls.io/repos/github/rajasegar/codeshift/badge.svg?branch=master)](https://coveralls.io/github/rajasegar/codeshift?branch=master)\n\nA Ruby codemod CLI to transform your source code using AST(Abstract Syntax Trees) and the [parser](https://github.com/whitequark/parser) gem. \nIt is typically used on Ruby codebase like RAILS applications and other stuff.\n\n## Installation\n\n```sh\n$ gem install codeshift\n```\n\n\n## Usage\nThis tool requires a `transform.rb` file which contains the transform logic to be \napplied on the source files in a folder.\n\n```sh\n$ codeshift -t [TRANSFORM FILE] [PATHS]\n```\n\nTo apply the transform logic on your `app/models` files\n\n```sh\n$ codeshift -t transform.rb app/models\n```\n\nFor example if you want to reverse the local variable names and method names in your code\nyou will be doing something like this:\n\nCreate a new Ruby file with the tranformation logic to be applied on the\nAST of the source code. For writing transforms you can make use of \n[Ruby AST Explorer](https://ruby-ast-explorer.herokuapp.com/) and [cybertron](https://github.com/rajasegar/cybertron)\n\n### transform.rb\n```ruby\n# Your Transform Class should always extend from \n# Parser:: TreeRewriter\nclass Transform \u003c Parser::TreeRewriter\n  def on_lvasgn(node)\n    # Reverse the variable names\n    replace(node.loc.name, node.children[0].to_s.reverse)\n  end\n\n  def on_def(node)\n    replace(node.loc.name, node.children[0].to_s.reverse)\n  end\nend\n\n```\n\nIf your source code looks like below in a folder called `~/Desktop/test/ruby`\n\n### sample.rb\n```ruby\ntips = [\"hello\", \"world\"]\ndef print_tips\n  tips.each { |key, value| print \"Tip #{key}: #{value}\" }\nend\n```\n\nThen use the transform against your source code\n\n```sh\n$ codeshift -t transform.rb ~/Desktop/test/ruby\n```\n\nThen your source will be transformed something like:\n\n### sample.rb\n```ruby\nspit = [\"hello\", \"world\"]\ndef spit_tnirp\n  tips.each { |key, value| print \"Tip #{key}: #{value}\" }\nend\n\n```\n\n## Options\nUsage: codeshift -t \u003ctransform-file\u003e [path]\n* --version                    Print version number\n* -t, --transform=TRANSFORM        path to the transform file. Can be either a local path or url\n             (default: ./transform.rb)\n* -h, --help                       Prints this help\n\n### transform-file\nThe transform file could be a local file or a remote url. For example you can use a remote transform like below:\n\n```sh\n$ codeshift -t https://gist.githubusercontent.com/[user]/.../transform.rb ~/Desktop/test/ruby\n```\n\n### path\nThe path could be a list of directories or files separated by space.\n\n```sh\n$ codeshift -t transform.rb ~/app/legacy/ruby ~/app/old\n```\n\n```sh\n$ codeshift -t transform.rb ~/code/legacy/app/models/account.rb ~/old/app/models/customer.rb\n```\n\n## Related tools\n- [ruby-ast-explorer](https://github.com/rajasegar/ruby-ast-explorer)\n- [cybertron](https://github.com/rajasegar/cybertron)\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/rajasegar/codeshift. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Codeshift project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rajasegar/codeshift/blob/master/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":["Ruby","By Environment","Tools"],"sub_categories":["Ruby"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frajasegar%2Fcodeshift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frajasegar%2Fcodeshift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frajasegar%2Fcodeshift/lists"}