Skip to content

Commit 4af82cc

Browse files
committed
put reported issue's mass in read up contents
One aspect of the duplication engine that is different from other engines and that can be frustrating is that the main dial you can turn to adjust the results, mass threshold, is a completely invisible value once the issue has been reported to CC (either .com or CLI). As a user, this makes the engine difficult to configure because even though the README documents how to set the mass threshold, the fact that you can't ever see what mass issues have makes the feedback loop between getting results and deciding what your settings should be basically impossible. This is an attempt to remediate this problem by describing generally what mass is, and what its specific value for an issue is, within the read up contents. This makes the value accessible without unduly cluttering the description with that value.
1 parent 4408107 commit 4af82cc

File tree

10 files changed

+41
-27
lines changed

10 files changed

+41
-27
lines changed

config/contents/duplicated_code.md renamed to config/contents/duplicated_code.md.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Duplicated code can lead to software that is hard to understand and difficult to
66

77
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
88

9+
## Issue Mass
10+
11+
Duplicated code has a calculated mass, which can be thought of as a measure of how much logic has been duplicated.
12+
This issue has a mass of `<%= issue.mass %>`: if you would like to change the minimum mass that will be reported as an issue, please see the details in [`codeclimate-duplication`'s documentation](https://github.com/codeclimate/codeclimate-duplication).
13+
914
## Refactorings
1015

1116
* [Extract Method](http://sourcemaking.com/refactoring/extract-method)

lib/cc/engine/analyzers/violation.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "cc/engine/analyzers/sexp_lines"
2+
require "cc/engine/analyzers/violation_read_up"
13
require "digest"
24

35
module CC
@@ -80,14 +82,7 @@ def format_sexp(sexp)
8082
end
8183

8284
def content_body
83-
@_content_body ||= { "body": File.read(read_up_path) }
84-
end
85-
86-
def read_up_path
87-
relative_path = "../../../../config/contents/duplicated_code.md"
88-
File.expand_path(
89-
File.join(File.dirname(__FILE__), relative_path)
90-
)
85+
@_content_body ||= { "body": ViolationReadUp.new(issue).contents }
9186
end
9287

9388
def fingerprint
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require "erb"
2+
3+
module CC
4+
module Engine
5+
module Analyzers
6+
class ViolationReadUp
7+
def initialize(issue)
8+
@issue = issue
9+
end
10+
11+
def contents
12+
ERB.new(File.read(template_path)).result(binding)
13+
end
14+
15+
private
16+
17+
attr_reader :issue
18+
19+
TEMPLATE_REL_PATH = "../../../../config/contents/duplicated_code.md.erb"
20+
21+
def template_path
22+
File.expand_path(
23+
File.join(File.dirname(__FILE__), TEMPLATE_REL_PATH)
24+
)
25+
end
26+
end
27+
end
28+
end
29+
end

lib/cc/engine/duplication.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
require 'cc/engine/analyzers/reporter'
77
require 'cc/engine/analyzers/engine_config'
88
require 'cc/engine/analyzers/sexp'
9-
require 'cc/engine/analyzers/sexp_lines'
109
require 'flay'
1110
require 'json'
1211

spec/cc/engine/analyzers/javascript/main_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
{"path" => "foo.js", "lines" => { "begin" => 2, "end" => 2} },
4242
{"path" => "foo.js", "lines" => { "begin" => 3, "end" => 3} }
4343
])
44-
expect(json["content"]).to eq({ "body" => read_up })
44+
expect(json["content"]["body"]).to match /This issue has a mass of `99`/
4545
expect(json["fingerprint"]).to eq("55ae5d0990647ef496e9e0d315f9727d")
4646
end
4747
end

spec/cc/engine/analyzers/php/main_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
expect(json["other_locations"]).to eq([
5454
{"path" => "foo.php", "lines" => { "begin" => 10, "end" => 14} },
5555
])
56-
expect(json["content"]).to eq({ "body" => read_up })
56+
expect(json["content"]["body"]).to match /This issue has a mass of `44`/
5757
expect(json["fingerprint"]).to eq("667da0e2bab866aa2fe9d014a65d57d9")
5858
end
5959
end

spec/cc/engine/analyzers/python/main_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
{"path" => "foo.py", "lines" => { "begin" => 2, "end" => 2} },
4242
{"path" => "foo.py", "lines" => { "begin" => 3, "end" => 3} }
4343
])
44-
expect(json["content"]).to eq({ "body" => read_up })
44+
expect(json["content"]["body"]).to match /This issue has a mass of `54`/
4545
expect(json["fingerprint"]).to eq("42b832387c997f54a2012efb2159aefc")
4646
end
4747
end

spec/cc/engine/analyzers/ruby/main_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
expect(json["other_locations"]).to eq([
5151
{"path" => "foo.rb", "lines" => { "begin" => 9, "end" => 13} },
5252
])
53-
expect(json["content"]).to eq({ "body" => read_up })
53+
expect(json["content"]["body"]).to match /This issue has a mass of `36`/
5454
expect(json["fingerprint"]).to eq("f21b75bbd135ec3ae6638364d5c73762")
5555
end
5656

spec/spec_helper.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,4 @@
1414

1515
config.order = :random
1616
config.disable_monkey_patching!
17-
18-
config.include ReadUpHelpers
1917
end

spec/support/helpers/read_up_helpers.rb

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)