Class: Homebrew::DevCmd::Typecheck Private

Inherits:
AbstractCommand show all
Includes:
FileUtils
Defined in:
dev-cmd/typecheck.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/typecheck.rbi

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Defined Under Namespace

Classes: Args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#argsHomebrew::DevCmd::Typecheck::Args

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.



10
# File 'sorbet/rbi/dsl/homebrew/dev_cmd/typecheck.rbi', line 10

def args; end

#runvoid

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.



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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'dev-cmd/typecheck.rb', line 46

def run
  if (args.dir.present? || args.file.present?) && args.named.present?
    raise UsageError, "Cannot use `--dir` or `--file` when specifying a tap."
  elsif args.fix? && args.named.present?
    raise UsageError, "Cannot use `--fix` when specifying a tap."
  end

  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
      workers = args.debug? ? ["--workers=1"] : []
      safe_system "bundle", "exec", "tapioca", "dsl", *workers
      # 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

      if args.suggest_typed?
        ohai "Checking if we can bump Sorbet `typed` sigils..."
        # --sorbet needed because of https://github.com/Shopify/spoom/issues/488
        system "bundle", "exec", "spoom", "srb", "bump", "--from", "false", "--to", "true",
               "--sorbet", "#{Gem.bin_path("sorbet", "srb")} tc"
        system "bundle", "exec", "spoom", "srb", "bump", "--from", "true", "--to", "strict",
               "--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

    if args.lsp?
      srb_exec << "--lsp"
      if (watchman = which("watchman", ORIGINAL_PATHS))
        srb_exec << "--watchman-path" << watchman
      else
        srb_exec << "--disable-watchman"
      end
    end

    srb_exec += ["--ignore", args.ignore] if args.ignore.present?
    if args.file.present? || args.dir.present? || (tap_dir = args.named.to_paths(only: :tap).first).present?
      cd("sorbet") do
        srb_exec += ["--file", "../#{args.file}"] if args.file
        srb_exec += ["--dir", "../#{args.dir}"] if args.dir
        srb_exec += ["--dir", tap_dir.to_s] if tap_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