Sha256: ba8cd035937a5fc0d58233b78e5c648e65ab106eb6055504aa7725f6f75cf7b0

Contents?: true

Size: 719 Bytes

Versions: 10

Compression:

Stored size: 719 Bytes

Contents

# frozen_string_literal: true

module Gitlab
  module Styles
    module Common
      module BannedConstants
        attr_reader :replacements, :message_template, :autocorrect

        def on_const(node)
          constant = node.source.delete_prefix('::')

          return unless replacements.key?(constant)

          replacement = replacements.fetch(constant)
          message = format(message_template, { replacement: replacement })

          add_offense(node, message: message) do |corrector|
            next unless autocorrect

            replacement = "::#{replacement}" if node.source.start_with?("::")

            corrector.replace(node, replacement)
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gitlab-styles-13.0.1 lib/gitlab/styles/common/banned_constants.rb
gitlab-styles-13.0.0 lib/gitlab/styles/common/banned_constants.rb
gitlab-styles-11.0.0 lib/gitlab/styles/common/banned_constants.rb
gitlab-styles-10.1.0 lib/gitlab/styles/common/banned_constants.rb
gitlab-styles-10.0.0 lib/gitlab/styles/common/banned_constants.rb
gitlab-styles-9.2.0 lib/gitlab/styles/common/banned_constants.rb
gitlab-styles-9.1.0 lib/gitlab/styles/common/banned_constants.rb
gitlab-styles-9.0.0 lib/gitlab/styles/common/banned_constants.rb
gitlab-styles-8.0.0 lib/gitlab/styles/common/banned_constants.rb
gitlab-styles-7.1.0 lib/gitlab/styles/common/banned_constants.rb