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 cop's ExpectMatchingDefinition doesn't work with custom directories #6289

Closed
patbl opened this issue Sep 14, 2018 · 2 comments
Closed

Comments

@patbl
Copy link

@patbl patbl commented Sep 14, 2018

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 file News::PhotoStory. But if you add app/models/news to config.autoload_paths, you can instead name the file PhotoStory, 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 like

photo_story.rb should define a class or module called News::PhotoStory.

Describe 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 like

Naming/FileName:
  Enabled: true
  ExpectMatchingDefinition: true
  CustomDirectories:
    - app/models/news

Then 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 like PhotosStory.

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).

@bbatsov bbatsov added the enhancement label Sep 23, 2018
@stale
Copy link

@stale stale bot commented May 8, 2019

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!

@stale stale bot added the stale label May 8, 2019
@stale
Copy link

@stale stale bot commented Jun 7, 2019

This issues been automatically closed due to lack of activity. Feel free to re-open it if you ever come back to it.

@stale stale bot closed this Jun 7, 2019
jschneid added a commit to jschneid/rubocop that referenced this issue Mar 6, 2020
jschneid added a commit to jschneid/rubocop that referenced this issue Mar 6, 2020
jschneid added a commit to jschneid/rubocop that referenced this issue May 1, 2020
…hy option
jschneid added a commit to jschneid/rubocop that referenced this issue May 1, 2020
…hy option
jschneid added a commit to jschneid/rubocop that referenced this issue May 1, 2020
…hy option
jschneid added a commit to jschneid/rubocop that referenced this issue May 29, 2020
…hy option
bbatsov added a commit that referenced this issue May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.