Code Monkey home page Code Monkey logo

synvert-ruby's People

Contributors

airhorns avatar ashchan avatar ferdinandrosario avatar flyerhzm avatar olleolleolle avatar uu59 avatar victorsolis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

synvert-ruby's Issues

unary splat operator is not handled properly

I have seen this with the rails/strong_parameters snippet, but I think the problem is more general.

Basically, given a source like

attr_accessible *args

doing

eval arguments.first.to_source # "*args"

is never going to do the right thing, because eval("*args")is invalid.
This can't be handled easily because the splat operator needs to bubble up the chain of calls, but replacing eval with an appropriate synvert_eval may allow the tool to work while notifying the users, i.e.

def synvert_eval token, expr, file, line 
   if token[0] == ?*
      log "synvert could not handle #{expr} at #{file}:#{line}, look for SYNVERT_FIXME to handle this"
      "SYNVERT_FIXME('#{token}',#{file},#{line})"
   else
      eval(token)
   end
end

ActiveSupport 2.3.15 undefined method 'mattr_accessor'

I just install synvert gem but it seems it's not working with rails 2.3.15
I would like to use the gem to upgrade to rails 3 then rails 4.

I get these errors :

When I use synvert -l

/Users/men/.rvm/gems/ruby-1.8.7-p358@rails2315b/gems/activesupport-2.3.18/lib/active_support/deprecation.rb:5: undefined method `mattr_accessor' for ActiveSupport::Deprecation:Module (NoMethodError)

When I launch my app

/Users/men/.rvm/gems/ruby-1.8.7-p358@rails2315b/gems/activesupport-2.3.15/lib/active_support/dependencies.rb:182:in `require': /Users/men/.rvm/gems/ruby-1.8.7-p358@rails2315b/gems/synvert-core-0.9.0/lib/synvert/core/node_ext.rb:337: invalid regular expression; there's no previous pattern, to which '{' would define cardinality at 1: /{{(.*?)}}/ (SyntaxError)

add helper method

allow developers define their own helper methods in their own Synvert::Rewriter, the helper methods should be accessed in the rewriter where they are defined, but not accessed in the other rewriters.

Undefined Method 'path'

Ran into an error:

>>> 9:08:13 user3@myworkstation ~ ➜ alias sv='/System/Volumes/Data/Users/user3/.rbenv/versions/3.1.2/bin/synvert-ruby'
>>> 9:08:27 user3@myworkstation ~ ➜ sv -h
Usage: synvert-ruby [project_path]
    -l, --list                       list all available snippets
    -q, --query QUERY                query specified snippets
    -s, --show SNIPPET_NAME          show specified snippet description, SNIPPET_NAME is combined by group and name, e.g. ruby/new_hash_syntax
    -o, --open SNIPPET_NAME          Open a snippet
    -g, --generate NEW_SNIPPET_NAME  generate a new snippet
        --sync                       sync snippets
        --execute                    execute snippet
    -r, --run SNIPPET_NAME           run specified snippet, e.g. ruby/new_hash_syntax, or remote url, or local file path
        --show-run-process           show processing files when running a snippet
        --skip FILE_PATTERNS         skip specified files or directories, separated by comma, e.g. app/models/post.rb,vendor/plugins/**/*.rb
    -f, --format FORMAT              output format
    -v, --version                    show this version
>>> 9:08:30 user3@myworkstation ~ ➜ c
>>> 9:08:34 user3@myworkstation ~ ➜ sv -l
/Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/synvert-0.20.0/lib/synvert/cli.rb:128:in `run_option_parser': undefined method `path=' for Synvert::Core::Configuration:Class (NoMethodError)

      Core::Configuration.path = paths.first || Dir.pwd
                         ^^^^^^^
	from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/synvert-0.20.0/lib/synvert/cli.rb:28:in `run'
	from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/synvert-0.20.0/lib/synvert/cli.rb:16:in `run'
	from /Users/user3/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/synvert-0.20.0/bin/synvert-ruby:7:in `<top (required)>'
	from /System/Volumes/Data/Users/user3/.rbenv/versions/3.1.2/bin/synvert-ruby:25:in `load'
	from /System/Volumes/Data/Users/user3/.rbenv/versions/3.1.2/bin/synvert-ruby:25:in `<main>'

Looks like a code issue. Mac Mini M1, ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21].

can't modify frozen String (RuntimeError) on Ruby 1.9.3

$ synvert -s ruby/new_hash_syntax
/Users/zhour6/.rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/rubygems/version.rb:191:in `strip!': can't modify frozen String (RuntimeError)
    from /Users/zhour6/.rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/rubygems/version.rb:191:in `initialize'
    from (eval):8:in `new'
    from (eval):8:in `block (2 levels) in load_rewriters'
    from /Users/zhour6/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/synvert-core-0.6.3/lib/synvert/core/rewriter.rb:153:in `instance_eval'
    from /Users/zhour6/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/synvert-core-0.6.3/lib/synvert/core/rewriter.rb:153:in `process'
    from /Users/zhour6/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/synvert-core-0.6.3/lib/synvert/core/rewriter.rb:160:in `process_with_sandbox'
    from /Users/zhour6/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/synvert-0.5.3/lib/synvert/cli.rb:160:in `show_rewriter'
    from /Users/zhour6/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/synvert-0.5.3/lib/synvert/cli.rb:32:in `run'
    from /Users/zhour6/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/synvert-0.5.3/lib/synvert/cli.rb:12:in `run'
    from /Users/zhour6/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/synvert-0.5.3/bin/synvert:7:in `<top (required)>'
    from /Users/zhour6/.rbenv/versions/1.9.3/bin/synvert:23:in `load'
    from /Users/zhour6/.rbenv/versions/1.9.3/bin/synvert:23:in `<main>'
$ ruby --version
ruby 1.9.3p545 (2014-02-24 revision 45159) [x86_64-darwin12.5.0]
$ gem --version
1.8.23.2

Any help? Thanks!

Add a snippet to convert `confirm` syntax to Rails 4.1

Rails 4.1 adds a new syntax for the confirm option in link_to helpers, so that it must be inside the data hash:

=link_to 'Here', '#', data: {confirm: 'Are you sure?'}

I'm in process of migrating an existing app to rails 4.1, so I might do this myself if no one else does it first :)

default install of synvert 0.5.3 is broken (w/ ruby 2.1.2)

on OSX 10.9, ruby installed via rvm, this is the latest available gem:

$ gem install synvert
Fetching: ast-2.0.0.gem (100%)
Successfully installed ast-2.0.0
Fetching: parser-2.2.0.pre.4.gem (100%)
Successfully installed parser-2.2.0.pre.4
Fetching: synvert-core-0.6.2.gem (100%)
Successfully installed synvert-core-0.6.2
Fetching: synvert-0.5.3.gem (100%)
Successfully installed synvert-0.5.3
Parsing documentation for ast-2.0.0
Installing ri documentation for ast-2.0.0
Parsing documentation for parser-2.2.0.pre.4
Installing ri documentation for parser-2.2.0.pre.4
Parsing documentation for synvert-0.5.3
Installing ri documentation for synvert-0.5.3
Parsing documentation for synvert-core-0.6.2
Installing ri documentation for synvert-core-0.6.2
Done installing documentation for ast, parser, synvert, synvert-core after 19 seconds
4 gems installed
$ synvert -l
/Users/riffraff/.rvm/gems/ruby-2.1.2/gems/synvert-0.5.3/lib/synvert/cli.rb:124:in list_available_rewriters': undefined methodempty?' for nil:NilClass (NoMethodError)
from /Users/riffraff/.rvm/gems/ruby-2.1.2/gems/synvert-0.5.3/lib/synvert/cli.rb:30:in run' from /Users/riffraff/.rvm/gems/ruby-2.1.2/gems/synvert-0.5.3/lib/synvert/cli.rb:12:inrun'
from /Users/riffraff/.rvm/gems/ruby-2.1.2/gems/synvert-0.5.3/bin/synvert:7:in <top (required)>' from /Users/riffraff/.rvm/gems/ruby-2.1.2/bin/synvert:23:inload'
from /Users/riffraff/.rvm/gems/ruby-2.1.2/bin/synvert:23:in <main>' from /Users/riffraff/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:ineval'
from /Users/riffraff/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `

'

It seems the line should either be

  if Core::Rewriter.availables.nil? || Core::Rewriter.availables.empty?

or better, @rewriters in core should be initialized properly (or used consistently through an accessor that initializes it lazily, but I don't see why :)

Allow nested `replace_with`

Original code:

Post.where{ (due_at < Time.zone.now) & ~paid }

Target code:

Post.where("due_at < Time.zone.now AND paid = 0")

Actual result:

Post.where{ due_at < Time.zone.now AND paid = 0 }

Snippet

within_file 'test.rb' do
  within_node type: 'block', caller: {message: 'where'} do

    within_node type: 'send', message: '&' do
      replace_with "{{receiver}} AND {{arguments}}"
    end
    within_node type: 'send', message: '>' do
      replace_with "{{receiver}} > {{arguments}}"
    end
    within_node type: 'send', message: '~' do
      replace_with "{{receiver}} = 0"
    end
    within_node type: 'begin' do
      replace_with "{{body}}"
    end
    # this rule is ignored
    replace_with %Q{where("{{body}}")}
  end
end

This could be done by helper_method, but it is harder to write and read.
So what I want is that each part should be replaced by its own rule while the scope is respected.
I think currently the nested scope works, but it only allow one replace_with call.

if_ruby does not use the good ruby version

Hi,

I tried to use the last version of synvert and I have something which looks like an issue.

What I did:

$> rbenv version
2.1.6
$> gem install synvert
Fetching: synvert-core-0.9.0.gem (100%)
Fetching: synvert-0.9.0.gem (100%)
Successfully installed synvert-core-0.9.0
Successfully installed synvert-0.9.0
Parsing documentation for synvert-0.9.0
Parsing documentation for synvert-core-0.9.0
Installing ri documentation for synvert-0.9.0
Installing ri documentation for synvert-core-0.9.0
Done installing documentation for synvert, synvert-core after 0 seconds
2 gems installed
$> synvert --sync
Cloning into '/Users/work/.synvert'...
remote: Counting objects: 1120, done.
remote: Total 1120 (delta 0), reused 0 (delta 0), pack-reused 1120
Receiving objects: 100% (1120/1120), 187.29 KiB | 102.00 KiB/s, done.
Resolving deltas: 100% (777/777), done.
Checking connectivity... done.
synvert snippets are synced

When I try to run, for example, synvert -r ruby/new_hash_syntax which should replace old hashes by new ones, when ruby is greater than 1.9, nothing happen:

$> synvert -r ruby/new_hash_syntax arena_core
===== ruby/new_hash_syntax started =====
===== ruby/new_hash_syntax done =====
$> git status
## feature-#5950...github/feature-#5950

I tried to add some debug in the synvert gem and the ruby version seems to be set 2.2.0 instead of 1.9 when I run the snippet.
Then, I removed all the snippets except the new_hash_syntax from the .synvert folder. And now the good version of ruby is used, and the task is working.

My guess is: there is a bug in the new if_ruby DSL. It uses the ruby version set in the last snippet loaded instead of using the one from the snippet we want to run. Does that sound right?

Thanks

add other snippet

e.g.

Synvert::Rewriter.new 'upgrade rails from 3.2 to 4.0' do
  add_snippet 'strong_parameters'
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.