RuboCop complains when using "Hash.new"

RuboCop complains when I use Hash.new, and assumes that I use a hash literal instead. Is there a way to get RuboCop to ignore usage Hash.new? In particular, can I change the configuration .rubocop.ymlto allow use Hash.newwithout involving any complaints?

+4
source share
2 answers

You can disable Rubocop::Cop::Style::EmptyLiteralin the rubocop.yml file:

# .rubocop.yml
Style:
  EmptyLiteral: false

Or, if you want to just ignore a specific line:

hsh = Hash.new # rubocop:disable Style/EmptyLiteral
+3
source

Ruby Style Guide , . , , hash = {} hash = Hash.new.

, , , Style/EmptyLiteral cop, , .

rubocop.yml :

Style:
  EmptyLiteral: false

# rubocop:disable Style/EmptyLiteral
hash = Hash.new 
# rubocop:enable Style/EmptyLiteral

:

hash = Hash.new # rubocop:disable Style/EmptyLiteral

, Rubocop, .

+1

Source: https://habr.com/ru/post/1692605/


All Articles