Skip to content

1.0.1 warnings - recommended code uses inconsistent capitalized constants #128

Open
@jrafanie

Description

@hsbt First of all, thank you again for your work on ruby.

Following up on #125. The "suggested" or recommended code in the warnings can be confusing:

% ruby -W2 -e "puts RUBY_VERSION; require 'uri'; puts URI::VERSION; puts URI::PATTERN; URI::DEFAULT_PARSER.escape(''); URI::DEFAULT_PARSER.unescape(''); puts URI::Regexp; puts URI::REGEXP"
3.1.6
1.0.1
-e:1: warning: URI::PATTERN is obsolete. Use RFC2396_Parser::PATTERN explicitly.
URI::RFC2396_REGEXP::PATTERN
-e:1: warning: URI::RFC3986_PARSER.escape is obsoleted. Use URI::RFC2396_PARSER.escape explicitly.
-e:1: warning: URI::RFC3986_PARSER.unescape is obsoleted. Use URI::RFC2396_PARSER.unescape explicitly.
-e:1: warning: URI::Regexp is obsolete. Use RFC2396_Parser::Regexp explicitly.
Regexp
-e:1: warning: URI::REGEXP is obsolete. Use URI::RFC2396_REGEXP explicitly.
URI::RFC2396_REGEXP

The problem is this:
RFC2396_Parser vs. RFC2396_PARSER or RFC2396_Parser::Regexp vs. URI::RFC2396_REGEXP

It's easy to make a mistake and use the wrong case. They're very similar names with different capitalization but they're not the same thing. I'm sure there are others:

% git grep "explicitly" lib/uri*
lib/uri/common.rb:      warn "URI::REGEXP is obsolete. Use URI::RFC2396_REGEXP explicitly.", uplevel: 1 if $VERBOSE
lib/uri/common.rb:      warn "URI::#{const} is obsolete. Use RFC2396_PARSER.regexp[#{const.inspect}] explicitly.", uplevel: 1 if $VERBOSE
lib/uri/common.rb:      warn "URI::#{const} is obsolete. Use RFC2396_Parser::#{const} explicitly.", uplevel: 1 if $VERBOSE
lib/uri/rfc3986_parser.rb:      warn "URI::RFC3986_PARSER.extract is obsoleted. Use URI::RFC2396_PARSER.extract explicitly.", uplevel: 1 if $VERBOSE
lib/uri/rfc3986_parser.rb:      warn "URI::RFC3986_PARSER.make_regexp is obsoleted. Use URI::RFC2396_PARSER.make_regexp explicitly.", uplevel: 1 if $VERBOSE
lib/uri/rfc3986_parser.rb:      warn "URI::RFC3986_PARSER.escape is obsoleted. Use URI::RFC2396_PARSER.escape explicitly.", uplevel: 1 if $VERBOSE
lib/uri/rfc3986_parser.rb:      warn "URI::RFC3986_PARSER.unescape is obsoleted. Use URI::RFC2396_PARSER.unescape explicitly.", uplevel: 1 if $VERBOSE

Can we add capitalized versions of constants so we can consistently suggest capitalized versions of constants in these warnings?

Thank you!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions