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

Cop idea: mark self-require_relative as bad code #10084

Closed
ShockwaveNN opened this issue Sep 15, 2021 · 0 comments · Fixed by #10085
Closed

Cop idea: mark self-require_relative as bad code #10084

ShockwaveNN opened this issue Sep 15, 2021 · 0 comments · Fixed by #10085

Comments

@ShockwaveNN
Copy link
Contributor

Is your feature request related to a problem? Please describe.

This code in file my_class.rb

# frozen_string_literal: true

require_relative 'my_class'

# Class which puts foo
class MyClass
  def foo
    puts 'foo'
  end
end

Describe the solution you'd like

require_relative 'my_class' is completely useless (require itself) - rubocop should mark it as bad smell

Additional context

# rubocop -V
1.21.0 (using Parser 3.0.2.0, rubocop-ast 1.11.0, running on ruby 3.0.2 x86_64-linux)

@ShockwaveNN ShockwaveNN changed the title Cop idea - mark self-require_relative as bad code Cop idea: mark self-require_relative as bad code Sep 15, 2021
koic added a commit to koic/rubocop that referenced this issue Sep 15, 2021
Fixes rubocop#10084.

This PR adds new `Lint/RequireRelativeSelfPath` cop.
It checks for uses of `require_relative` with self file path argument.

```ruby
# bad

# foo.rb
require_relative 'foo'
require_relative 'bar'

# good

# foo.rb
require_relative 'bar'
```
bbatsov pushed a commit that referenced this issue Sep 16, 2021
Fixes #10084.

This PR adds new `Lint/RequireRelativeSelfPath` cop.
It checks for uses of `require_relative` with self file path argument.

```ruby
# bad

# foo.rb
require_relative 'foo'
require_relative 'bar'

# good

# foo.rb
require_relative 'bar'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants