Skip to content

Put Reported Issue's Mass in Read Up Contents #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions bin/test
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env ruby
#!/bin/sh
set -ex

module_path = File.expand_path('../../node_modules/esprima', __FILE__)

print `npm install esprima` unless File.directory?(module_path)

print `script -q /dev/null bundle exec rake `
docker build -t codeclimate/codeclimate-duplication .
docker run codeclimate/codeclimate-duplication bundle exec rake
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
## Duplicated code
## Duplicated Code

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

> Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

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).

## Issue Mass

Duplicated code has a calculated mass, which can be thought of as a measure of how much logic has been duplicated.
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).

## Refactorings

* [Extract Method](http://sourcemaking.com/refactoring/extract-method)
Expand Down
11 changes: 3 additions & 8 deletions lib/cc/engine/analyzers/violation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "cc/engine/analyzers/sexp_lines"
require "cc/engine/analyzers/violation_read_up"
require "digest"

module CC
Expand Down Expand Up @@ -80,14 +82,7 @@ def format_sexp(sexp)
end

def content_body
@_content_body ||= { "body": File.read(read_up_path) }
end

def read_up_path
relative_path = "../../../../config/contents/duplicated_code.md"
File.expand_path(
File.join(File.dirname(__FILE__), relative_path)
)
@_content_body ||= { "body": ViolationReadUp.new(issue).contents }
end

def fingerprint
Expand Down
29 changes: 29 additions & 0 deletions lib/cc/engine/analyzers/violation_read_up.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require "erb"

module CC
module Engine
module Analyzers
class ViolationReadUp
def initialize(issue)
@issue = issue
end

def contents
ERB.new(File.read(template_path)).result(binding)
end

private

attr_reader :issue

TEMPLATE_REL_PATH = "../../../../config/contents/duplicated_code.md.erb"

def template_path
File.expand_path(
File.join(File.dirname(__FILE__), TEMPLATE_REL_PATH)
)
end
end
end
end
end
1 change: 0 additions & 1 deletion lib/cc/engine/duplication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
require 'cc/engine/analyzers/reporter'
require 'cc/engine/analyzers/engine_config'
require 'cc/engine/analyzers/sexp'
require 'cc/engine/analyzers/sexp_lines'
require 'flay'
require 'json'

Expand Down
2 changes: 1 addition & 1 deletion spec/cc/engine/analyzers/javascript/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{"path" => "foo.js", "lines" => { "begin" => 2, "end" => 2} },
{"path" => "foo.js", "lines" => { "begin" => 3, "end" => 3} }
])
expect(json["content"]).to eq({ "body" => read_up })
expect(json["content"]["body"]).to match /This issue has a mass of `99`/
expect(json["fingerprint"]).to eq("55ae5d0990647ef496e9e0d315f9727d")
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/cc/engine/analyzers/php/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
expect(json["other_locations"]).to eq([
{"path" => "foo.php", "lines" => { "begin" => 10, "end" => 14} },
])
expect(json["content"]).to eq({ "body" => read_up })
expect(json["content"]["body"]).to match /This issue has a mass of `44`/
expect(json["fingerprint"]).to eq("667da0e2bab866aa2fe9d014a65d57d9")
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/cc/engine/analyzers/python/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{"path" => "foo.py", "lines" => { "begin" => 2, "end" => 2} },
{"path" => "foo.py", "lines" => { "begin" => 3, "end" => 3} }
])
expect(json["content"]).to eq({ "body" => read_up })
expect(json["content"]["body"]).to match /This issue has a mass of `54`/
expect(json["fingerprint"]).to eq("42b832387c997f54a2012efb2159aefc")
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/cc/engine/analyzers/ruby/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
expect(json["other_locations"]).to eq([
{"path" => "foo.rb", "lines" => { "begin" => 9, "end" => 13} },
])
expect(json["content"]).to eq({ "body" => read_up })
expect(json["content"]["body"]).to match /This issue has a mass of `36`/
expect(json["fingerprint"]).to eq("f21b75bbd135ec3ae6638364d5c73762")
end

Expand Down
2 changes: 0 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@

config.order = :random
config.disable_monkey_patching!

config.include ReadUpHelpers
end
12 changes: 0 additions & 12 deletions spec/support/helpers/read_up_helpers.rb

This file was deleted.