Too-Many-Constants.md

October 18, 2023 ยท View on GitHub

Introduction

Too Many Constants is a case of Large Class.

Example

Given this configuration

TooManyConstants:
  max_constants: 3

and this code:

class Smelly
  CONST_1 = :dummy
  CONST_2 = :dummy
  CONST_3 = :dummy
  CONST_4 = :dummy
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [1]:TooManyConstants: Smelly has 4 constants

Configuration

Reek's Too Many Constants detector offers the Basic Smell Options, plus:

OptionValueEffect
max_constantsintegerThe maximum number of constants that are permitted. Defaults to 5