gpt4 book ai didi

ruby - 是否有任何源代码分析工具检测 Ruby 中未使用的参数?

转载 作者:数据小太阳 更新时间:2023-10-29 07:38:34 27 4
gpt4 key购买 nike

如何检测 Ruby 中未使用的参数?

我知道的选项包括

  • 对 TDD 严格。
  • Heckle(由于 ParseTree 问题,目前仅适用于 Ruby 1.8)
  • 使用 RubyMine 等 IDE 检测未使用的参数或自动进行重构。

但是否有任何源代码分析工具或警告选项允许您检测未使用的参数?

背景:我正在做一些重构。我改变了(代码略有简化):

# Not within the Foo class (therefore can't be as easily accessed by unit testing)
# and in addition, the name of the configuration file is hard-wired
def parse_configuration
raw_configuration = YAML.load_file("configuration.yml")
# Do stuff with raw_configuration to produce configuration_options_for_foo
return configuration_options_for_foo
end

if __FILE__ == $0
configuration_options_for_foo = parse_configuration
foo = Foo.new(configuration_options_for_foo)
end

class Foo
# Now unit tests can call Foo.new_using_yaml("configuration.yml")
# or use "test_configuration.yml"
def self.new_using_yaml(yaml_filename)
# Where I went wrong, forgetting to replace "configuration.yml" with yaml_filename
raw_configuration = YAML.load_file("configuration.yml")
# Do stuff with raw_configuration to produce configuration_options_for_foo
new(configuration_options_for_foo)
end
end

if __FILE__ == $0
foo = Foo.new_using_yaml("configuration.yml")
end

最佳答案

我认为激光可以做到这一点。

它还处于 alpha-y 阶段,但似乎可以按照您的意愿行事。

http://github.com/michaeledgar/laser

关于ruby - 是否有任何源代码分析工具检测 Ruby 中未使用的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6039025/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com