Skip to content

Commit 70de51e

Browse files
committed
Update filename type from String to Pathname
Previously `filename`s were typed as strings, but more accurately they are `Pathname` objects. This commit updates type comments to reflect this
1 parent 16c797e commit 70de51e

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

lib/tapioca/commands/abstract_dsl.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def dsl_rbi_filename(constant_name)
272272
@outpath / "#{underscore(constant_name)}.rbi"
273273
end
274274

275-
#: (tmp_dir: Pathname) -> Hash[String, Symbol]
275+
#: (tmp_dir: Pathname) -> Hash[Pathname, Symbol]
276276
def verify_dsl_rbi(tmp_dir:)
277277
diff = {}
278278

@@ -304,7 +304,7 @@ def verify_dsl_rbi(tmp_dir:)
304304
diff
305305
end
306306

307-
#: (Symbol cause, Array[String] files) -> String
307+
#: (Symbol cause, Array[Pathname] files) -> String
308308
def build_error_for_files(cause, files)
309309
filenames = files.map do |file|
310310
@outpath / file
@@ -313,7 +313,7 @@ def build_error_for_files(cause, files)
313313
" File(s) #{cause}:\n - #{filenames}"
314314
end
315315

316-
#: (Hash[String, Symbol] diff, tmp_dir: Pathname, command: Symbol) -> void
316+
#: (Hash[Pathname, Symbol] diff, tmp_dir: Pathname, command: Symbol) -> void
317317
def report_diff_and_exit_if_out_of_date(diff, tmp_dir:, command:)
318318
if diff.empty?
319319
say("Nothing to do, all RBIs are up-to-date.")
@@ -351,20 +351,19 @@ def report_diff_and_exit_if_out_of_date(diff, tmp_dir:, command:)
351351
ERROR
352352
end
353353

354-
#: (Hash[String, Symbol] diff, Pathname tmp_dir) -> String
354+
#: (Hash[Pathname, Symbol] diff, Pathname tmp_dir) -> String
355355
def build_diff_output(diff, tmp_dir)
356356
out = String.new
357357
line_count = 0
358358

359359
diff.each do |file, status|
360-
filename = file
361360
old_path = (@outpath / file)
362361
new_path = (tmp_dir / file)
363362

364363
chunk = case status
365-
when :added then file_diff(filename, File::NULL, new_path)
366-
when :removed then file_diff(filename, old_path, File::NULL)
367-
when :changed then file_diff(filename, old_path, new_path)
364+
when :added then file_diff(file, File::NULL, new_path)
365+
when :removed then file_diff(file, old_path, File::NULL)
366+
when :changed then file_diff(file, old_path, new_path)
368367
else ""
369368
end
370369

lib/tapioca/helpers/rbi_files_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ def validate_rbi_files(command:, gem_dir:, dsl_dir:, auto_strictness:, gems: [],
139139
Kernel.raise Tapioca::Error, error_messages.join("\n") if parse_errors.any?
140140
end
141141

142-
#: (String filename, Pathname | String old_path, Pathname | String new_path) -> String
142+
#: (Pathname filename, Pathname | String old_path, Pathname | String new_path) -> String
143143
def file_diff(filename, old_path, new_path)
144+
filename = filename.to_s
144145
stdout, stderr, status = Open3.capture3(
145146
"diff",
146147
"-u",

0 commit comments

Comments
 (0)