Navigation Menu

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 with ExpectMatchingDefinition and CheckDefinitionPathHierarchy does not enforce in custom folders #10220

Closed
grosser opened this issue Oct 28, 2021 · 3 comments · Fixed by #10224

Comments

@grosser
Copy link
Contributor

grosser commented Oct 28, 2021

Expected behavior

Naming/FileName:
  ExpectMatchingDefinition: true
  CheckDefinitionPathHierarchy: true

and

# something/bar.rb
module Foo
  class Bar

should be invalid because something != Bar

Actual behavior

it is valid (nothing with --debug either)

Steps to reproduce the problem

see expected

RuboCop version

1.22.3 (using Parser 3.0.2.0, rubocop-ast 1.12.0, running on ruby 2.6.5 x86_64-darwin19)

Misc

I tried poking around in lib/rubocop/cop/naming/file_name.rb but none of the methods in there are getting called if the filename matches the expected constant (also tried with --cache=false)

@splattael
Copy link
Contributor

splattael commented Oct 29, 2021

I can reproduce it with:

$ tree
.
├── lol
│   └── something
│       └── bar.rb
├── lib
│   └── something
│       └── bar.rb
└── something
    └── bar.rb

5 directories, 3 files

$ cat $(find . -name "*.rb")
module Foo
  class Bar
  end
end
module Foo
  class Bar
  end
end
module Foo
  class Bar
  end
end

$ rubocop -v
1.22.3

$ rubocop --only Naming/FileName .
Inspecting 3 files
C..

Offenses:

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

3 files inspected, 1 offense detected

RuboCop only detects a single offenses for code which is inside lib (or test, spec or src). Code outside of this structure (e.g. lol/) won't be detected.

Edit: I've added the actual directory structure 🤦

@grosser
Copy link
Contributor Author

grosser commented Oct 29, 2021

Finally got that working by hacking the gem and using UseCache: false ... so yeah can confirm that works, now just need a way to modify it :D

@grosser
Copy link
Contributor Author

grosser commented Oct 29, 2021

opened #10224 to fix

grosser added a commit to grosser/rubocop that referenced this issue Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants