codeclimate 0.63.5 → 0.63.6

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: 11dfd2b77e1b00acf30d6ad1299abfa96e7d2d8e
4
- data.tar.gz: a9be19297272feb11bcc44200ce35c0f940cd746
3
+ metadata.gz: a0910a8c5ed74b148c5a1b5a218e6c200c2b74da
4
+ data.tar.gz: 6d1908dce5f304cddb4a42c631740b4b3a203b44
5
5
  SHA512:
6
- metadata.gz: 5df2636a2cbf2ebbeaa5459b4bca139ca94a2e06d0f6a802cbb10f790b436cf82ba40fc690de3435c32660ea90242699c3cc5e0f7a09c52e63764d7ee4e7e7df
7
- data.tar.gz: 0ad116622093f5f77bb5d9e369179fc970ebdb3d979b237c0f966b657795bb4fea458cd07436e5f10c2ca0ccf53f0f214889adfffc489a3f821b0b6ebf6e13ab
6
+ metadata.gz: f2e936686b3f67520cca272dc0ea8a1695132ffbd5608859ad5f883f478b0505af785c248f24f74bb0cbe342daa9c6e29a4f5dbecbd87da79434bbff67d69c5b
7
+ data.tar.gz: dc35be23df2007e0be97437e9f980be65ddd05a3eb60885fcca2e0c681dab0dde0b283ceb178a2cc41bd1cc6bae0f97188ac6d9a0657f4a944533d2c0ca7ae7f
@@ -23,6 +23,8 @@ module CC
23
23
 
24
24
  def ignore_fingerprint?(issue)
25
25
  @config.fetch("exclude_fingerprints", []).include?(issue.fingerprint)
26
+ rescue SourceExtractor::InvalidLocation
27
+ false
26
28
  end
27
29
 
28
30
  def check_config(check_name)
@@ -2,42 +2,69 @@ module CC
2
2
  module Analyzer
3
3
  module IssueValidations
4
4
  class LocationFormatValidation < Validation
5
- def valid?
6
- if location["lines"]
7
- valid_lines?(location["lines"])
8
- elsif location["positions"]
9
- valid_positions?(location["positions"])
10
- else
11
- false
5
+ class Validator
6
+ def initialize(location)
7
+ @location = location
8
+ check_validity
12
9
  end
13
- end
14
10
 
15
- def message
16
- "Location is not formatted correctly"
17
- end
11
+ def valid?
12
+ error.nil?
13
+ end
18
14
 
19
- private
15
+ def message
16
+ if error
17
+ "Location is not formatted correctly: #{error}"
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ attr_accessor :error
20
24
 
21
- def location
22
- @location ||= object.fetch("location", {})
25
+ attr_reader :location
26
+
27
+ def check_validity
28
+ if location["lines"]
29
+ self.error = "location.lines is not valid: #{JSON.dump(location["lines"])}" unless valid_lines?(location["lines"])
30
+ elsif location["positions"]
31
+ self.error = "location.positions is not valid: #{JSON.dump(location["positions"])}" unless valid_positions?(location["positions"])
32
+ else
33
+ self.error = "location.lines or location.positions must be present"
34
+ end
35
+ end
36
+
37
+ def valid_positions?(positions)
38
+ positions.is_a?(Hash) &&
39
+ valid_position?(positions["begin"]) &&
40
+ valid_position?(positions["end"])
41
+ end
42
+
43
+ def valid_position?(position)
44
+ position &&
45
+ (
46
+ [position["line"], position["column"]].all? { |value| value.is_a?(Integer) } ||
47
+ position["offset"].is_a?(Integer)
48
+ )
49
+ end
50
+
51
+ def valid_lines?(lines)
52
+ lines.is_a?(Hash) && [lines["begin"], lines["end"]].all? { |value| value.is_a?(Integer) }
53
+ end
23
54
  end
24
55
 
25
- def valid_positions?(positions)
26
- positions.is_a?(Hash) &&
27
- valid_position?(positions["begin"]) &&
28
- valid_position?(positions["end"])
56
+ def valid?
57
+ validation.valid?
29
58
  end
30
59
 
31
- def valid_position?(position)
32
- position &&
33
- (
34
- [position["line"], position["column"]].all? { |value| value.is_a?(Integer) } ||
35
- position["offset"].is_a?(Integer)
36
- )
60
+ def message
61
+ validation.message
37
62
  end
38
63
 
39
- def valid_lines?(lines)
40
- lines.is_a?(Hash) && [lines["begin"], lines["end"]].all? { |value| value.is_a?(Integer) }
64
+ private
65
+
66
+ def validation
67
+ @validation ||= Validator.new(object.fetch("location", {}))
41
68
  end
42
69
  end
43
70
  end
@@ -1,13 +1,15 @@
1
1
  module CC
2
2
  module Analyzer
3
3
  class SourceExtractor
4
- InvalidLocationPositions = Class.new(StandardError)
4
+ InvalidLocation = Class.new(StandardError)
5
5
 
6
6
  def initialize(source)
7
7
  @source = source
8
8
  end
9
9
 
10
10
  def extract(location)
11
+ validate_location(location)
12
+
11
13
  if (lines = location["lines"])
12
14
  extract_from_lines(lines)
13
15
  elsif (positions = location["positions"])
@@ -17,7 +19,14 @@ module CC
17
19
 
18
20
  private
19
21
 
20
- attr_reader :location, :source
22
+ attr_reader :source
23
+
24
+ def validate_location(location)
25
+ validator = IssueValidations::LocationFormatValidation::Validator.new(location)
26
+ unless validator.valid?
27
+ raise InvalidLocation, validator.message
28
+ end
29
+ end
21
30
 
22
31
  def extract_from_lines(lines)
23
32
  begin_index = lines.fetch("begin") - 1
@@ -40,23 +49,14 @@ module CC
40
49
 
41
50
  def convert_to_offsets(positions)
42
51
  positions.each_with_object({}) do |(key, value), memo|
43
- if value.key?("offset")
44
- memo[key] = value
45
- else
46
- validate_position_format!(value)
47
-
48
- memo[key] = {
49
- "offset" => to_offset(value["line"] - 1, value["column"] - 1),
50
- }
51
- end
52
- end
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
52
+ memo[key] =
53
+ if value.key?("offset")
54
+ value
55
+ else
56
+ {
57
+ "offset" => to_offset(value["line"] - 1, value["column"] - 1),
58
+ }
59
+ end
60
60
  end
61
61
  end
62
62
 
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.63.5
4
+ version: 0.63.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code Climate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-15 00:00:00.000000000 Z
11
+ date: 2017-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -288,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
288
288
  version: '0'
289
289
  requirements: []
290
290
  rubyforge_project:
291
- rubygems_version: 2.6.8
291
+ rubygems_version: 2.6.11
292
292
  signing_key:
293
293
  specification_version: 4
294
294
  summary: Code Climate CLI