Sha256: a51b30573e285caf93cf94a2811568bf208a44c7ab0865eebf768ff7f85885eb

Contents?: true

Size: 883 Bytes

Versions: 7

Compression:

Stored size: 883 Bytes

Contents

require 'yaml'

module Reek
  #
  # A comment header from an abstract syntax tree; found directly above
  # module, class and method definitions.
  #
  # @api private
  class CodeComment
    CONFIG_REGEX = /:reek:(\w+)(:\s*\{.*?\})?/

    def initialize(text)
      @text = text.gsub(CONFIG_REGEX) do
        add_to_config($1, $2)
        ''
      end.gsub(/#/, '').gsub(/\n/, '').strip
    end

    def config
      @config ||= Hash.new { |hash, key| hash[key] = {} }
    end

    def descriptive?
      @text.split(/\s+/).length >= 2
    end

    protected

    def add_to_config(smell, options)
      options ||= ': { enabled: false }'
      config.merge! YAML.load(smell.gsub(/(?:^|_)(.)/) { $1.upcase } + options)
      # TODO: extend this to all configs -------------------^
      # TODO: extend to allow configuration of whole smell class, not just subclass
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
reek-3.2.1 lib/reek/code_comment.rb
reek-3.1 lib/reek/code_comment.rb
reek-3.0.4 lib/reek/code_comment.rb
reek-3.0.3 lib/reek/code_comment.rb
reek-3.0.2 lib/reek/code_comment.rb
reek-3.0.1 lib/reek/code_comment.rb
reek-3.0.0 lib/reek/code_comment.rb