【问题标题】:i am getting error of ABC error from rubocop how i can remove it我从 rubocop 收到 ABC 错误错误,我该如何删除它
【发布时间】:2021-10-21 11:27:32
【问题描述】:
def result_p3(high, low)
    arr_ind = []
    ((1..31).each { |n| arr_ind << n })
    (0..30).each do |i|
      puts " #{arr_ind[i]}" + " #{'+' * high[i].to_i} ".red + "#{high[i].to_i}C "
      puts " #{arr_ind[i]}" + " #{'+' * low[i].to_i} ".blue + "#{low[i].to_i}C "
    end
  end

【问题讨论】:

    标签: ruby rubocop


    【解决方案1】:

    RuboCop 非常清楚问题所在:your method is too large。你可以:

    1. 重构您的代码,使其符合您团队的编码标准,这是推荐的方法;
    2. update your todo file 所以在你准备好修复它之前你不会看到错误;或
    3. disable the cop for this method,如果您不明白为什么 RuboCop 会告诉您您的代码不理想,那么您绝对不应该这样做。

    RuboCop 是一个 linter 和 style guide。它并不总是正确的,但在这种情况下它是正确的。您的方法需要重构,所以要么这样做,要么推迟修复它,但绝对将其视为代码异味。

    【讨论】:

      【解决方案2】:

      arr_ind 是多余的,它包含从 1 到 31 的数字。对于xarr_ind[x] == x + 1 的任何值。除了#{arr_ind[i]},您可以只使用#{i + 1}。当然,删除与arr_ind 相关的所有内容。

      【讨论】:

        猜你喜欢
        • 2021-07-08
        • 2015-01-14
        • 2020-01-22
        • 1970-01-01
        • 2022-12-21
        • 1970-01-01
        • 1970-01-01
        • 2018-01-19
        相关资源
        最近更新 更多