Skip to content

Commit 8c6f2b7

Browse files
committedNov 18, 2015
Merge pull request #45 from codeclimate/will/mass-in-readup
Put Reported Issue's Mass in Read Up Contents
2 parents bbf627e + 4af82cc commit 8c6f2b7

File tree

11 files changed

+46
-34
lines changed

11 files changed

+46
-34
lines changed
 

‎bin/test

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#!/usr/bin/env ruby
1+
#!/bin/sh
2+
set -ex
23

3-
module_path = File.expand_path('../../node_modules/esprima', __FILE__)
4-
5-
print `npm install esprima` unless File.directory?(module_path)
6-
7-
print `script -q /dev/null bundle exec rake `
4+
docker build -t codeclimate/codeclimate-duplication .
5+
docker run codeclimate/codeclimate-duplication bundle exec rake

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
## Duplicated code
1+
## Duplicated Code
22

33
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
44

55
> Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
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)