Sha256: b8c2ed267301a852fa6cceecf8b5b85c4c8162ff45be93f4f92de880772ece73

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

module Wool
  module Advice
    # Using this module, you can make your match? method automatically
    # receive de-commented source text.
    #
    # class MyWarning < Wool::Warning do
    #   extend Wool::Advice::CommentAdvice
    #
    #   def self.match?(body, context)
    #     body.include?('#')
    #   end
    #   remove_comments
    # end
    module CommentAdvice
      def self.included(klass)
        klass.__send__(:extend, ClassMethods)
        klass.__send__(:include, InstanceMethods)
      end

      module ClassMethods
        def remove_comments
          argument_advice :match?, :comment_removing_twiddler
        end
      end

      module InstanceMethods
        # This twiddler aims to remove comments and trailing whitespace
        # from the ruby source input, so that warnings that aren't concerned
        # with the implications of comments in their source can safely
        # discard them. Uses Ripper to look for comment tokens.
        def comment_removing_twiddler(body = self.body, settings = {})
          [split_on_token(body, :on_comment).first.rstrip, settings]
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wool-0.5.1 lib/wool/advice/comment_advice.rb