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

Naming/FileName: Detect constant assignment #10221

Closed
splattael opened this issue Oct 29, 2021 · 1 comment · Fixed by #10223
Closed

Naming/FileName: Detect constant assignment #10221

splattael opened this issue Oct 29, 2021 · 1 comment · Fixed by #10223

Comments

@splattael
Copy link
Contributor

splattael commented Oct 29, 2021

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

Currently, Naming/FileName always flag the following code:

lib/something/bar.rb

module Something
  Bar = Struct.new(:bar)
end

which produces

Offenses:

lib/something/bar.rb:1:1: C: Naming/FileName: bar.rb should define a class or module called Something::Bar.
module Something
^

Describe the solution you'd like

It'd be great to support such constant assignments.

Describe alternatives you've considered

In this example, one could use class Bar < Struct.new(:bar) but those workarounds are not always feasible.

Additional context

See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/73252#note_717026413

dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Oct 29, 2021
…as classes that satisfy the `ExpectMatchingDefinition` requirement.
@splattael
Copy link
Contributor Author

We might also want to support aliasing as in:

module Something
  Bar = ::OtherNamespace::Bar
end

bbatsov pushed a commit that referenced this issue Nov 12, 2021
…ses that satisfy the `ExpectMatchingDefinition` requirement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants