Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 065ee38

Browse files
Only use SexpLines for old parsers
Addresses codeclimate/app#6227.
1 parent 95a6d4e commit 065ee38

File tree

7 files changed

+65
-9
lines changed

7 files changed

+65
-9
lines changed

‎lib/cc/engine/analyzers/analyzer_base.rb‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ def transform_sexp(sexp)
9090
sexp
9191
end
9292

93+
# Please see: codeclimate/app#6227
94+
def use_sexp_lines?
95+
true
96+
end
97+
9398
private
9499

95100
attr_reader :engine_config

‎lib/cc/engine/analyzers/java/main.rb‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class Main < CC::Engine::Analyzers::Base
2020
POINTS_PER_OVERAGE = 10_000
2121
REQUEST_PATH = "/java".freeze
2222

23+
def use_sexp_lines?
24+
false
25+
end
26+
2327
private
2428

2529
def process_file(file)

‎lib/cc/engine/analyzers/javascript/main.rb‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class Main < CC::Engine::Analyzers::Base
2020
POINTS_PER_OVERAGE = 30_000
2121
REQUEST_PATH = "/javascript".freeze
2222

23+
def use_sexp_lines?
24+
false
25+
end
26+
2327
private
2428

2529
def process_file(file)

‎lib/cc/engine/analyzers/php/main.rb‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def transform_sexp(sexp)
2323
delete_comments!(sexp)
2424
end
2525

26+
def use_sexp_lines?
27+
false
28+
end
29+
2630
private
2731

2832
def process_file(file)

‎lib/cc/engine/analyzers/violation.rb‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,24 @@ def format_other_locations
8585
end
8686

8787
def format_sexp(sexp)
88-
lines = SexpLines.new(sexp)
89-
{
90-
"path": sexp.file.gsub(%r{^./}, ""),
91-
"lines": {
92-
"begin": lines.begin_line,
93-
"end": lines.end_line,
94-
},
95-
}
88+
if language_strategy.use_sexp_lines?
89+
lines = SexpLines.new(sexp)
90+
{
91+
"path": sexp.file.gsub(%r{^./}, ""),
92+
"lines": {
93+
"begin": lines.begin_line,
94+
"end": lines.end_line,
95+
},
96+
}
97+
else
98+
{
99+
"path": sexp.file.gsub(%r{^./}, ""),
100+
"lines": {
101+
"begin": sexp.line,
102+
"end": sexp.end_line,
103+
},
104+
}
105+
end
96106
end
97107

98108
def content_body

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,35 @@
172172
expect(issues).to be_empty
173173
end
174174

175+
it "outputs the correct line numbers for ASTs missing line details (codeclimate/app#6227)" do
176+
create_source_file("foo.js", <<~EOJS)
177+
`/movie?${getQueryString({ movie_id: movieId })}`
178+
EOJS
179+
180+
create_source_file("bar.js", <<~EOJS)
181+
var greeting = "hello";
182+
183+
`/movie?${getQueryString({ movie_id: movieId })}`
184+
EOJS
185+
186+
issues = run_engine(engine_conf).strip.split("0円")
187+
expect(issues).to_not be_empty
188+
189+
issues.map! { |issue| JSON.parse(issue) }
190+
191+
foo_issue = issues.detect { |issue| issue.fetch("location").fetch("path") == "foo.js" }
192+
expect(foo_issue["location"]).to eq({
193+
"path" => "foo.js",
194+
"lines" => { "begin" => 1, "end" => 1 },
195+
})
196+
197+
bar_issue = issues.detect { |issue| issue.fetch("location").fetch("path") == "bar.js" }
198+
expect(bar_issue["location"]).to eq({
199+
"path" => "bar.js",
200+
"lines" => { "begin" => 3, "end" => 3 },
201+
})
202+
end
203+
175204
def engine_conf
176205
CC::Engine::Analyzers::EngineConfig.new({
177206
'config' => {

‎spec/cc/engine/analyzers/violations_spec.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module CC::Engine::Analyzers
55
describe "#each" do
66
let(:issue) { double(:issue, mass: 10, identical?: true) }
77
let(:hashes) { sexps }
8-
let(:language_strategy) { double(:language_strategy, calculate_points: 30, calculate_severity: CC::Engine::Analyzers::Base::MINOR) }
8+
let(:language_strategy) { double(:language_strategy, calculate_points: 30, calculate_severity: CC::Engine::Analyzers::Base::MINOR,use_sexp_lines?: true) }
99
let(:violations) { [] }
1010

1111
before do

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /