Module: Spoom::Context::Sorbet
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/spoom/context/sorbet.rb
Overview
Sorbet features for a context
Instance Method Summary collapse
- #has_sorbet_config? ⇒ Boolean
- #read_file_strictness(relative_path) ⇒ Object
- #read_sorbet_config ⇒ Object
- #sorbet_config ⇒ Object
- #sorbet_intro_commit ⇒ Object
- #sorbet_removal_commit ⇒ Object
- #srb(*arg, sorbet_bin: nil, capture_err: true) ⇒ Object
- #srb_files(with_config: nil) ⇒ Object
- #srb_metrics(*arg, sorbet_bin: nil, capture_err: true) ⇒ Object
- #srb_tc(*arg, sorbet_bin: nil, capture_err: true) ⇒ Object
- #srb_version(*arg, sorbet_bin: nil, capture_err: true) ⇒ Object
- #write_sorbet_config!(contents, append: false) ⇒ Object
Instance Method Details
#has_sorbet_config? ⇒ Boolean
84 85 86 |
# File 'lib/spoom/context/sorbet.rb', line 84 def has_sorbet_config? file?(Spoom::Sorbet::CONFIG_PATH) end |
#read_file_strictness(relative_path) ⇒ Object
107 108 109 |
# File 'lib/spoom/context/sorbet.rb', line 107 def read_file_strictness(relative_path) Spoom::Sorbet::Sigils.file_strictness(absolute_path_to(relative_path)) end |
#read_sorbet_config ⇒ Object
95 96 97 |
# File 'lib/spoom/context/sorbet.rb', line 95 def read_sorbet_config read(Spoom::Sorbet::CONFIG_PATH) end |
#sorbet_config ⇒ Object
89 90 91 |
# File 'lib/spoom/context/sorbet.rb', line 89 def sorbet_config Spoom::Sorbet::Config.parse_string(read_sorbet_config) end |
#sorbet_intro_commit ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/spoom/context/sorbet.rb', line 113 def sorbet_intro_commit res = git_log("--diff-filter=A --format='%h %at' -1 -- sorbet/config") return nil unless res.status out = res.out.strip return nil if out.empty? Spoom::Git::Commit.parse_line(out) end |
#sorbet_removal_commit ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/spoom/context/sorbet.rb', line 125 def sorbet_removal_commit res = git_log("--diff-filter=D --format='%h %at' -1 -- sorbet/config") return nil unless res.status out = res.out.strip return nil if out.empty? Spoom::Git::Commit.parse_line(out) end |
#srb(*arg, sorbet_bin: nil, capture_err: true) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/spoom/context/sorbet.rb', line 15 def srb(*arg, sorbet_bin: nil, capture_err: true) res = if sorbet_bin exec("#{sorbet_bin} #{arg.join(" ")}", capture_err: capture_err) else bundle_exec("srb #{arg.join(" ")}", capture_err: capture_err) end case res.exit_code when Spoom::Sorbet::KILLED_CODE raise Spoom::Sorbet::Error::Killed.new("Sorbet was killed.", res) when Spoom::Sorbet::SEGFAULT_CODE raise Spoom::Sorbet::Error::Segfault.new("Sorbet segfaulted.", res) end res end |
#srb_files(with_config: nil) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/spoom/context/sorbet.rb', line 65 def srb_files(with_config: nil) config = with_config || sorbet_config regs = config.ignore.map { |string| Regexp.new(Regexp.escape(string)) } exts = config.allowed_extensions.empty? ? [".rb", ".rbi"] : config.allowed_extensions glob("**/*{#{exts.join(",")}}").reject do |f| regs.any? { |re| re.match?(f) } end.sort end |
#srb_metrics(*arg, sorbet_bin: nil, capture_err: true) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/spoom/context/sorbet.rb', line 45 def srb_metrics(*arg, sorbet_bin: nil, capture_err: true) metrics_file = "metrics.tmp" T.unsafe(self).srb_tc( "--metrics-file", metrics_file, *arg, sorbet_bin: sorbet_bin, capture_err: capture_err, ) return nil unless file?(metrics_file) metrics_path = absolute_path_to(metrics_file) metrics = Spoom::Sorbet::MetricsParser.parse_file(metrics_path) remove!(metrics_file) metrics end |
#srb_tc(*arg, sorbet_bin: nil, capture_err: true) ⇒ Object
33 34 35 36 |
# File 'lib/spoom/context/sorbet.rb', line 33 def srb_tc(*arg, sorbet_bin: nil, capture_err: true) arg.prepend("tc") unless sorbet_bin T.unsafe(self).srb(*arg, sorbet_bin: sorbet_bin, capture_err: capture_err) end |
#srb_version(*arg, sorbet_bin: nil, capture_err: true) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/spoom/context/sorbet.rb', line 75 def srb_version(*arg, sorbet_bin: nil, capture_err: true) res = T.unsafe(self).srb_tc("--no-config", "--version", *arg, sorbet_bin: sorbet_bin, capture_err: capture_err) return nil unless res.status res.out.split(" ")[2] end |
#write_sorbet_config!(contents, append: false) ⇒ Object
101 102 103 |
# File 'lib/spoom/context/sorbet.rb', line 101 def write_sorbet_config!(contents, append: false) write!(Spoom::Sorbet::CONFIG_PATH, contents, append: append) end |