Sha256: 3f60a37522c9831543e843a53a37f8cc44d9b0581e66f5bd991c5bc766901af1

Contents?: true

Size: 860 Bytes

Versions: 4

Compression:

Stored size: 860 Bytes

Contents

require_relative '../ruler'


class Tailor
  module Rulers
    class AllowInvalidRubyRuler < Tailor::Ruler
      def initialize(config, options)
        super(config, options)
        add_lexer_observers :file_beg
      end

      def file_beg_update(file_name)
        @file_name = file_name
        measure
      end

      # @return [Boolean]
      def invalid_ruby?
        log 'Checking for valid Ruby...'
        result = `"#{Gem.ruby}" -c "#{@file_name}"`

        result.size.zero?
      end

      def measure
        if invalid_ruby? && @config == false
          lineno = 0
          column = 0
          msg = 'File contains invalid Ruby; run `ruby -c [your_file.rb]` '
          msg << 'for more details.'

          @problems << Problem.new(problem_type, lineno, column, msg,
            @options[:level])
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tailor-1.4.1 lib/tailor/rulers/allow_invalid_ruby_ruler.rb
tailor-1.4.0 lib/tailor/rulers/allow_invalid_ruby_ruler.rb
tailor-1.3.1 lib/tailor/rulers/allow_invalid_ruby_ruler.rb
tailor-1.3.0 lib/tailor/rulers/allow_invalid_ruby_ruler.rb