codeclimate 0.63.5 → 0.63.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0910a8c5ed74b148c5a1b5a218e6c200c2b74da
|
4
|
+
data.tar.gz: 6d1908dce5f304cddb4a42c631740b4b3a203b44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2e936686b3f67520cca272dc0ea8a1695132ffbd5608859ad5f883f478b0505af785c248f24f74bb0cbe342daa9c6e29a4f5dbecbd87da79434bbff67d69c5b
|
7
|
+
data.tar.gz: dc35be23df2007e0be97437e9f980be65ddd05a3eb60885fcca2e0c681dab0dde0b283ceb178a2cc41bd1cc6bae0f97188ac6d9a0657f4a944533d2c0ca7ae7f
|
@@ -2,42 +2,69 @@ module CC
|
|
2
2
|
module Analyzer
|
3
3
|
module IssueValidations
|
4
4
|
class LocationFormatValidation < Validation
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
11
|
+
def valid?
|
12
|
+
error.nil?
|
13
|
+
end
|
18
14
|
|
19
|
-
|
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
|
-
|
22
|
-
|
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
|
26
|
-
|
27
|
-
valid_position?(positions["begin"]) &&
|
28
|
-
valid_position?(positions["end"])
|
56
|
+
def valid?
|
57
|
+
validation.valid?
|
29
58
|
end
|
30
59
|
|
31
|
-
def
|
32
|
-
|
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
|
-
|
40
|
-
|
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
|
-
|
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 :
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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.
|
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-
|
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.
|
291
|
+
rubygems_version: 2.6.11
|
292
292
|
signing_key:
|
293
293
|
specification_version: 4
|
294
294
|
summary: Code Climate CLI
|