Class: Homebrew::DevCmd::Typecheck

Inherits:
AbstractCommand show all
Includes:
FileUtils
Defined in:
dev-cmd/typecheck.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, #initialize, parser

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#runvoid

This method returns an undefined value.



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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'dev-cmd/typecheck.rb', line 41

def run
  update = args.update? || args.update_all?
  groups = update ? Homebrew.valid_gem_groups : ["typecheck"]
  Homebrew.install_bundler_gems!(groups:)

  # Sorbet doesn't use bash privileged mode so we align EUID and UID here.
  Process::UID.change_privilege(Process.euid) if Process.euid != Process.uid

  HOMEBREW_LIBRARY_PATH.cd do
    if update
      safe_system "bundle", "exec", "tapioca", "dsl"
      # Prefer adding args here: Library/Homebrew/sorbet/tapioca/config.yml
      tapioca_args = args.update_all? ? ["--all"] : []

      ohai "Updating Tapioca RBI files..."
      safe_system "bundle", "exec", "tapioca", "gem", *tapioca_args
      safe_system "bundle", "exec", "parlour"

      if args.suggest_typed?
        ohai "Bumping Sorbet `typed` sigils..."
        # --sorbet needed because of https://github.com/Shopify/spoom/issues/488
        safe_system "bundle", "exec", "spoom", "srb", "bump", "--dry", "--sorbet",
                    "#{Gem.bin_path("sorbet", "srb")} tc"
      end

      return
    end

    srb_exec = %w[bundle exec srb tc]

    srb_exec << "--quiet" if args.quiet?

    if args.fix?
      # Auto-correcting method names is almost always wrong.
      srb_exec << "--suppress-error-code" << "7003"

      srb_exec << "--autocorrect"
    end

    srb_exec += ["--ignore", args.ignore] if args.ignore.present?
    if args.file.present? || args.dir.present?
      cd("sorbet") do
        srb_exec += ["--file", "../#{args.file}"] if args.file
        srb_exec += ["--dir", "../#{args.dir}"] if args.dir
      end
    end
    success = system(*srb_exec)
    return if success

    $stderr.puts "Check #{Formatter.url("https://docs.brew.sh/Typechecking")} for " \
                 "more information on how to resolve these errors."
    Homebrew.failed = true
  end
end