Class: Model::Diagnostic

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/lsp/model/diagnostic.rb

Constant Summary collapse

DOCS_URLS =
{
  "Bundler":          "https://docs.rubocop.org/rubocop/cops_bundler.html#%{anchor}",
  "Gemspec":          "https://docs.rubocop.org/rubocop/cops_gemspec.html#%{anchor}",
  "Layout":           "https://docs.rubocop.org/rubocop/cops_layout.html#%{anchor}",
  "Lint":             "https://docs.rubocop.org/rubocop/cops_lint.html#%{anchor}",
  "Metrics":          "https://docs.rubocop.org/rubocop/cops_metrics.html#%{anchor}",
  "Migration":        "https://docs.rubocop.org/rubocop/cops_migration.html#%{anchor}",
  "Naming":           "https://docs.rubocop.org/rubocop/cops_naming.html#%{anchor}",
  "Security":         "https://docs.rubocop.org/rubocop/cops_security.html#%{anchor}",
  "Style":            "https://docs.rubocop.org/rubocop/cops_style.html#%{anchor}",
  "Minitest":         "https://docs.rubocop.org/rubocop-minitest/cops_minitest.html#%{anchor}",
  "Performance":      "https://docs.rubocop.org/rubocop-performance/cops_performance.html#%{anchor}",
  "Rails":            "https://docs.rubocop.org/rubocop-rails/cops_rails.html#%{anchor}",
  "RSpec":            "https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#%{anchor}",
  "RSpec/Capybara":   "https://docs.rubocop.org/rubocop-rspec/cops_rspec/capybara.html#%{anchor}",
  "RSpec/FactoryBot": "https://docs.rubocop.org/rubocop-rspec/cops_rspec/factorybot.html#%{anchor}",
  "RSpec/Rails":      "https://docs.rubocop.org/rubocop-rspec/cops_rspec/rails.html#%{anchor}",
  "Sorbet":           "https://github.com/Shopify/rubocop-sorbet/blob/master/manual/cops_sorbet.md#%{anchor}",
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(offense) ⇒ Diagnostic

Returns a new instance of Diagnostic.



27
28
29
30
31
32
33
# File 'lib/rubocop/lsp/model/diagnostic.rb', line 27

def initialize(offense)
  @badge = RuboCop::Cop::Badge.parse(offense.cop_name)
  @message = offense.message
  @start = Interface::Position.new(line: offense.line - 1, character: offense.column)
  @end = Interface::Position.new(line: offense.last_line - 1, character: offense.last_column)
  @replacements = replacements_from_offense(offense)
end

Instance Attribute Details

#badgeObject (readonly)

Returns the value of attribute badge.



5
6
7
# File 'lib/rubocop/lsp/model/diagnostic.rb', line 5

def badge
  @badge
end

#endObject (readonly)

Returns the value of attribute end.



5
6
7
# File 'lib/rubocop/lsp/model/diagnostic.rb', line 5

def end
  @end
end

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'lib/rubocop/lsp/model/diagnostic.rb', line 5

def message
  @message
end

#replacementsObject (readonly)

Returns the value of attribute replacements.



5
6
7
# File 'lib/rubocop/lsp/model/diagnostic.rb', line 5

def replacements
  @replacements
end

#startObject (readonly)

Returns the value of attribute start.



5
6
7
# File 'lib/rubocop/lsp/model/diagnostic.rb', line 5

def start
  @start
end

Instance Method Details

#cop_nameObject



39
40
41
# File 'lib/rubocop/lsp/model/diagnostic.rb', line 39

def cop_name
  @cop_name ||= badge.to_s
end

#correctable?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/rubocop/lsp/model/diagnostic.rb', line 35

def correctable?
  !!@replacements
end

#diagnostic_responseObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rubocop/lsp/model/diagnostic.rb', line 43

def diagnostic_response
  @diagnostic_response ||= Interface::Diagnostic.new(
    message: message,
    "source": "RuboCop",
    code: cop_name,
    code_description: Interface::CodeDescription.new(
      href: doc_url
    ),
    severity: Constant::DiagnosticSeverity::INFORMATION,
    range: Interface::Range.new(
      start: start,
      end: self.end
    )
  )
end