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 cop's ExpectMatchingDefinition doesn't work with custom directories #6289
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding! |
This issues been automatically closed due to lack of activity. Feel free to re-open it if you ever come back to it. |
@patbl I wonder if you found a solution for this in the meantime? I saw there's a new(ish) setting In my case my projects are all in a rubocop/lib/rubocop/cop/naming/file_name.rb Line 186 in 1d5621d
~/src/project/app/models/user.rb it wants a Project::App::Models namespace 😁
Related discussion: https://stackoverflow.com/questions/61689211/rubocop-naming-filename-cop-complains-about-standard-files-when-expectmatchingde |
I added all the custom paths to the |
I'd love a |
opened #10220 |
PR that should fix it #10224 |
Is your feature request related to a problem? Please describe.
In Rails, you can add directories to
config.autoload_paths
, and these directories don't have to conform to the standard Rails namespacing conventions.For example, suppose you have the file
app/models/news/photo_story.rb
. Normally, you'd have to name the class in that fileNews::PhotoStory
. But if you addapp/models/news
toconfig.autoload_paths
, you can instead name the filePhotoStory
, and autoloading will still work.This usually isn't the best thing to do, but people do it.
If you have
ExpectMatchingDefinition: true
, Rubocop will say something likeDescribe the solution you'd like
It would be nice if you could specify
autoload_paths
in the Rubocop configuration, and have Rubocop instead look for unnamespaced classes in those directories. Something likeThen it would omit the
News::
prefix when looking for constants in those files. It would still report an offense if you named the class something likePhotosStory
.Describe alternatives you've considered
I could exclude the relevant paths, but then I'd lose out the check for those files (including the snake-case filename check).
The text was updated successfully, but these errors were encountered: