Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--fix replacement of Pathname#sub(...) with Pathname#delete_suffix(...) breaks the code #292

Closed
myronmarston opened this issue May 7, 2021 · 1 comment

Comments

@myronmarston
Copy link

myronmarston commented May 7, 2021

Given standardrb_bug.rb:

require "pathname"

path = Pathname.new("path/to/some/ruby/file.rb").sub(/\.rb\z/, "")
puts path

...when I run it, I get the following:

$ ruby standardrb_bug.rb
path/to/some/ruby/file

...but when I run the following:

$ standardrb --version
1.1.1
$ standardrb standardrb_bug.rb --fix

...it changes standardrb_bug.rb like so:

require "pathname"

path = Pathname.new("path/to/some/ruby/file.rb").delete_suffix(".rb")
puts path

...which raises an error when run:

$ ruby standardrb_bug.rb
Traceback (most recent call last):
standardrb_bug.rb:3:in `<main>': undefined method `delete_suffix' for #<Pathname:path/to/some/ruby/file.rb> (NoMethodError)

Pathname objects have a sub method but not a delete_suffix method and it's not safe for standardrb to change it.

@jmkoni
Copy link
Contributor

jmkoni commented May 7, 2021

Huh. Totally agree that we should not be changing it. Now I just need to find the rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants