我熟悉python,需要在我目前的工作中进行ruby开发。在设置我的编辑时,我注意到一些比我喜欢的更经常地咬我的东西:
--我的编辑器没有提醒我注意ruby中未定义的变量
据我所知,Pylint会在python中提醒我这一点,rubocop对ruby则不这么做。
我无法确定的是:是否有可能填补这一空白?
作为参考,我将新病毒与CoC和白酒结合使用。CoC用于完成,并运行LSP。如果需要的话,我很乐意把另一种工具加入其中。
下面是一些人为的示例代码,如果修复了,则需要打印:
omg
wtf
bbq
foo
barPython:
# pylint: disable=missing-function-docstring,disallowed-name,missing-module-docstring
def omg():
output = "omg"
print(output)
return output
def wtf():
output = "wtf"
print(output)
return output
def bbq():
output = "bbq"
print(outtputt)
return output
def foo():
output = "foo"
print(outtputt)
if __name__ == "__main__":
omg()
wtf()
bbq()
foo()
print("bar")红宝石:
# frozen_string_literal: true
def omg
output = 'omg'
puts output
output
end
def wtf
output = 'wtf'
puts output
output
end
def bbq
output = 'bbq'
puts outtputt
output
end
def foo
output = 'foo'
puts outtputt
end
if __FILE__ == $PROGRAM_NAME
omg
wtf
bbq
foo
puts 'bar'
end在上面的python上运行vanilla pylint将提供给我:
python_var_error.py:16:10: E0602: Undefined variable 'outtputt' (undefined-variable)
python_var_error.py:22:10: E0602: Undefined variable 'outtputt' (undefined-variable)
python_var_error.py:21:4: W0612: Unused variable 'output' (unused-variable)然而,在上面的红宝石上运行香草rubocop只会给我:
ruby_var_error.rb:22:3: W: Lint/UselessAssignment: Useless assignment to variable - output. Did you mean outtputt?
output = 'foo'我可以使用什么工具(如果有的话)来提醒我上面ruby中第17行的错误?
到目前为止,我发现的一切(示例)似乎都是粗略的“红宝石做不到,你是索尔。”
发布于 2022-07-26 22:08:56
我可以使用什么工具(如果有的话)提醒我在上面的红宝石第17行的错误?
没有(静态)工具可以用于警告第17行的错误,因为第17行没有(静态)错误。第17行是完全有效的Ruby代码,它调用一个名为outtputt的方法,并将结果作为参数传递给puts的方法调用。
由于没有(静态)错误,因此不可能有显示错误的(静态)工具。
显然,如果未定义该方法,这将是一个运行时错误,并将被您的测试捕获。
https://stackoverflow.com/questions/73130202
复制相似问题