简体   繁体   English

我在哪里可以找到一个积极开发的Ruby工具?

[英]Where can I find an actively developed lint tool for Ruby?

Most of the code I write is in Ruby, and every once in a while, I make some typo which only gets caught after a while. 我编写的大多数代码都是在Ruby中,每隔一段时间,我会做一些错字,只会在一段时间后被捕获。 This is irritating when I have my scripts running long tasks, and return to find I had a typo. 当我的脚本运行很长的任务时,这很烦人,回来发现我有一个错字。

Is there an actively developed lint tool for Ruby that could help me overcome this? 是否有一个积极开发的Ruby工具lint工具可以帮助我克服这个问题? Would it be possible to use it across a system that works with a lot of source files, some of them loaded dynamically? 是否可以在一个使用大量源文件的系统中使用它,其中一些是动态加载的?

Take this snippet as an example: 以此片段为例:

a = 20
b = 30
puts c

To win bounty, show me a tool that will detect the c variable as not created/undefined. 要获得赏金,请向我展示一个工具,它将检测c变量为未创建/未定义。

  • ruby -c myfile.rb will check for correct Ruby syntax. ruby -c myfile.rb将检查正确的Ruby语法。
  • Reek checks Ruby code for common code smells. Reek检查Ruby代码以查找常见的代码味道。
  • Roodi checks Ruby code for common object-oriented design issues. Roodi检查Ruby代码以解决常见的面向对象设计问题。
  • Flog can warn you about unusually complex code. Flog可以警告您异常复杂的代码。

[Plug] If your project is in a public Github repository, Caliper can run the latter three tools and others on your code every time you commit. [Plug]如果您的项目位于公共Github存储库中,则每次提交时, Caliper都可以在您的代码上运行后三个工具和其他工具。 (Disclaimer: I work on Caliper) (免责声明:我在Caliper工作)

You could give Diamondback Ruby a try. 您可以尝试使用Diamondback Ruby It does a static typecheck of Ruby code, and will thus blame you for using an undefined variable. 它执行Ruby代码的静态类型检查,因此会责怪您使用未定义的变量。

While DRuby is an ongoing research project, it already works quite well for small, self-contained Ruby scripts. 虽然DRuby是一个正在进行的研究项目,但它已经适用于小型,自包含的Ruby脚本。 Currently, it is unable to analyze much of the Ruby standard library “out-of-the-box”. 目前,它无法分析大量的Ruby标准库“开箱即用”。 Currently they are working toward typing Ruby on Rails (see their most recent papers ). 目前他们正在努力键入Ruby on Rails(参见他们最近的论文 )。

RubyMine ( http://www.jetbrains.com/ruby ) does the trick: RubyMinehttp://www.jetbrains.com/ruby )可以解决这个问题:

alt text http://img707.imageshack.us/img707/5688/31911448.png alt text http://img707.imageshack.us/img707/5688/31911448.png

None of the below will do all the analysis that RubyMine does. 以下所有内容都不会完成RubyMine的所有分析。

  • NetBeans Ruby pack NetBeans Ruby包
  • Aptana RadRails Aptana RadRails
  • gVIM (with syntastic plugin by scrooloose) gVIM(通过scrooloose合成插件)

Each of these has the capacity to identify syntax errors such as wrong number of parentheses, too many defs, ends, braces, etc. But none will identify invalid method calls the way RubyMine does. 这些中的每一个都有能力识别语法错误,例如错误的括号,太多的defs,end,braces等。但是没有人会像RubyMine那样识别无效的方法调用。

Here's why: it's difficult. 原因如下:这很难。

Since Ruby is extremely dynamic (and methods like 'c' could easily be generated on the fly), any editor that tries to identify non-existent variables/methods would need to have a large part of the entire evironment loaded and multiple program flow paths constantly tested in order to get accurate 'validity' results. 由于Ruby非常动态(像'c'这样的方法可以轻松生成),任何试图识别不存在的变量/方法的编辑器都需要加载整个环境的很大一部分和多个程序流路径经过不断测试,以获得准确的“有效性”结果。 This is much more difficult than in Java where almost all programming is static (at least it was when I dropped that hat). 这比几乎所有编程都是静态的Java要困难得多(至少在我放弃那个帽子的时候)。

This ability to easily generate methods on the fly is one of the reasons the community holds testing to such high esteem. 这种轻松生成方法的能力是社区对这种高度尊重进行测试的原因之一。 I really do reccomend you try testing as well. 我确实建议您尝试测试。

Have a look at RuboCop . 看看RuboCop It is a Ruby code style checker based on the Ruby Style Guide . 它是一个基于Ruby样式指南的Ruby代码样式检查器。 It's maintained pretty actively and supports all major Ruby implementations. 它非常积极地维护并支持所有主要的Ruby实现。 It works well with Ruby 1.9 and 2.0 and has great Emacs integration. 它适用于Ruby 1.9和2.0,并且具有出色的Emacs集成。

Yes. 是。 Test::Unit

Ok, I know you already know this and that in some sense this is a non-helpful answer, but you do bring up the negative consequence of duck typing, that there kind of is (at this time) no way around just writing more tests than something like Java might need. 好吧,我知道你已经知道了这一点,从某种意义上讲,这是一个无用的答案,但是你确实提出了鸭子打字的负面后果,那就是(此时)还没有办法只是写更多的测试比Java可能需要的东西。

So, for the record, see Test::Unit in the Ruby Standard Library or one of the other test frameworks. 因此,对于记录,请参阅Ruby标准库中的Test::Unit或其他测试框架之一。

Having unit tests that you can run and rerun is the best way to catch errors, and you do need more of them (tests, not errors :-) in dynamic languages like Ruby... 拥有可以运行和重新运行的单元测试是捕获错误的最佳方法,并且在Ruby等动态语言中确实需要更多(测试,而不是错误:-) ...

nitpick might be what you're lookng for. nitpick可能是你所期待的。

With this code: 使用此代码:

class MyString < String
  def awesome
    self.gsub("e", "3").gsub("l", "1").uppercase
  end
end

puts MyString.new("leet").awesome

... it outputs: ......它输出:

$ nitpick misspelling.rb 
*** Nitpick had trouble loading "misspelling.rb":
    NoMethodError undefined method `uppercase' for "133t":MyString
Nothing to report boss! He's clean!

Pelusa is nice, but is working in rubinius only. Pelusa很不错,但只在rubinius工作。 This shouln't be a proplem for people familar with RVM though. 对于熟悉RVM的人来说,这不是一个问题。

Have not used it yet, but sounds promising (will update when I've tested this). 尚未使用它,但听起来很有希望(当我测试这个时会更新)。

https://github.com/michaeledgar/laser https://github.com/michaeledgar/laser

Static analysis and style linter for Ruby code. Ruby代码的静态分析和样式linter。

avdi@lazarus:~$ irb
>> a = 20
=> 20
>> b = 30
=> 30
>> puts c
NameError: undefined local variable or method `c' for main:Object
        from (irb):3
>>

There ya go, the tool is called "IRB". 你去了,这个工具被称为“IRB”。 Do I get the bounty? 我得到了赏金吗?

I'm only half joking. 我只是半开玩笑。 I wrote this second answer to hopefully drive home the point that in Ruby, if you want to know that something is defined or not, you have to run the code . 我写了第二个答案,希望能够回到家中,在Ruby中,如果你想知道某些东西是否被定义, 你必须运行代码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在哪里可以找到 Ruby 宝石的集合? - Where can I find a collection Of Ruby Gems? IronRuby正在积极开发吗? - Is IronRuby being actively developed? 在哪里可以找到AWS Ruby SDK连接的URL? - Where can I find the URLs that the AWS Ruby SDK connects to? 我在哪里可以找到与其兼容的 Ruby 版本的 gem 的版本号? - Where can I find the version numbers of gems with the Ruby version it is compatible with? 我在哪里可以找到一个好的语法检查器,以便在Emacs中使用ruby - Where can I find a good syntax checker for ruby to use in Emacs 我在哪里可以找到 Ruby 文档中的字符串转义序列? - Where can I find string escape sequences in the Ruby documentation? 我在哪里可以找到Ruby中数学密集的应用程序 - Where can I find math intense apps in Ruby 我如何找到在Ruby中进行Minitest运行期间抛出异常的位置? - How can I find where exception is thrown during a Minitest run in Ruby? Python客户端无法与ruby服务器通信。 我得到[Errno 10061]无法建立连接,因为目标计算机主动拒绝了它 - Python client can not communicate with ruby server. I get [Errno 10061] No connection could be made because the target machine actively refused it 为什么 Ruby 的(辛酸)指南:我在哪里可以找到工作的 preeventualist.org 镜像(或类似的东西)? - Why's (Poignant) Guide to Ruby: Where can I find a working preeventualist.org mirror (or something like it)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM