codeclimate 0.26.0 → 0.27.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d43c699da6eae6069acb8272502c1f14f21314b
4
- data.tar.gz: 831177029f49803b8196bc87ae215825856833af
3
+ metadata.gz: 9527caedfb7602bda076c88af7a6c5d776a66697
4
+ data.tar.gz: ba274a662e0f68a8479fe0a3f196720a5316ab56
5
5
  SHA512:
6
- metadata.gz: 011ea2bf09e8c6f49439546fe49cf18b55473163ba2b9b62b676b3054411db336870d9ccafa5387cb7cf25820de4a770f80ab722c2f7c6148effbb6e296fe7ed
7
- data.tar.gz: 37f30fe06ba2ac1c65874837fef499effe1f9eab80a7522f65061e0294428afce0b9101125afaa7d97172184544e8571e29a23c6b8f8d461e95b0ed54b45ebf3
6
+ metadata.gz: 5743efcfa4ee9acc4ee8b4de0949884a3a83af56146cdfa3330d896b0b607a0cc38384380a31c1f1a734afcb199badd9d51bba790ad816b591fd450bad58e6d6
7
+ data.tar.gz: 10a3d50fa006ee8c17eadd13d1028c776e4f4afe4f2a36ab5695d2a63d663106e27b33036a64c8534ee7759c6c8a31c55780bb3c526c878118bd38b3eb9182c2
data/lib/cc/analyzer.rb CHANGED
@@ -31,6 +31,8 @@ module CC
31
31
  autoload :MountedPath, "cc/analyzer/mounted_path"
32
32
  autoload :RaisingContainerListener, "cc/analyzer/raising_container_listener"
33
33
  autoload :SourceBuffer, "cc/analyzer/source_buffer"
34
+ autoload :SourceExtractor, "cc/analyzer/source_extractor"
35
+ autoload :SourceFingerprint, "cc/analyzer/source_fingerprint"
34
36
  autoload :StatsdContainerListener, "cc/analyzer/statsd_container_listener"
35
37
  autoload :Validation, "cc/analyzer/validation"
36
38
 
@@ -34,25 +34,21 @@ module CC
34
34
  end
35
35
  end
36
36
 
37
+ def path
38
+ parsed_output.fetch("location", {}).fetch("path", "")
39
+ end
40
+
37
41
  private
38
42
 
39
43
  attr_reader :output
40
44
 
41
45
  def default_fingerprint
42
- digest = Digest::MD5.new
43
- digest << path
44
- digest << "|"
45
- digest << check_name.to_s
46
- digest.to_s
46
+ SourceFingerprint.new(self).compute
47
47
  end
48
48
 
49
49
  def parsed_output
50
50
  @parsed_output ||= JSON.parse(output)
51
51
  end
52
-
53
- def path
54
- parsed_output.fetch("location", {}).fetch("path", "")
55
- end
56
52
  end
57
53
  end
58
54
  end
@@ -0,0 +1,79 @@
1
+ module CC
2
+ module Analyzer
3
+ class SourceExtractor
4
+ InvalidLocationPositions = Class.new(StandardError)
5
+
6
+ def initialize(source)
7
+ @source = source
8
+ end
9
+
10
+ def extract(location)
11
+ if (lines = location["lines"])
12
+ extract_from_lines(lines)
13
+ elsif (positions = location["positions"])
14
+ extract_from_positions(positions)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :location, :source
21
+
22
+ def extract_from_lines(lines)
23
+ begin_index = lines.fetch("begin") - 1
24
+ end_index = lines.fetch("end") - 1
25
+ range = (begin_index..end_index)
26
+
27
+ source.each_line.with_object("").with_index do |(source_line, memo), index|
28
+ memo << source_line if range.include?(index)
29
+ end
30
+ end
31
+
32
+ def extract_from_positions(positions)
33
+ positions = convert_to_offsets(positions)
34
+ begin_offset = positions.fetch("begin").fetch("offset")
35
+ end_offset = positions.fetch("end").fetch("offset")
36
+ length = end_offset - begin_offset
37
+
38
+ source[begin_offset, length + 1]
39
+ end
40
+
41
+ def convert_to_offsets(positions)
42
+ positions.each do |key, value|
43
+ next if value["offset"]
44
+
45
+ validate_position_format!(value)
46
+
47
+ positions[key] = {
48
+ "offset" => to_offset(value["line"] - 1, value["column"] - 1),
49
+ }
50
+ end
51
+
52
+ positions
53
+ end
54
+
55
+ def validate_position_format!(position)
56
+ unless position.key?("line") && position.key?("column")
57
+ message = "Location positions must have either line/column or offset form"
58
+
59
+ raise InvalidLocationPositions, message
60
+ end
61
+ end
62
+
63
+ def to_offset(line, column, offset = 0)
64
+ source.each_line.with_index do |source_line, index|
65
+ offset +=
66
+ if line == index
67
+ column
68
+ else
69
+ source_line.length
70
+ end
71
+
72
+ break if index >= line
73
+ end
74
+
75
+ offset
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,32 @@
1
+ require "digest/md5"
2
+
3
+ module CC
4
+ module Analyzer
5
+ class SourceFingerprint
6
+ def initialize(issue)
7
+ @issue = issue
8
+ end
9
+
10
+ def compute
11
+ md5 = Digest::MD5.new
12
+ md5 << issue.path
13
+ md5 << issue.check_name.to_s
14
+ md5 << relevant_source.gsub(/\s+/, "") if relevant_source
15
+ md5.hexdigest
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :issue
21
+
22
+ def relevant_source
23
+ source = SourceExtractor.new(raw_source).extract(issue.location)
24
+ source if source && !source.empty?
25
+ end
26
+
27
+ def raw_source
28
+ @raw_source ||= File.read(issue.path)
29
+ end
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codeclimate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.0
4
+ version: 0.27.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code Climate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-18 00:00:00.000000000 Z
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -184,6 +184,8 @@ files:
184
184
  - lib/cc/analyzer/mounted_path.rb
185
185
  - lib/cc/analyzer/raising_container_listener.rb
186
186
  - lib/cc/analyzer/source_buffer.rb
187
+ - lib/cc/analyzer/source_extractor.rb
188
+ - lib/cc/analyzer/source_fingerprint.rb
187
189
  - lib/cc/analyzer/statsd_container_listener.rb
188
190
  - lib/cc/analyzer/validation.rb
189
191
  - lib/cc/cli.rb
@@ -226,9 +228,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
226
228
  version: '0'
227
229
  required_rubygems_version: !ruby/object:Gem::Requirement
228
230
  requirements:
229
- - - ">="
231
+ - - ">"
230
232
  - !ruby/object:Gem::Version
231
- version: '0'
233
+ version: 1.3.1
232
234
  requirements: []
233
235
  rubyforge_project:
234
236
  rubygems_version: 2.4.5