Class: Ducalis::FetchExpression
- Inherits:
-
RuboCop::Cop::Cop
- Object
- RuboCop::Cop::Cop
- Ducalis::FetchExpression
- Defined in:
- lib/ducalis/cops/fetch_expression.rb
Constant Summary collapse
- HASH_CALLING_REGEX =
/\:\[\]/.freeze
- OFFENSE =
" | You can use `fetch` instead:\n\n | ```ruby\n | %<source>s\n | ```\n\n | If your hash contains `nil` or `false` values and you want to treat them not like an actual values you should preliminarily remove this values from hash.\n | You can use `compact` (in case if you do not want to ignore `false` values) or `keep_if { |key, value| value }` (if you want to ignore all `false` and `nil` values).\n".gsub(/^ +\|\s/, '').strip
Instance Method Summary collapse
Instance Method Details
#investigate(processed_source) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/ducalis/cops/fetch_expression.rb', line 20 def investigate(processed_source) return unless processed_source.ast matching_nodes(processed_source.ast).each do |node| add_offense(node, :expression, format(OFFENSE, source: correct_variant(node))) end end |