lib/spoom/sorbet.rb in spoom-1.1.11 vs lib/spoom/sorbet.rb in spoom-1.1.12

- old
+ new

@@ -26,11 +26,11 @@ path: String, capture_err: T::Boolean, sorbet_bin: T.nilable(String) ).returns(ExecResult) end - def srb(*arg, path: '.', capture_err: false, sorbet_bin: nil) + def srb(*arg, path: ".", capture_err: false, sorbet_bin: nil) if sorbet_bin arg.prepend(sorbet_bin) else arg.prepend("bundle", "exec", "srb") end @@ -43,21 +43,21 @@ path: String, capture_err: T::Boolean, sorbet_bin: T.nilable(String) ).returns(ExecResult) end - def srb_tc(*arg, path: '.', capture_err: false, sorbet_bin: nil) + def srb_tc(*arg, path: ".", capture_err: false, sorbet_bin: nil) arg.prepend("tc") unless sorbet_bin srb(*T.unsafe(arg), path: path, capture_err: capture_err, sorbet_bin: sorbet_bin) end # List all files typechecked by Sorbet from its `config` sig { params(config: Config, path: String).returns(T::Array[String]) } - def srb_files(config, path: '.') + def srb_files(config, path: ".") regs = config.ignore.map { |string| Regexp.new(Regexp.escape(string)) } - exts = config.allowed_extensions.empty? ? ['.rb', '.rbi'] : config.allowed_extensions - Dir.glob((Pathname.new(path) / "**/*{#{exts.join(',')}}").to_s).reject do |f| + exts = config.allowed_extensions.empty? ? [".rb", ".rbi"] : config.allowed_extensions + Dir.glob((Pathname.new(path) / "**/*{#{exts.join(",")}}").to_s).reject do |f| regs.any? { |re| re.match?(f) } end.sort end sig do @@ -66,20 +66,21 @@ path: String, capture_err: T::Boolean, sorbet_bin: T.nilable(String) ).returns(T.nilable(String)) end - def srb_version(*arg, path: '.', capture_err: false, sorbet_bin: nil) + def srb_version(*arg, path: ".", capture_err: false, sorbet_bin: nil) result = T.let(T.unsafe(self).srb_tc( "--no-config", "--version", *arg, path: path, capture_err: capture_err, sorbet_bin: sorbet_bin ), ExecResult) return nil unless result.status + result.out.split(" ")[2] end sig do params( @@ -87,11 +88,11 @@ path: String, capture_err: T::Boolean, sorbet_bin: T.nilable(String) ).returns(T.nilable(T::Hash[String, Integer])) end - def srb_metrics(*arg, path: '.', capture_err: false, sorbet_bin: nil) + def srb_metrics(*arg, path: ".", capture_err: false, sorbet_bin: nil) metrics_file = "metrics.tmp" metrics_path = "#{path}/#{metrics_file}" T.unsafe(self).srb_tc( "--metrics-file", metrics_file, @@ -110,14 +111,16 @@ # Get `gem` version from the `Gemfile.lock` content # # Returns `nil` if `gem` cannot be found in the Gemfile. sig { params(gem: String, path: String).returns(T.nilable(String)) } - def version_from_gemfile_lock(gem: 'sorbet', path: '.') + def version_from_gemfile_lock(gem: "sorbet", path: ".") gemfile_path = "#{path}/Gemfile.lock" return nil unless File.exist?(gemfile_path) + content = File.read(gemfile_path).match(/^ #{gem} \(.*(\d+\.\d+\.\d+).*\)/) return nil unless content + content[1] end end end end