Class: Rigor::Analysis::Runner
- Inherits:
-
Object
- Object
- Rigor::Analysis::Runner
- Defined in:
- lib/rigor/analysis/runner.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- RUBY_GLOB =
"**/*.rb"- DEFAULT_CACHE_ROOT =
".rigor/cache"
Instance Attribute Summary collapse
-
#cache_store ⇒ Object
readonly
Returns the value of attribute cache_store.
-
#dependency_source_index ⇒ Object
readonly
Returns the value of attribute dependency_source_index.
-
#plugin_registry ⇒ Object
readonly
Returns the value of attribute plugin_registry.
Instance Method Summary collapse
-
#initialize(configuration:, explain: false, cache_store: Cache::Store.new(root: DEFAULT_CACHE_ROOT), plugin_requirer: nil) ⇒ Runner
constructor
A new instance of Runner.
-
#pre_file_diagnostics(expansion) ⇒ Object
Pre-file diagnostic streams that fire once per run rather than per analyzed file: plugin load / prepare envelopes, the ADR-10 dependency-source resolution surface, and the ‘expand_paths` errors for `paths:` entries that don’t exist or aren’t ‘.rb`.
-
#run(paths = @configuration.paths) ⇒ Object
Walks every Ruby file under ‘paths`, parses it, builds a per-node scope index through `Rigor::Inference::ScopeIndexer`, and runs the `Rigor::Analysis::CheckRules` catalogue over it.
-
#validate_target_ruby ⇒ Object
‘target_ruby` flows through to Prism’s ‘version:` option.
Constructor Details
#initialize(configuration:, explain: false, cache_store: Cache::Store.new(root: DEFAULT_CACHE_ROOT), plugin_requirer: nil) ⇒ Runner
Returns a new instance of Runner.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rigor/analysis/runner.rb', line 36 def initialize(configuration:, explain: false, cache_store: Cache::Store.new(root: DEFAULT_CACHE_ROOT), plugin_requirer: nil) @configuration = configuration @explain = explain @cache_store = cache_store @plugin_requirer = plugin_requirer @plugin_registry = Plugin::Registry::EMPTY @dependency_source_index = DependencySourceInference::Index::EMPTY end |
Instance Attribute Details
#cache_store ⇒ Object (readonly)
Returns the value of attribute cache_store.
25 26 27 |
# File 'lib/rigor/analysis/runner.rb', line 25 def cache_store @cache_store end |
#dependency_source_index ⇒ Object (readonly)
Returns the value of attribute dependency_source_index.
25 26 27 |
# File 'lib/rigor/analysis/runner.rb', line 25 def dependency_source_index @dependency_source_index end |
#plugin_registry ⇒ Object (readonly)
Returns the value of attribute plugin_registry.
25 26 27 |
# File 'lib/rigor/analysis/runner.rb', line 25 def plugin_registry @plugin_registry end |
Instance Method Details
#pre_file_diagnostics(expansion) ⇒ Object
Pre-file diagnostic streams that fire once per run rather than per analyzed file: plugin load / prepare envelopes, the ADR-10 dependency-source resolution surface, and the ‘expand_paths` errors for `paths:` entries that don’t exist or aren’t ‘.rb`. Aggregated here so `#run` stays under the ABC budget.
85 86 87 88 89 90 91 92 |
# File 'lib/rigor/analysis/runner.rb', line 85 def pre_file_diagnostics(expansion) plugin_load_diagnostics + plugin_prepare_diagnostics + dependency_source_diagnostics + dependency_source_budget_diagnostics + dependency_source_config_conflict_diagnostics + expansion.fetch(:errors) end |
#run(paths = @configuration.paths) ⇒ Object
Walks every Ruby file under ‘paths`, parses it, builds a per-node scope index through `Rigor::Inference::ScopeIndexer`, and runs the `Rigor::Analysis::CheckRules` catalogue over it. Returns a `Rigor::Analysis::Result` aggregating every produced diagnostic plus any Prism parse errors. The Environment is built once at run start through `Environment.for_project` so all files share the same RBS load.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rigor/analysis/runner.rb', line 55 def run(paths = @configuration.paths) Inference::MethodDispatcher::FileFolding.fold_platform_specific_paths = @configuration.fold_platform_specific_paths target_ruby_error = validate_target_ruby return Result.new(diagnostics: [target_ruby_error]) if target_ruby_error @plugin_registry = load_plugins @dependency_source_index = DependencySourceInference::Builder.build(@configuration.dependencies) environment = Environment.for_project( libraries: @configuration.libraries, signature_paths: @configuration.signature_paths, cache_store: @cache_store, plugin_registry: @plugin_registry, dependency_source_index: @dependency_source_index ) expansion = (paths) diagnostics = pre_file_diagnostics(expansion) diagnostics += expansion.fetch(:files).flat_map { |path| analyze_file(path, environment) } Result.new(diagnostics: apply_severity_profile(diagnostics)) end |
#validate_target_ruby ⇒ Object
‘target_ruby` flows through to Prism’s ‘version:` option. Prism enforces the supported range and raises `ArgumentError` for versions it does not recognise. Run a one-time smoke parse here so a misconfigured target_ruby surfaces as a single project-level diagnostic instead of crashing the whole run on the first file.
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rigor/analysis/runner.rb', line 100 def validate_target_ruby Prism.parse("nil", version: @configuration.target_ruby) nil rescue ArgumentError => e Diagnostic.new( path: ".rigor.yml", line: 1, column: 1, message: "target_ruby #{@configuration.target_ruby.inspect} is not accepted by Prism: #{e.}", severity: :error, rule: "configuration-error", source_family: :builtin ) end |