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
Tempfile closing and unlinking #12328
Comments
Change line here
Note, that |
Thank @fatkodima, that was exactly my concern. I'm not super experienced in Rubocop, so I have no idea how to check that a Tempfile is created and never closed. It could be in the same metod, or another method, or somewhere else. Is that possible with Rubocop? |
No, because rubocop is a static code analyzer and does not run the user's code. The best it can do, as seen in the mentioned cop, is checking that |
Actually you can check that the file is closed in the same method, but this is a perfect case for calling |
I opened #12330 and also refactored it to tweak some redundant logic. |
…le.open` Fixes rubocop#12328. This PR makes `Style/AutoResourceCleanup` aware of `Tempfile.open`.
…leanup_aware_of_tempfile_open [Fix #12328] Make `Style/AutoResourceCleanup` aware of `Tempfile.open`
Is your feature request related to a problem? Please describe.
I was today years old when I found out that Tempfile are supposed to be unlinked and closed for the GC to free the memory. I had a huge spike in memory and took me hours of investigations
Describe the solution you'd like
whenever using a Tempfile, raise a Rubocop error if it's not unlinked and closed - something similar to what happens when calling Kernel.open
Describe alternatives you've considered
I have not considered any, tbh
Additional context
I'm more than happy to help with a PR, but I don't know where to start and I don't have enough time in the next few weeks
The text was updated successfully, but these errors were encountered: