Class: Audition::Static::Checks::RuntimeRequire

Inherits:
Base
  • Object
show all
Defined in:
lib/audition/static/checks/runtime_require.rb

Overview

require inside a non-main Ractor works on Ruby 4.0 by proxying the call to the main Ractor; but that serializes every Ractor through a single lock, and it means load-time side effects run mid-request. autoload is the same hazard in disguise: the require fires whenever the constant happens to be resolved first, possibly inside a Ractor.

Constant Summary collapse

REQUIRE_METHODS =
%i[require require_relative load].freeze

Constants inherited from Base

Base::EMPTY_CATALOG, Base::WRAPPER

Instance Attribute Summary

Attributes inherited from Base

#file, #findings

Instance Method Summary collapse

Methods inherited from Base

call, check_name, explain, explanations, handlers, #initialize, on

Constructor Details

This class inherits a constructor from Audition::Static::Checks::Base

Instance Method Details

#visit_begin_node(node) ⇒ Object

A require under a rescue is conditional by construction (optional dependencies, tzinfo's tzinfo-data); hoisting it to an unguarded top-level require breaks every installation without the feature.



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/audition/static/checks/runtime_require.rb', line 66

def visit_begin_node(node)
  if node.rescue_clause
    @rescue_depth = rescue_depth + 1
    begin
      super
    ensure
      @rescue_depth -= 1
    end
  else
    super
  end
end

#visit_def_node(node) ⇒ Object



55
56
57
58
59
60
# File 'lib/audition/static/checks/runtime_require.rb', line 55

def visit_def_node(node)
  @def_depth = def_depth + 1
  super
ensure
  @def_depth -= 1
end

#visit_rescue_modifier_node(node) ⇒ Object



79
80
81
82
83
84
# File 'lib/audition/static/checks/runtime_require.rb', line 79

def visit_rescue_modifier_node(node)
  @rescue_depth = rescue_depth + 1
  super
ensure
  @rescue_depth -= 1
end