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

Add Tempfile.create to ignored iterators list #1747

Merged

Conversation

mateusdeap
Copy link
Contributor

Fixes #1490

I've added Tempfile.create to the list of ignored iterators and added a spec for it.

I'm submitting the PR to also get some feedback on the implementation. The specs all pass but it fails on the manual method dispatch code smell.

I tried searching for alternative ways to implement this without using respond_to? but didn't really find anything satisfactory, and if I don't test for that beforehand, many specs fail on exceptions because the exp object lacks the receiver method. Feedback on how to fix this would be most welcome!

Otherwise, I hope this is useful!

@troessner
Copy link
Owner

Looks good to me! @mvz ?

@mvz
Copy link
Collaborator

mvz commented Oct 31, 2023

I'll have a look this evening.

@mvz
Copy link
Collaborator

mvz commented Oct 31, 2023

The code looks good, but there are two issues:

  1. For some reason, ManualDispatch complains that "Reek::SmellDetectors::NestedIterators#ignored_iterator? manually dispatches method call". I don't see that, so maybe that's a bug in ManualDispatch?
  2. @troessner if I read NestedIterator should ignore _currently open_ like methods (like CSV and tempfile). #1490 (comment) correctly, you wanted to allow the option of ignoring Tempfile.create but not have that method be added to the default list of ignored methods?

@mvz
Copy link
Collaborator

mvz commented Oct 31, 2023

For some reason, ManualDispatch complains that "Reek::SmellDetectors::NestedIterators#ignored_iterator? manually dispatches method call". I don't see that, so maybe that's a bug in ManualDispatch?

Ah, that detector simply finds calls to #respond_to?, so I guess that makes sense.

"#{call.receiver&.name}.#{called_name}"
else
called_name
end
Copy link
Collaborator

@mvz mvz Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following seems to work and won't trigger ManualDispatch:

/#{pattern}/ =~ call.format_to_ruby

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I never heard of that method. Will edit the PR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a method defined on AST nodes by Reek itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied changes

@mateusdeap mateusdeap force-pushed the ignore-tempfile-create-in-nested-iterators branch from c1c7095 to 7dedfb3 Compare November 3, 2023 13:48
@mateusdeap
Copy link
Contributor Author

@troessner if I read #1490 (comment) correctly, you wanted to allow the option of ignoring Tempfile.create but not have that method be added to the default list of ignored methods?

@mvz As for this, now that I'm rereading it, I'm not sure. I interpreted it at the time as being "A PR that whitelists Tempfile.create". But if it's an option, than I suppose it would be something like a whitelist section in the reek configuration?

@mvz
Copy link
Collaborator

mvz commented Nov 3, 2023

But if it's an option, than I suppose it would be something like a whitelist section in the reek configuration?

Yes, it would be the ignore_iterators section just like here: https://github.com/troessner/reek/pull/1747/files#diff-473a12b36b25df9c36979c53cb67f2dce02afc614dca0c971b96154a7474d483R60, except in the user's own .reek.yml file.

@mateusdeap
Copy link
Contributor Author

I see. In that case, I'm not sure, honestly.

Now that I think about it, maybe I just leave the addition of the Tempfile.create item in the default reek.yml and that would be good enough?

Because I still get the impression the idea was that Tempfile.create (and some other methods, I now notice) are getting flagged with this smell even though they actually aren't cases of nested iterators. Basically all situations where the method yields a file that is open and closed within the loop.

Now I'm not so sure about the PR anymore lol

@mvz
Copy link
Collaborator

mvz commented Nov 10, 2023

Now I'm not so sure about the PR anymore lol

I think the change to #ignored_iterator? is still very useful.

@troessner can you enlighten us about your comment #1490 (comment)?

@troessner
Copy link
Owner

Puhh, that's 4 years ago and I haven't really any context anymore regarding this. Feel free to ignore my comment ;)

Copy link
Collaborator

@mvz mvz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright then, let's merge this!

@mvz mvz merged commit 70d6d53 into troessner:master Nov 12, 2023
6 checks passed
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

Successfully merging this pull request may close these issues.

NestedIterator should ignore _currently open_ like methods (like CSV and tempfile).
3 participants