Skip to content

Commit 53d93f6

Browse files
author
Ashley Baldwin-Hunter
committed
Merge pull request #91 from codeclimate/abh-revert-erb-files
Revert "Include erb files for analysis, following Flay"
2 parents 3ec765e + ea8a3f0 commit 53d93f6

File tree

6 files changed

+2
-78
lines changed

6 files changed

+2
-78
lines changed

.codeclimate.yml

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ engines:
88
enabled: true
99
duplication:
1010
enabled: true
11-
exclude_fingerprints:
12-
- b2dc8dbd27916d8321e298f59fc2f431 # Erubis < ::Erubis::Eruby
1311
config:
1412
languages:
1513
- ruby

Gemfile

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
source 'https://rubygems.org'
22

3-
gem 'erubis'
43
gem 'flay', git: 'https://github.com/codeclimate/flay.git'
54
gem 'concurrent-ruby', "~> 1.0.0"
65
gem 'ruby_parser'

Gemfile.lock

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ GEM
1010
coderay (1.1.0)
1111
concurrent-ruby (1.0.0)
1212
diff-lcs (1.2.5)
13-
erubis (2.7.0)
1413
json (1.8.3)
1514
method_source (0.8.2)
1615
pry (0.10.3)
@@ -41,7 +40,6 @@ PLATFORMS
4140

4241
DEPENDENCIES
4342
concurrent-ruby (~> 1.0.0)
44-
erubis
4543
flay!
4644
json
4745
pry

lib/cc/engine/analyzers/ruby/main.rb

+2-33
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
require "erubis"
21
require "flay"
32
require "json"
43
require "cc/engine/analyzers/reporter"
@@ -11,12 +10,12 @@ module Ruby
1110
class Main < CC::Engine::Analyzers::Base
1211
LANGUAGE = "ruby"
1312
DEFAULT_PATHS = [
14-
"**/*.erb",
1513
"**/*.rb",
1614
"**/*.rake",
1715
"**/Rakefile",
1816
"**/Gemfile",
1917
"**/*.gemspec"
18+
2019
]
2120
DEFAULT_MASS_THRESHOLD = 18
2221
BASE_POINTS = 1_500_000
@@ -34,37 +33,7 @@ def overage(mass)
3433
end
3534

3635
def process_file(file)
37-
if File.extname(file) == ".erb"
38-
process_erb file
39-
else
40-
RubyParser.new.process(File.binread(file), file, TIMEOUT)
41-
end
42-
end
43-
44-
def process_erb(file)
45-
erb = File.binread(file)
46-
ruby = Erubis.new(erb).src
47-
RubyParser.new.process(ruby, file)
48-
end
49-
50-
class Erubis < ::Erubis::Eruby
51-
BLOCK_EXPR = /\s+(do|\{)(\s*\|[^|]*\|)?\s*\Z/
52-
53-
def add_expr_literal(src, code)
54-
if code =~ BLOCK_EXPR
55-
src << "@output_buffer.append= " << code
56-
else
57-
src << "@output_buffer.append=(" << code << ");"
58-
end
59-
end
60-
61-
def add_expr_escaped(src, code)
62-
if code =~ BLOCK_EXPR
63-
src << "@output_buffer.safe_append= " << code
64-
else
65-
src << "@output_buffer.safe_append=(" << code << ");"
66-
end
67-
end
36+
RubyParser.new.process(File.binread(file), file, TIMEOUT)
6837
end
6938
end
7039
end

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

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require 'cc/engine/analyzers/reporter'
44
require 'cc/engine/analyzers/engine_config'
55
require 'cc/engine/analyzers/file_list'
6-
require 'erubis'
76

87
RSpec.describe CC::Engine::Analyzers::Javascript::Main, in_tmpdir: true do
98
include AnalyzerSpecHelpers

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

-39
Original file line numberDiff line numberDiff line change
@@ -88,45 +88,6 @@ module CC::Engine::Analyzers
8888
expect(run_engine(engine_conf)).to eq("")
8989
}.to output(/Skipping file/).to_stderr
9090
end
91-
92-
it "analyzes erb files" do
93-
create_source_file("recipe.erb", <<-EOERB)
94-
<div class="container">
95-
<h1>Select a Category</h1>
96-
<ul>
97-
<%categories.each do |category| %>
98-
<li> <a href= "/category/<%=category.id%>"><%=category.name%> | <%=category.recipes.count%> Recipes </a></li>
99-
<%end%>
100-
101-
<%categories.each do |category| %>
102-
<li> <a href= "/category/<%=category.id%>"><%=category.name%> | <%=category.recipes.count%> Recipes </a></li>
103-
<%end%>
104-
105-
<%categories.each do |category| %>
106-
<li> <a href= "/category/<%=category.id%>"><%=category.name%> | <%=category.recipes.count%> Recipes </a></li>
107-
<%end%>
108-
</ul>
109-
</div>
110-
EOERB
111-
112-
issues = run_engine(engine_conf).strip.split("\0")
113-
result = issues.first.strip
114-
json = JSON.parse(result)
115-
116-
expect(json["type"]).to eq("issue")
117-
expect(json["check_name"]).to eq("Similar code")
118-
expect(json["description"]).to eq("Similar code found in 2 other locations (mass = 30)")
119-
expect(json["categories"]).to eq(["Duplication"])
120-
expect(json["location"]).to eq({
121-
"path" => "recipe.erb",
122-
"lines" => { "begin" => 4, "end" => 5 },
123-
})
124-
expect(json["remediation_points"]).to eq(2_700_000)
125-
expect(json["other_locations"]).to eq([
126-
{"path" => "recipe.erb", "lines" => { "begin" => 8, "end" => 9} },
127-
{"path" => "recipe.erb", "lines" => { "begin" => 12, "end" => 13} }
128-
])
129-
end
13091
end
13192

13293
describe "#calculate_points(mass)" do

0 commit comments

Comments
 (0)