Sha256: d0bd1979082b616b7332e0c7c25759629416405b9e6e4c50266b68e7be12ff90

Contents?: true

Size: 882 Bytes

Versions: 25

Compression:

Stored size: 882 Bytes

Contents

require 'json'
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
      end

      def offenses_by_file
        return [] if @filenames.empty?

        escaped_paths = @filenames.map { |path| Shellwords.escape(path) }
        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
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
ndr_dev_support-5.2.0 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.1.0 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.0.1 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-5.0.0 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-4.2.1 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-4.2.0 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-4.1.3 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-4.1.2 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-4.1.1 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-4.1.0 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-4.0.0 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-3.1.3 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-3.1.2 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-3.1.1 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-3.1.0 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-3.0.0 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-2.1.2 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-2.1.1 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-2.0.2 lib/ndr_dev_support/rubocop/executor.rb
ndr_dev_support-2.0.1 lib/ndr_dev_support/rubocop/executor.rb