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

`Style/EvalWithLocation` could auto-correct #9403

Closed
marcandre opened this issue Jan 22, 2021 · 5 comments
Closed

`Style/EvalWithLocation` could auto-correct #9403

marcandre opened this issue Jan 22, 2021 · 5 comments

Comments

@marcandre
Copy link
Contributor

@marcandre marcandre commented Jan 22, 2021

The cop Style/EvalWithLocation could autocorrect:

example.class_eval <<~RUBY
  etc...
RUBY
# to
example.class_eval <<~RUBY, __FILE__, __LINE__ + 1
  etc...
RUBY
@caalberts
Copy link

@caalberts caalberts commented Jan 23, 2021

For #eval, the current cop is suggesting to pass __FILE__ and __LINE__, but there needs to be a binding as second argument.

  it 'registers an offense when using `#eval` without any arguments' do
    expect_offense(<<~RUBY)
      eval <<-CODE
      ^^^^^^^^^^^^ Pass `__FILE__` and `__LINE__` to `eval` method, as they are used by backtraces.
        do_something
      CODE
    RUBY

Without binding, there would be an error:

eval(<<~CODE, __FILE__, __LINE__ + 1)
  raise 'test error in eval'
CODE

# Traceback (most recent call last):
#        1: from sample.rb:3:in `<main>'
# sample.rb:3:in `eval': no implicit conversion of Integer into String (TypeError)

I think this should be fixed first before adding auto-correct.

@dvandersluis
Copy link
Member

@dvandersluis dvandersluis commented Jan 23, 2021

I opened #9409 to fix the offense messages for this cop.

@ceteece
Copy link
Contributor

@ceteece ceteece commented Jan 23, 2021

I can take a stab at this issue this weekend if no one else has gotten a start on it.

@dvandersluis
Copy link
Member

@dvandersluis dvandersluis commented Jan 23, 2021

@ceteece go for it! Just be aware there are two PRs open that change the cop (particularly #9411 which refactors some of the code).

@ceteece
Copy link
Contributor

@ceteece ceteece commented Jan 24, 2021

Sounds good, I'll wait for those to get merged before submitting a PR.

ceteece added a commit to ceteece/rubocop that referenced this issue Jan 28, 2021
ceteece added a commit to ceteece/rubocop that referenced this issue Jan 30, 2021
ceteece added a commit to ceteece/rubocop that referenced this issue Jan 30, 2021
ceteece added a commit to ceteece/rubocop that referenced this issue Jan 30, 2021
ceteece added a commit to ceteece/rubocop that referenced this issue Jan 30, 2021
ceteece added a commit to ceteece/rubocop that referenced this issue Jan 30, 2021
bbatsov added a commit that referenced this issue Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants