lib/spoom/context/sorbet.rb in spoom-1.2.0 vs lib/spoom/context/sorbet.rb in spoom-1.2.1

- old
+ new

@@ -59,17 +59,35 @@ remove!(metrics_file) metrics end # List all files typechecked by Sorbet from its `config` - sig { params(with_config: T.nilable(Spoom::Sorbet::Config)).returns(T::Array[String]) } - def srb_files(with_config: nil) + sig { params(with_config: T.nilable(Spoom::Sorbet::Config), include_rbis: T::Boolean).returns(T::Array[String]) } + def srb_files(with_config: nil, include_rbis: true) 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 + + allowed_extensions = config.allowed_extensions + allowed_extensions = Spoom::Sorbet::Config::DEFAULT_ALLOWED_EXTENSIONS if allowed_extensions.empty? + allowed_extensions -= [".rbi"] unless include_rbis + + excluded_patterns = config.ignore.map { |string| File.join("**", string, "**") } + + collector = FileCollector.new(allow_extensions: allowed_extensions, exclude_patterns: excluded_patterns) + collector.visit_paths(config.paths.map { |path| absolute_path_to(path) }) + collector.files.map { |file| file.delete_prefix("#{absolute_path}/") }.sort + end + + # List all files typechecked by Sorbet from its `config` that matches `strictness` + sig do + params( + strictness: String, + with_config: T.nilable(Spoom::Sorbet::Config), + include_rbis: T::Boolean, + ).returns(T::Array[String]) + end + def srb_files_with_strictness(strictness, with_config: nil, include_rbis: true) + srb_files(with_config: with_config, include_rbis: include_rbis) + .select { |file| read_file_strictness(file) == strictness } end sig { params(arg: String, sorbet_bin: T.nilable(String), capture_err: T::Boolean).returns(T.nilable(String)) } 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)