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

RequireRelativeToLib cop shouldn't flag offenses from lib into lib #8

Closed
utkarsh2102 opened this issue Jul 31, 2020 · 0 comments · Fixed by #10
Closed

RequireRelativeToLib cop shouldn't flag offenses from lib into lib #8

utkarsh2102 opened this issue Jul 31, 2020 · 0 comments · Fixed by #10
Assignees
Labels
bug Something isn't working false-positive This is a false-positive

Comments

@utkarsh2102
Copy link
Owner

Upon using the cop on autoprefixer-rails' codebase, here's what it shows:

➜  autoprefixer-rails git:(use-rubocop) ✗ rubocop --only Packaging
Inspecting 25 files
..CC....................C

Offenses:

autoprefixer-rails.gemspec:13:24: C: Packaging/GemspecGit: Avoid using git to produce lists of files.
Downstreams often need to build your package in an environment that does not have git (on purpose).
Use some pure Ruby alternative, like Dir or Dir.glob.
  s.files            = `git ls-files`.split("\n")
                       ^^^^^^^^^^^^^^
lib/autoprefixer-rails.rb:39:1: C: Packaging/RelativeRequireToLib: Avoid using require_relative with
relative path to lib. Use require instead.
require_relative "autoprefixer-rails/result"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/autoprefixer-rails.rb:40:1: C: Packaging/RelativeRequireToLib: Avoid using require_relative with
relative path to lib. Use require instead.
require_relative "autoprefixer-rails/version"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/autoprefixer-rails.rb:41:1: C: Packaging/RelativeRequireToLib: Avoid using require_relative with
relative path to lib. Use require instead.
require_relative "autoprefixer-rails/processor"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/autoprefixer-rails.rb:43:1: C: Packaging/RelativeRequireToLib: Avoid using require_relative with
relative path to lib. Use require instead.
require_relative "autoprefixer-rails/railtie" if defined?(Rails)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/spec_helper.rb:6:1: C: Packaging/RelativeRequireToLib: Avoid using require_relative with
relative path to lib. Use require instead.
require_relative "../lib/autoprefixer-rails"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

25 files inspected, 6 offenses detected

The first and last offenses are correct. However, the middle ones don't look right.
The cop, essentially, shouldn't flag offenses from lib to lib. Just the ones that map from outside to lib.

@utkarsh2102 utkarsh2102 self-assigned this Jul 31, 2020
@utkarsh2102 utkarsh2102 added the bug Something isn't working label Jul 31, 2020
utkarsh2102 added a commit that referenced this issue Aug 16, 2020
At the moment, we are flagging *all* the `require_relative`
calls unless specified to behave differently via .rubocop.yml.

This means that this cop flags an offense as soon as it finds
a `require_relative` call anywhere. But it shouldn't flag
those as offenses if they're being used in lib/ and are
requiring files inside lib/ itself.

This is a false-positive.

Fixes: #8

Signed-off-by: Utkarsh Gupta <utkarsh@debian.org>
terceiro pushed a commit that referenced this issue Aug 17, 2020
At the moment, we are flagging *all* the `require_relative`
calls unless specified to behave differently via .rubocop.yml.

This means that this cop flags an offense as soon as it finds
a `require_relative` call anywhere. But it shouldn't flag
those as offenses if they're being used in lib/ and are
requiring files inside lib/ itself.

This is a false-positive.

Fixes: #8

Signed-off-by: Utkarsh Gupta <utkarsh@debian.org>
@utkarsh2102 utkarsh2102 added the false-positive This is a false-positive label Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working false-positive This is a false-positive
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant