Skip to content

Commit 15ed918

Browse files
author
ABaldwinHunter
committed
Correctly strip detailed message in fingerprint
A user may elect more detailed messaging in RuboCop output by configuring: AllCops: DisplayCopNames: true DisplayStyleGuide: true ExtraDetails: true which adds a url to issue messages, part of the fingerprint compute. To correctly compute fingerprints in this case, we need an extra strip step.
1 parent cc3a725 commit 15ed918

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

lib/cc/engine/fingerprint.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ class Fingerprint
1212
Metrics/PerceivedComplexity
1313
].freeze
1414

15+
URL_REGEX = / \(https?\:.+\)/
16+
LINES_REGEX = / \[.+\]$/
17+
1518
def initialize(path, cop_name, message)
1619
@path = path
1720
@cop_name = cop_name
@@ -33,7 +36,7 @@ def compute
3336
attr_reader :path, :cop_name, :message
3437

3538
def stripped_message
36-
message.gsub(/ \[.+\]$/, "")
39+
message.gsub(URL_REGEX, "").strip.gsub(LINES_REGEX, "")
3740
end
3841
end
3942
end

spec/cc/engine/fingerprint_spec.rb

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
require "spec_helper"
2+
require "cc/engine/fingerprint"
3+
4+
module CC::Engine
5+
describe Fingerprint do
6+
describe "#compute" do
7+
it "returns a fingerprint for method/class offenses" do
8+
cop_name = "Metrics/ModuleLength"
9+
path = "foo/bar.rb"
10+
message = "foo"
11+
12+
computed = Fingerprint.new(path, cop_name, message).compute
13+
14+
expect(computed).to eq "53a5f182884e58dcb16d24fca37e10bc"
15+
end
16+
17+
it "returns nil for non method/class offenses" do
18+
cop_name = "Style/Foo"
19+
path = "foo/bar.rb"
20+
message = "foo"
21+
22+
computed = Fingerprint.new(path, cop_name, message).compute
23+
24+
expect(computed).not_to be
25+
end
26+
27+
it "computes same fingerprint regardles of message url detail" do
28+
cop_name = "Metrics/ModuleLength"
29+
path = "foo/bar.rb"
30+
31+
plain = "Metrics/MethodLength: Method has too many lines. [18/10]"
32+
verbose = "Metrics/MethodLength: Method has too many lines. [18/10] (https://github.com/bbatsov/ruby-style-guide#short-methods)"
33+
34+
verbose_print = Fingerprint.new(path, cop_name, verbose).compute
35+
plain_print = Fingerprint.new(path, cop_name, plain).compute
36+
37+
expect(verbose_print).to eq plain_print
38+
end
39+
40+
it "computes same fingerprint regardles of line number detail" do
41+
old_count = "Metrics/MethodLength: Method has too many lines. [20/10]"
42+
improved_count = "Metrics/MethodLength: Method has too many lines. [18/10]"
43+
44+
cop_name = "Metrics/ModuleLength"
45+
path = "foo/bar.rb"
46+
47+
old_fingerprint = Fingerprint.new(path, cop_name, old_count).compute
48+
improved_fingerprint = Fingerprint.new(path, cop_name, improved_count).compute
49+
50+
expect(old_fingerprint).to eq improved_fingerprint
51+
end
52+
end
53+
end
54+
end

0 commit comments

Comments
 (0)