Module: Gitlab::Styles::Common::BannedConstants
- Defined in:
- lib/gitlab/styles/common/banned_constants.rb
Instance Attribute Summary collapse
-
#autocorrect ⇒ Object
readonly
Returns the value of attribute autocorrect.
-
#message_template ⇒ Object
readonly
Returns the value of attribute message_template.
-
#replacements ⇒ Object
readonly
Returns the value of attribute replacements.
Instance Method Summary collapse
Instance Attribute Details
#autocorrect ⇒ Object (readonly)
Returns the value of attribute autocorrect.
7 8 9 |
# File 'lib/gitlab/styles/common/banned_constants.rb', line 7 def autocorrect @autocorrect end |
#message_template ⇒ Object (readonly)
Returns the value of attribute message_template.
7 8 9 |
# File 'lib/gitlab/styles/common/banned_constants.rb', line 7 def @message_template end |
#replacements ⇒ Object (readonly)
Returns the value of attribute replacements.
7 8 9 |
# File 'lib/gitlab/styles/common/banned_constants.rb', line 7 def replacements @replacements end |
Instance Method Details
#on_const(node) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gitlab/styles/common/banned_constants.rb', line 9 def on_const(node) constant = node.source.delete_prefix('::') return unless replacements.key?(constant) replacement = replacements.fetch(constant) = format(, { replacement: replacement }) add_offense(node, message: ) do |corrector| next unless autocorrect replacement = "::#{replacement}" if node.source.start_with?("::") corrector.replace(node, replacement) end end |