codeshift 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/gem-push.yml +45 -0
- data/Gemfile +2 -0
- data/README.md +17 -10
- data/codeshift.gemspec +1 -1
- data/lib/codeshift/cli.rb +2 -2
- data/lib/codeshift/transformer.rb +1 -2
- data/lib/codeshift/version.rb +3 -1
- data/lib/codeshift.rb +5 -3
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09160e4f1daa03101fdcf2d1d6cd43ba664bac73d96d8de24885b6a695a1d869'
|
4
|
+
data.tar.gz: 6582cb9a1b60bb904e30ced7a55d7fbef9d1c5f44d5254410417c49dee176718
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36b88bcaa1f32e8b120d7f1d2ede3f947c33d51d8dfabb40776ff02cda7f8e1e01a810e58f3e0a89cb76982cb9626f602417d60544e688988c2e835d54397db8
|
7
|
+
data.tar.gz: 4f9af39477612d3138840307d7a4bc8f8b04dc0c73083e2709b56bd9d34dc81a795d4c118d7ecd74dd5cb0c0540a9b718af71083bf15b62b3e77124500427a7d
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
3
|
+
# Please see the documentation for all configuration options:
|
4
|
+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
5
|
+
|
6
|
+
version: 2
|
7
|
+
updates:
|
8
|
+
- package-ecosystem: "bundler" # See documentation for possible values
|
9
|
+
directory: "/" # Location of package manifests
|
10
|
+
schedule:
|
11
|
+
interval: "weekly"
|
@@ -0,0 +1,45 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
name: Build + Publish
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
permissions:
|
14
|
+
contents: read
|
15
|
+
packages: write
|
16
|
+
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v3
|
19
|
+
- name: Set up Ruby 2.6
|
20
|
+
uses: ruby/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: '2.6'
|
23
|
+
|
24
|
+
- name: Publish to GPR
|
25
|
+
run: |
|
26
|
+
mkdir -p $HOME/.gem
|
27
|
+
touch $HOME/.gem/credentials
|
28
|
+
chmod 0600 $HOME/.gem/credentials
|
29
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
30
|
+
gem build *.gemspec
|
31
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
32
|
+
env:
|
33
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
34
|
+
OWNER: ${{ github.repository_owner }}
|
35
|
+
|
36
|
+
- name: Publish to RubyGems
|
37
|
+
run: |
|
38
|
+
mkdir -p $HOME/.gem
|
39
|
+
touch $HOME/.gem/credentials
|
40
|
+
chmod 0600 $HOME/.gem/credentials
|
41
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
42
|
+
gem build *.gemspec
|
43
|
+
gem push *.gem
|
44
|
+
env:
|
45
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# Codeshift
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/codeshift.svg)](https://badge.fury.io/rb/codeshift)
|
4
|
+
[![Build Status](https://travis-ci.org/rajasegar/codeshift.svg?branch=master)](https://travis-ci.org/rajasegar/codeshift)
|
5
|
+
![](https://ruby-gem-downloads-badge.herokuapp.com/codeshift?type=total&style=plastic&color=brightgreen&total_label=)
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/github/rajasegar/codeshift/badge.svg?branch=master)](https://coveralls.io/github/rajasegar/codeshift?branch=master)
|
4
7
|
|
5
8
|
A Ruby codemod CLI to transform your source code using AST(Abstract Syntax Trees) and the [parser](https://github.com/whitequark/parser) gem.
|
6
|
-
It is typically used on
|
9
|
+
It is typically used on Ruby codebase like RAILS applications and other stuff.
|
7
10
|
|
8
11
|
## Installation
|
9
12
|
|
@@ -29,9 +32,9 @@ $ codeshift -t transform.rb app/models
|
|
29
32
|
For example if you want to reverse the local variable names and method names in your code
|
30
33
|
you will be doing something like this:
|
31
34
|
|
32
|
-
Create a new
|
33
|
-
AST of the source code. For writing transforms you can make use of
|
34
|
-
[Ruby AST Explorer](https://ruby-ast-explorer.herokuapp.com/)
|
35
|
+
Create a new Ruby file with the tranformation logic to be applied on the
|
36
|
+
AST of the source code. For writing transforms you can make use of
|
37
|
+
[Ruby AST Explorer](https://ruby-ast-explorer.herokuapp.com/) and [cybertron](https://github.com/rajasegar/cybertron)
|
35
38
|
|
36
39
|
### transform.rb
|
37
40
|
```ruby
|
@@ -40,11 +43,11 @@ AST of the source code. For writing transforms you can make use of the
|
|
40
43
|
class Transform < Parser::TreeRewriter
|
41
44
|
def on_lvasgn(node)
|
42
45
|
# Reverse the variable names
|
43
|
-
replace(node.loc.
|
46
|
+
replace(node.loc.name, node.children[0].to_s.reverse)
|
44
47
|
end
|
45
48
|
|
46
49
|
def on_def(node)
|
47
|
-
replace(node.loc.
|
50
|
+
replace(node.loc.name, node.children[0].to_s.reverse)
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
@@ -60,7 +63,7 @@ def print_tips
|
|
60
63
|
end
|
61
64
|
```
|
62
65
|
|
63
|
-
Then use
|
66
|
+
Then use the transform against your source code
|
64
67
|
|
65
68
|
```sh
|
66
69
|
$ codeshift -t transform.rb ~/Desktop/test/ruby
|
@@ -84,8 +87,8 @@ Usage: codeshift -t <transform-file> [path]
|
|
84
87
|
(default: ./transform.rb)
|
85
88
|
* -h, --help Prints this help
|
86
89
|
|
87
|
-
###
|
88
|
-
The transform file could be a local file or a remote url. For example you can use like
|
90
|
+
### transform-file
|
91
|
+
The transform file could be a local file or a remote url. For example you can use a remote transform like below:
|
89
92
|
|
90
93
|
```sh
|
91
94
|
$ codeshift -t https://gist.githubusercontent.com/[user]/.../transform.rb ~/Desktop/test/ruby
|
@@ -102,6 +105,10 @@ $ codeshift -t transform.rb ~/app/legacy/ruby ~/app/old
|
|
102
105
|
$ codeshift -t transform.rb ~/code/legacy/app/models/account.rb ~/old/app/models/customer.rb
|
103
106
|
```
|
104
107
|
|
108
|
+
## Related tools
|
109
|
+
- [ruby-ast-explorer](https://github.com/rajasegar/ruby-ast-explorer)
|
110
|
+
- [cybertron](https://github.com/rajasegar/cybertron)
|
111
|
+
|
105
112
|
## Development
|
106
113
|
|
107
114
|
After 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.
|
@@ -118,4 +125,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
118
125
|
|
119
126
|
## Code of Conduct
|
120
127
|
|
121
|
-
Everyone 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/
|
128
|
+
Everyone 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).
|
data/codeshift.gemspec
CHANGED
@@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_runtime_dependency 'parser', '~> 2.6'
|
30
30
|
|
31
31
|
spec.add_development_dependency "bundler", "~> 2.0"
|
32
|
-
spec.add_development_dependency "rake", "~>
|
32
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
33
33
|
spec.add_development_dependency "rspec", "~> 3.0"
|
34
34
|
end
|
data/lib/codeshift/cli.rb
CHANGED
@@ -23,7 +23,7 @@ module CodeShift
|
|
23
23
|
@options.transform = f
|
24
24
|
end
|
25
25
|
|
26
|
-
opts.on(
|
26
|
+
opts.on('-h', '--help', 'Prints this help') do
|
27
27
|
puts opts
|
28
28
|
exit
|
29
29
|
end
|
@@ -46,7 +46,7 @@ module CodeShift
|
|
46
46
|
paths = @files.empty? ? [] : @files
|
47
47
|
paths.each do |path|
|
48
48
|
if File.directory?(path)
|
49
|
-
glob_path = File.join(path,'**','*.rb')
|
49
|
+
glob_path = File.join(path, '**', '*.rb')
|
50
50
|
Dir.glob(glob_path) do |file_path|
|
51
51
|
process_file file_path
|
52
52
|
end
|
data/lib/codeshift/version.rb
CHANGED
data/lib/codeshift.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codeshift
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rajasegar Chandran
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,6 +75,8 @@ executables:
|
|
75
75
|
extensions: []
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
|
+
- ".github/dependabot.yml"
|
79
|
+
- ".github/workflows/gem-push.yml"
|
78
80
|
- ".gitignore"
|
79
81
|
- ".rspec"
|
80
82
|
- ".travis.yml"
|
@@ -113,8 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
115
|
- !ruby/object:Gem::Version
|
114
116
|
version: '0'
|
115
117
|
requirements: []
|
116
|
-
|
117
|
-
rubygems_version: 2.7.6.2
|
118
|
+
rubygems_version: 3.0.3.1
|
118
119
|
signing_key:
|
119
120
|
specification_version: 4
|
120
121
|
summary: A tool to run Ruby codemods.
|