Class: RubyLLM::Toolbox::Tools::Lint

Inherits:
Base
  • Object
show all
Includes:
ToolchainHelpers
Defined in:
lib/ruby_llm/toolbox/tools/lint.rb

Overview

EXEC. Runs RuboCop or Standard over the project at fs_root. Offenses are a normal result, not a tool error. With autocorrect, the linter rewrites files in place (a write effect — hence exec-gated).

Constant Summary collapse

LINTERS =
%w[rubocop standard].freeze

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods included from ToolchainHelpers

#gemfile?, #jail_relative, #run_in_project, #toolchain_output

Methods inherited from Base

#call, exec_tool!, exec_tool?, #initialize, #name

Constructor Details

This class inherits a constructor from RubyLLM::Toolbox::Base

Instance Method Details

#execute(path: nil, linter: nil, autocorrect: false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ruby_llm/toolbox/tools/lint.rb', line 32

def execute(path: nil, linter: nil, autocorrect: false)
  tool = (linter || detect_linter).to_s
  return error("unknown linter: #{tool} (use #{LINTERS.join(', ')})", code: :bad_linter) unless LINTERS.include?(tool)

  rel = jail_relative(path)
  out, err, status = run_in_project(build_args(tool, rel, autocorrect), use_bundle: true)
  toolchain_output(out, err, status,
                   pass_label: "LINT CLEAN",
                   fail_label: autocorrect ? "LINT: offenses found (autocorrected where possible)" : "LINT: offenses found")
rescue Safety::PathJail::Jailbreak => e
  error(e.message, code: :path_denied)
rescue CommandMissing => e
  error("#{e.message} is not available (is it in the bundle / installed?)", code: :unavailable)
end