troessner / reek

Code smell detector for Ruby
https://github.com/troessner/reek
MIT License
4.05k stars 280 forks source link

UncommunicativeVariableName does not take regex configuration into account #1063

Closed troessner closed 8 years ago

troessner commented 8 years ago

Found this bug while investigating #1058

Given this config.reek:


---
UncommunicativeVariableName:
  accept:
  - /\d+$/

this:

def foo; x1 = 2; end

shouldn't smell of UncommunicativeVariableName. Unfortunately it does:

 reek -c config.reek foo.rb
foo.rb -- 1 warning:
  [1]:UncommunicativeVariableName: foo has the variable name 'x1'

The reason for this behaviour is here:

      def bad_name?(name, _ctx)
        var = name.to_s.gsub(/^[@\*\&]*/, '')
        return false if accept_names.include?(var) # <- here is the problem!
        reject_names.find { |patt| patt =~ var }
      end

We only check for literals here, not for regexes. The other Uncommunicative* smell detectors are not affected by the issue since they rightfully check for literals and regexes.

troessner commented 8 years ago

I'll tackle that in the next couple of days.

troessner commented 8 years ago

Working on this issue in #1065