-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add new Lint/UriEscapeUnescape
cop
#4702
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 new Lint/UriEscapeUnescape
cop
#4702
Conversation
a95564f
to
5bcc92b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I'm going through some of my code, but I'm hung up on the correct remediation for a violation of this rule.
It's not obvious to me which use cases warrant which of the three options that were given. Are you able to elaborate? Thanks. |
I also don't see why |
Because
I agree, and the educational aspect is arguably the more important one. This message was ported directly from the commit in Ruby trunk. Perhaps "obsolete" should be reworded to "deprecated", but "obsolete" is the wording used in Ruby's own deprecation warning, and the suggested replacement was made by Ruby core team members themselves. |
Thanks @Drenmi for your fantastic explanation! I'm now 100% a proponent of this cop. |
I found http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-core/29293?29179-31097 but I still have no idea why Ruby core team deprecated it. |
Feature
This cop identifies places where
URI.escape
can be replaced byCGI.escape
,URI.encode_www_form
orURI.encode_www_form_component
depending on your specific use case.Also this cop identifies places where
URI.unescape
can be replaced byCGI.unescape
,URI.decode_www_form
orURI.decode_www_form_component
depending on your specific use case.Target Problem
Emulate the following Ruby's warnings.
Other Information
This cop does not have autocorrect because these methods to replace depends on use case.
The following is an excerpt from the API Doc.
URI.escape
https://github.com/ruby/ruby/blob/cd6df5fb3c1e9b965071d6a92ed1c7d4a938560f/lib/uri/common.rb#L80-L87
URI.unescape
https://github.com/ruby/ruby/blob/cd6df5fb3c1e9b965071d6a92ed1c7d4a938560f/lib/uri/common.rb#L117-L122
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).rake spec
) are passing.rake internal_investigation
.and description in grammatically correct, complete sentences.
rake generate_cops_documentation
(required only when you've added a new cop or changed the configuration/documentation of an existing cop).