fables-tales/rubyfmt

Rubyfmt ignores files without the .rb extension (for example `.rake` files)

Closed this issue · 3 comments

  • Ruby version: 2.7.0p0
  • Rubyfmt git sha: 266b47b (0.8.1)

Input file

desc "Do thing"
task :do_thing do
  puts "Doing things"
end

Rubyfmt's output

rubyfmt -i task.rake

[DEBUG] (1) rubyfmt: logger works

This breaks because

rubyfmt ignores the file because it has a .rake extension, even when prompted to format it explicitly.
Renaming the file to task.rb works around the issue.

I believe this is

rubyfmt/src/main.rs

Lines 302 to 303 in 9a24d92

if file_path.is_file()
&& file_path.extension().and_then(OsStr::to_str) == Some("rb")

See also #189 & #210

To me there are two related but slightly different issues:

  • rubyfmt picking up files by default when running on a directory − we can discuss whether it should pick more than .rb (as #210 did) but I think it’s a sensible default
  • rubyfmt refusing to format my task.rake file even though I specifically invoke rubyfmt -i task.rake
reese commented

Yeah, IMO the most sensible fix for this is that if the path passed in is a file path, always format it regardless of the file extension. I think adding support for other file extensions isn't unreasonable, but it also becomes somewhat unnecessary once rubyfmt lets you pass in arbitrary file paths to format.

I probably won't get to this in the near term, but PRs are welcome if anyone wants to pick it up!

Thank you @reese! Looking forward to a release shipping this :)

I think adding support for other file extensions isn't unreasonable, but it also becomes somewhat unnecessary once rubyfmt lets you pass in arbitrary file paths to format.

Well, there is still something nice about letting rubyfmt go wild on the root of a repo and having it format everything Ruby-like. #189 links to the very extensive Rubocop include list (https://github.com/rubocop/rubocop/blob/master/config/default.yml#L11) which might be a bit too much, but there might be a sane middleground.

(Meanwhile, I guess I can invoke rubyfmt via a Shell script which finds all the files i care about and pass them to rubyfmt)

Expecting to see a release with this fix. Maybe it's time to ship a new release since it has been 5 months since last release. @reese