Skip to content

Commit a73ecde

Browse files
committed
CC issues
1 parent 75af4cd commit a73ecde

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

.codeclimate.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
engines:
22
rubocop:
33
enabled: true
4+
exclude_fingerprints:
5+
# Ignoring long method length for Issue#to_json
6+
- 3d618821b1ce28599d6c54f90bb4df59
47
ratings:
58
paths:
69
- "**.rb"

.rubocop.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
AllCops:
2+
TargetRubyVersion: 2.2
13
Metrics/AbcSize:
24
Enabled: false
35

@@ -16,7 +18,7 @@ Style/StringLiterals:
1618
Style/Documentation:
1719
Enabled: false
1820

19-
Style/TrailingComma:
21+
Style/TrailingCommaInLiteral:
2022
Enabled: false
2123

2224
Style/ClassAndModuleChildren:

lib/cc/engine/bundler_audit/analyzer.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,3 @@ def gemfile_lock_path
4242
end
4343
end
4444
end
45-

lib/cc/engine/bundler_audit/issue.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ module CC
22
module Engine
33
module BundlerAudit
44
class Issue
5-
GEM_REGEX = /^\s*(?<name>\S+) \([\d.]+\)/.freeze
5+
GEM_REGEX = /^\s*(?<name>\S+) \([\d.]+\)/
66
SEVERITIES = {
77
high: "critical",
88
medium: "normal",
9-
low: "info",
9+
low: "info"
1010
}.freeze
1111

1212
def initialize(result, gemfile_lock_lines)
@@ -17,7 +17,7 @@ def initialize(result, gemfile_lock_lines)
1717

1818
def to_json(*a)
1919
{
20-
categories: ["Security"],
20+
categories: %w[Security],
2121
check_name: "Insecure Dependency",
2222
content: {
2323
body: content_body
@@ -32,7 +32,7 @@ def to_json(*a)
3232
},
3333
remediation_points: remediation_points,
3434
severity: severity,
35-
type: "Issue",
35+
type: "Issue"
3636
}.to_json(a)
3737
end
3838

@@ -45,15 +45,15 @@ def content_body
4545
"**Advisory**: #{identifier}",
4646
"**Criticality**: #{advisory.criticality.capitalize}",
4747
"**URL**: #{advisory.url}",
48-
"**Solution**: #{solution}",
48+
"**Solution**: #{solution}"
4949
].join("\n\n")
5050
end
5151

5252
def line_number
5353
@line_number ||= begin
54-
gemfile_lock_lines.find_index do |line|
55-
(match = GEM_REGEX.match(line)) && match[:name] == gem.name
56-
end + 1
54+
gemfile_lock_lines.find_index do |line|
55+
(match = GEM_REGEX.match(line)) && match[:name] == gem.name
56+
end + 1
5757
end
5858
end
5959

lib/cc/engine/bundler_audit/remediation.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,14 @@ class Remediation
77
PATCH_UPGRADE_POINTS = 500_000
88
UNPATCHED_VERSION_POINTS = 500_000_000
99

10-
1110
def initialize(gem_version, patched_versions)
1211
@gem_version = gem_version
1312
@patched_versions = patched_versions
1413
end
1514

1615
def points
1716
if upgrade_versions.any?
18-
upgrade_versions.map do |upgrade_version|
19-
case
20-
when current_version.major != upgrade_version.major
21-
MAJOR_UPGRADE_POINTS
22-
when current_version.minor != upgrade_version.minor
23-
MINOR_UPGRADE_POINTS
24-
when current_version.tiny != upgrade_version.tiny
25-
PATCH_UPGRADE_POINTS
26-
end
27-
end.min
17+
upgrade_versions.map { |version| calculate_points(version) }.min
2818
else
2919
UNPATCHED_VERSION_POINTS
3020
end
@@ -34,6 +24,17 @@ def points
3424

3525
attr_reader :gem_version, :patched_versions
3626

27+
def calculate_points(upgrade_version)
28+
case
29+
when current_version.major != upgrade_version.major
30+
MAJOR_UPGRADE_POINTS
31+
when current_version.minor != upgrade_version.minor
32+
MINOR_UPGRADE_POINTS
33+
when current_version.tiny != upgrade_version.tiny
34+
PATCH_UPGRADE_POINTS
35+
end
36+
end
37+
3738
def current_version
3839
@current_version ||= Versionomy.parse(gem_version.to_s)
3940
end

0 commit comments

Comments
 (0)