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 845d72e

Browse files
committed
Fix reporting on non-existent files
We have at least as many bugs as we have regular expressions. We're using this regex to strip path prefixes of `./`. That `.`, of course, will match anything, meaning paths like `_/foo` end up as just `foo`. This bug has been in duplication for 2 years, which is almost impressive.
1 parent c2828db commit 845d72e

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ def format_sexp(sexp)
8888
if language_strategy.use_sexp_lines?
8989
lines = SexpLines.new(sexp)
9090
{
91-
"path": sexp.file.gsub(%r{^./}, ""),
91+
"path": sexp.file.gsub(%r{^\./}, ""),
9292
"lines": {
9393
"begin": lines.begin_line,
9494
"end": lines.end_line,
9595
},
9696
}
9797
else
9898
{
99-
"path": sexp.file.gsub(%r{^./}, ""),
99+
"path": sexp.file.gsub(%r{^\./}, ""),
100100
"lines": {
101101
"begin": sexp.line,
102102
"end": sexp.end_line,
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require "spec_helper"
2+
3+
require "cc/engine/analyzers/violation"
4+
5+
module CC::Engine::Analyzers
6+
RSpec.describe Violation do
7+
describe "#format" do
8+
it "gives the correct path for paths with leading single char dir" do
9+
sexp1 = Sexp.new([:foo, :a]).tap do |s|
10+
s.line = 42
11+
s.file = "_/a.rb"
12+
end
13+
sexp2 = Sexp.new([:foo, :a]).tap do |s|
14+
s.line = 13
15+
s.file = "T/b.rb"
16+
end
17+
engine_config = EngineConfig.new({})
18+
language_strategy = Ruby::Main.new(
19+
engine_config: engine_config,
20+
parse_metrics: nil,
21+
)
22+
issue = described_class.new(
23+
language_strategy: language_strategy,
24+
identical: true,
25+
current_sexp: sexp1,
26+
other_sexps: [sexp2],
27+
).format
28+
29+
expect(issue[:location][:path]).to eq("_/a.rb")
30+
expect(issue[:other_locations][0][:path]).to eq("T/b.rb")
31+
end
32+
end
33+
end
34+
end

0 commit comments

Comments
(0)

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