rubocop-rails
rubocop-rails copied to clipboard
New cop to make sure Digest is used within OpenSSL context
Is your feature request related to a problem? Please describe.
The is for the rails Issue - https://github.com/rails/rails/issues/42665
Basically the team wants to use OpenSSL::Digest
and prevent any new code to use Digest
.
Describe the solution you'd like
So a new cop lint rule for that.
A clear and concise description of what you want to happen.
I have already opened a PR on the rails repo, but I suppose the likely outcome is to have an optional cop on the rubocop-rails repo
Solution Suggestion Cop could look something like this
class DigestWithOpenSSL < RuboCop::Cop::Base
MSG = "Digest may only be called from OpenSSL"
def_node_matcher :digest_open_call?, <<~PATTERN
(const nil? :Digest)
PATTERN
def on_const(node)
return unless digest_open_call?(node)
add_offense(node)
end
end
Which of the following layers has this issue?
- Rails framework layer (rails/rails repo) specific issue
- The issue that Rails application layer will be affected
- General issue with OpenSSL library of Ruby (e.g. https://github.com/ruby/openssl)
I'm not sure about this issue. Could you summarize and explain the background of this issue?
I think its both 1 and 2. Though I'm not completely sure myself. These can provide more context,
https://github.com/rails/rails/pull/40770#issuecomment-748347066
Though the actual issue states new code going into rails/rails
I tried to read the links, but it seems difficult to understand without the summary. I will close this issue, but if there is an explanation that is easy to understand for user level (In other words, the cop manual text) , I think we can consider it again. Thank you.