Class: Codegrade::Grader::Rubocop

Inherits:
Object
  • Object
show all
Defined in:
lib/codegrade/grader/rubocop.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Rubocop

Returns a new instance of Rubocop.



6
7
8
9
# File 'lib/codegrade/grader/rubocop.rb', line 6

def initialize(file)
  @config_store = RuboCop::ConfigStore.new
  @file = file
end

Instance Attribute Details

#config_storeObject (readonly)

Returns the value of attribute config_store.



4
5
6
# File 'lib/codegrade/grader/rubocop.rb', line 4

def config_store
  @config_store
end

#fileObject (readonly)

Returns the value of attribute file.



4
5
6
# File 'lib/codegrade/grader/rubocop.rb', line 4

def file
  @file
end

Instance Method Details

#gradeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/codegrade/grader/rubocop.rb', line 11

def grade
  processed_file = RuboCop::ProcessedSource.from_file(file)
  config = config_store.for(processed_file.path)
  team = RuboCop::Cop::Team.new(classes, config, {})

  team.inspect_file(processed_file).map do |rubocop_offense|
    Offense.new(category: rubocop_offense.message,
      line_number: rubocop_offense.line,
      column_number: rubocop_offense.real_column,
      file: file,
      source: rubocop_offense.location.source)
  end
end