Class: Codescout::RubocopStats
- Inherits:
-
Object
- Object
- Codescout::RubocopStats
- Defined in:
- lib/codescout/rubocop_stats.rb
Instance Attribute Summary collapse
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#initialize(analyzer) ⇒ RubocopStats
constructor
A new instance of RubocopStats.
- #select_offences(lines, offenses) ⇒ Object
Constructor Details
#initialize(analyzer) ⇒ RubocopStats
Returns a new instance of RubocopStats.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/codescout/rubocop_stats.rb', line 5 def initialize(analyzer) @analyzer = analyzer @results = {} install_config `rubocop -c rubocop.yml -f json -o rubocop.json` report = File.read("rubocop.json") return if report.empty? json = JSON.load(report) json["files"].each do |file| next unless @analyzer.files.include?(file["path"]) next if file["offenses"].empty? lines = File.read(file["path"]).split("\n") @results[file["path"]] = select_offences(lines, file["offenses"]) end end |
Instance Attribute Details
#results ⇒ Object (readonly)
Returns the value of attribute results.
3 4 5 |
# File 'lib/codescout/rubocop_stats.rb', line 3 def results @results end |
Instance Method Details
#select_offences(lines, offenses) ⇒ Object
28 29 30 |
# File 'lib/codescout/rubocop_stats.rb', line 28 def select_offences(lines, offenses) offenses.map { |o| o["code"] = lines[o["location"]["line"] - 1] ; o } end |