Module: Utilits

Defined in:
lib/utilits.rb

Class Method Summary collapse

Class Method Details

.additional_locations_hash(locations) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/utilits.rb', line 30

def additional_locations_hash(locations)
  additional_locations = locations[1..]
  return nil if additional_locations.empty?

  additional_locations.map do
    { path: relative_path(it.pathname.to_s),
      lines: { begin: it.line } }
  end
end

.category(smell) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/utilits.rb', line 17

def category(smell)
  case smell.type.to_s
  when /Complex|TooManyStatements|LongParameterList/
    "Complexity"
  when /Duplicate/
    "Duplication"
  when /Irresponsible|FeatureEnvy|UtilityFunction|Clarity|NilCheck|ControlParameter/
    "Clarity"
  else
    "Clarity" # default to Clarity if not matched, since we filtered out pure style issues
  end
end

.fingerprint(smell, location) ⇒ Object



11
12
13
14
15
# File 'lib/utilits.rb', line 11

def fingerprint(smell, location)
  # Use a stable combination of attributes to generate an MD5 hash
  data = "#{smell.type}|#{smell.context}|#{smell.message}|#{location.pathname}|#{location.line}"
  Digest::MD5.hexdigest(data)
end

.relative_path(file_path) ⇒ Object

Helper to get relative file path (without “./”) from a Pathname or string



6
7
8
9
# File 'lib/utilits.rb', line 6

def relative_path(file_path)
  path = file_path.to_s
  path.sub(%r{^\.\/}, '')
end

.severity(smell) ⇒ Object

Map the smell to a severity level for GitLab (info, minor, major, critical, blocker)



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/utilits.rb', line 41

def severity(smell)
  score = smell.score
  return "info" unless score

  case score
  when 0..9
    "info"
  when 10..29
    "minor"
  when 30..80
    "major"
  else
    "critical"
  end
end