Sha256: 576913007b61c278bc5961a9517ccd8291cb4c0fc69350f7acd3a32846500857

Contents?: true

Size: 1.19 KB

Versions: 19

Compression:

Stored size: 1.19 KB

Contents

require 'json'
require 'open3'
require 'shellwords'

module NdrDevSupport
  module Rubocop
    # This class filters the Rubocop report of a file
    # to only the given lines.
    class Executor
      class << self
        # Use RuboCop to produce a list of all files that should be scanned.
        def target_files
          @target_files ||= `rubocop -L`.each_line.map(&:strip)
        end
      end

      def initialize(filenames)
        @filenames = Executor.target_files & filenames

        check_ruby_syntax
      end

      def offenses_by_file
        return [] if @filenames.empty?

        output = JSON.parse(`rubocop --format json #{escaped_paths.join(' ')}`)

        output['files'].each_with_object({}) do |file_output, result|
          result[file_output['path']] = file_output['offenses']
        end
      end

      private

      def escaped_paths
        @escaped_paths ||= @filenames.map { |path| Shellwords.escape(path) }
      end

      def check_ruby_syntax
        escaped_paths.each do |path|
          stdout_and_err_str, status = Open3.capture2e("ruby -c #{path}")
          next if status.exitstatus.zero?

          raise stdout_and_err_str
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ndr_dev_support-5.9.0 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.8.2 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.8.1 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.8.0 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.7.1 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.7.0 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.6.0 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.5.0 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.4.8 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.4.7 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.4.6 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.4.5 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.4.4 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.4.3 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.4.2 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.4.1 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.4.0 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.3.1 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.3.0 lib/ndr_dev_support/rubocop/executor.rb