Class: Tapioca::Compilers::RuboCop
- Defined in:
- sorbet/tapioca/compilers/rubocop.rb
Constant Summary collapse
- ConstantType =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
This should be a module whose singleton class contains RuboCop::AST::NodePattern::Macros, but I don't know how to express that in Sorbet.
type_member { { fixed: T::Module[T.anything] } }
Class Method Summary collapse
Instance Method Summary collapse
- #decorate ⇒ void private
Class Method Details
.gather_constants ⇒ Enumerable<T::Module[T.anything]>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'sorbet/tapioca/compilers/rubocop.rb', line 14 def self.gather_constants all_modules.select do |klass| next unless klass.singleton_class < ::RuboCop::AST::NodePattern::Macros path = T.must(Object.const_source_location(klass.to_s)).fetch(0).to_s # exclude vendored code, to avoid contradicting their RBI files !path.include?("/vendor/bundle/ruby/") && # exclude source code that already has an RBI file !File.exist?("#{path}i") && # exclude source code that doesn't use the DSLs File.readlines(path).any?(/def_node_/) end end |
Instance Method Details
#decorate ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'sorbet/tapioca/compilers/rubocop.rb', line 29 def decorate root.create_path(constant) do |klass| constant.instance_methods(false).each do |method_name| source_location = constant.instance_method(method_name).source_location next if source_location.nil? source_file, source_line = source_location source = File.readlines(source_file).fetch(source_line - 1).lstrip # For more info on these DSLs: # https://www.rubydoc.info/gems/rubocop-ast/RuboCop/AST/NodePattern/Macros # https://github.com/rubocop/rubocop-ast/blob/HEAD/lib/rubocop/ast/node_pattern.rb # https://github.com/rubocop/rubocop-ast/blob/HEAD/lib/rubocop/ast/node_pattern/method_definer.rb # The type signatures below could maybe be stronger, but I only wanted to avoid errors: case source when /\Adef_node_matcher/ # https://github.com/Shopify/tapioca/blob/3341a9b/lib/tapioca/rbi_ext/model.rb#L89 klass.create_method( method_name.to_s, parameters: [ create_param("node", type: "RuboCop::AST::Node"), create_kw_rest_param("kwargs", type: "T.untyped"), create_block_param("block", type: "T.untyped"), ], return_type: "T.untyped", ) when /\Adef_node_search/ klass.create_method( method_name.to_s, parameters: [ create_param("node", type: "RuboCop::AST::Node"), create_rest_param("pattern", type: "T.any(String, Symbol)"), create_kw_rest_param("kwargs", type: "T.untyped"), create_block_param("block", type: "T.untyped"), ], return_type: method_name.to_s.end_with?("?") ? "T::Boolean" : "T.untyped", ) end end end end |