没有回溯的Ruby警告检查?

时间:2015-02-18 00:52:00

标签: ruby warnings

我想检查项目中所有ruby文件的警告。

$ cd my_project
$ ruby -w **/*.rb
 /Users/sane/work/tachiko/pigeon.tachikoma.io/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.9.9.275/lib/new_relic/agent/sql_sampler.rb:9: warning: loading in progress, circular require considered harmful - /Users/sane/work/tachiko/pigeon.tachikoma.io/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.9.9.275/lib/new_relic/agent.rb
        from config/application.rb:14:in  `<main>'
        from /Users/sane/.anyenv/envs/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler.rb:134:in  `require'
        from /Users/sane/.anyenv/envs/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:61:in  `require'
        from /Users/sane/.anyenv/envs/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:61:in  `each'
        from /Users/sane/.anyenv/envs/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:72:in  `block in require'
        from /Users/sane/.anyenv/envs/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:72:in  `each'
        from /Users/sane/.anyenv/envs/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:76:in  `block (2 levels) in require'
        from /Users/sane/.anyenv/envs/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:76:in  `require'
        from /Users/sane/work/tachiko/pigeon.tachikoma.io/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.9.9.275/lib/newrelic_rpm.rb:25:in  `<top (required)>'
        from /Users/sane/work/tachiko/pigeon.tachikoma.io/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.9.9.275/lib/newrelic_rpm.rb:25:in  `require'
        from /Users/sane/work/tachiko/pigeon.tachikoma.io/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.9.9.275/lib/new_relic/control.rb:23:in  `<top (required)>'
        from /Users/sane/work/tachiko/pigeon.tachikoma.io/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.9.9.275/lib/new_relic/control.rb:23:in  `require'  
        from /Users/sane/work/tachiko/pigeon.tachikoma.io/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.9.9.275/lib/new_relic/agent.rb:40:in  `<top (required)>'
    from /Users/sane/work/tachiko/pigeon.tachikoma.io/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.9.9.275/lib/new_relic/agent.rb:69:in  `<module:NewRelic>'
    from /Users/sane/work/tachiko/pigeon.tachikoma.io/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.9.9.275/lib/new_relic/agent.rb:95:in  `<module:Agent>'
    from /Users/sane/work/tachiko/pigeon.tachikoma.io/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.9.9.275/lib/new_relic/agent.rb:95:in  `require'
    from /Users/sane/work/tachiko/pigeon.tachikoma.io/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.9.9.275/lib/new_relic/agent/sql_sampler.rb:10:in  `<top (required)>'
    from /Users/sane/work/tachiko/pigeon.tachikoma.io/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.9.9.275/lib/new_relic/agent/sql_sampler.rb:10:in  `require'
/Users/sane/work/tachiko/pigeon.tachikoma.io/vendor/bundle/ruby/2.1.0/gems/safe_yaml-1.0.4/lib/safe_yaml.rb:28: warning: method redefined; discarding old safe_load
/Users/sane/.anyenv/envs/rbenv/versions/2.1.5/lib/ruby/2.1.0/psych.rb:283: warning: previous definition of safe_load was here
(snip)

我想显示警告(第1行,第20行和第21行)。我不想显示回溯(第2行 - 第19行)。

  1. 这是从我的项目中获得警告的正确方法吗?
  2. 如何隐藏回溯?有选择吗?还是ruby -w **/*.rb | grep -v LINE_START_WITH_SPACE

1 个答案:

答案 0 :(得分:1)

  

这是从我的项目中获得警告的正确方法吗?

我用:

ruby -wW2 /path/to/script.rb

在我检查代码时收到完整的警告。

Ruby的命令行帮助说:

  -w              turn warnings on for your script
  -W[level=2]     set warning level; 0=silence, 1=medium, 2=verbose