Class: Homebrew::Style::RubocopOffense

Inherits:
Object
  • Object
show all
Defined in:
brew/Library/Homebrew/style.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ RubocopOffense

Returns a new instance of RubocopOffense



151
152
153
154
155
156
157
# File 'brew/Library/Homebrew/style.rb', line 151

def initialize(json)
  @severity = json["severity"]
  @message = json["message"]
  @cop_name = json["cop_name"]
  @corrected = json["corrected"]
  @location = RubocopLineLocation.new(json["location"])
end

Instance Attribute Details

#cop_nameObject (readonly)

Returns the value of attribute cop_name



149
150
151
# File 'brew/Library/Homebrew/style.rb', line 149

def cop_name
  @cop_name
end

#correctedObject (readonly)

Returns the value of attribute corrected



149
150
151
# File 'brew/Library/Homebrew/style.rb', line 149

def corrected
  @corrected
end

#locationObject (readonly)

Returns the value of attribute location



149
150
151
# File 'brew/Library/Homebrew/style.rb', line 149

def location
  @location
end

#messageObject (readonly)

Returns the value of attribute message



149
150
151
# File 'brew/Library/Homebrew/style.rb', line 149

def message
  @message
end

#severityObject (readonly)

Returns the value of attribute severity



149
150
151
# File 'brew/Library/Homebrew/style.rb', line 149

def severity
  @severity
end

Instance Method Details

#corrected?Boolean

Returns:

  • (Boolean)


163
164
165
# File 'brew/Library/Homebrew/style.rb', line 163

def corrected?
  @corrected
end

#correction_statusObject



167
168
169
# File 'brew/Library/Homebrew/style.rb', line 167

def correction_status
  "[Corrected] " if corrected?
end

#severity_codeObject



159
160
161
# File 'brew/Library/Homebrew/style.rb', line 159

def severity_code
  @severity[0].upcase
end

#to_s(options = {}) ⇒ Object



171
172
173
174
175
176
177
178
# File 'brew/Library/Homebrew/style.rb', line 171

def to_s(options = {})
  if options[:display_cop_name]
    "#{severity_code}: #{location.to_short_s}: #{cop_name}: " \
    "#{Tty.green}#{correction_status}#{Tty.reset}#{message}"
  else
    "#{severity_code}: #{location.to_short_s}: #{Tty.green}#{correction_status}#{Tty.reset}#{message}"
  end
end