查看 rubocop 源代码后,参数对齐的规则似乎在/lib/rubocop/cop/style/align_parameters.rb line 34:
def base_column(node, args)
if fixed_indentation?
lineno = target_method_lineno(node)
line = node.loc.expression.source_buffer.source_line(lineno)
indentation_of_line = /\S.*/.match(line).begin(0)
------> indentation_of_line + configured_indentation_width
else
args.first.loc.column
end
end
configured_indentation_width
定义在lib/rubocop/cop/mixin/autocorrect_alignment.rb line 10:
def configured_indentation_width
-> config.for_cop('IndentationWidth')['Width']
end
该变量存储在/config/default.yml
其中,需要将所有代码设置为 4 个空格而不是 2 个(类似于 Python PEP8)。
否则,您可以只修改 rubocop 的源代码,在多行参数分配/方法调用中始终需要 4 个空格。
另一个(更好的)选项是修改源代码,但添加对配置变量的引用,这样您就不会使用硬编码值。