meetcleo / rubocop-magic_numbers

A RuboCop Cop that detects the use of magic numbers within instance methods
MIT License
46 stars 3 forks source link

Invalid syntax on readme #63

Closed evanthegrayt closed 1 year ago

evanthegrayt commented 1 year ago

I was reading about this gem via the readme, and thought the syntax under the MagicNumbers/NoDefault section looked incorrect. I checked it using version 3.2.2, and I do indeed get errors.

def over_widget_limit?(20)
  # ...
end
# SyntaxError: unexpected integer literal, expecting ')'
# def over_widget_limit?(20)
#                        ^~

def over_widget_limit?(FREE_SUBSCRIPTION_WIDGET_MAX)
  # ...
end
# (eval):2: formal argument cannot be a constant
# ...t?(FREE_SUBSCRIPTION_WIDGET_MAX)
# ...   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

I'm not sure what the correct usage should be, but I assume either method calls?

# BAD
over_widget_limit?(20)

# GOOD
over_widget_limit?(FREE_SUBSCRIPTION_WIDGET_MAX)

...or method definitions with a default?

# BAD
def over_widget_limit?(max = 20)
  # ...
end

# GOOD
def over_widget_limit?(max = FREE_SUBSCRIPTION_WIDGET_MAX)
  # ...
end
Bodacious commented 1 year ago

Thanks @evanthegrayt. I've updated the README now