Rubocop: Style/Filename gives wrong diagnostic for some known ruby file names

Created on 7 Apr 2017  路  4Comments  路  Source: rubocop-hq/rubocop

Rubocop will interpret a file named Dangerfile as having ruby source, but will throw an invalid name error.

Diving in Rubocop's source, I've identified the list of file names to be considered Ruby source:

https://github.com/bbatsov/rubocop/blob/66405e118491afd8e8ec574cf2dc18549ef9a2df/lib/rubocop/target_finder.rb#L32-L52

In default.yml there is an interesting comment in the Style/Filename cop:

Style/FileName:
  # File names listed in `AllCops:Include` are excluded by default. Add extra
  # excludes here.

https://github.com/bbatsov/rubocop/blob/ef729dfcc5d15e038db24579b761bc0b56991de0/config/default.yml#L503-L505

If we go to AllCops:Include in the same file, we find an interesting list of files:

https://github.com/bbatsov/rubocop/blob/ef729dfcc5d15e038db24579b761bc0b56991de0/config/default.yml#L9-L29

These two lists have a big overlap but are not identical.

As I see it, to solve my particular issue I would need to add Dangerfile to AllCops:Include, but I'm wondering if these two lists of potential Ruby files shouldn't be merged instead of being maintained separately?

I want to hear what folks think. I'll be happy to send a PR when/if someone more knowledgeable in the codebase gives me some pointers :)

Expected behavior

The Style/Filename cop show show be triggered by known Ruby file names.

Actual behavior

$ rubocop Dangerfile
Inspecting 1 file
C

Offenses:

Dangerfile:1:1: C: The name of this source file (Dangerfile) should use snake_case.
# Make it more obvious that a PR is a work in progress and shouldn't be merged yet
^

1 file inspected, 1 offense detected

Steps to reproduce the problem

1- Create a file named Dangerfile
2- Run rubocop Dangerfile

RuboCop version

$ rubocop -V
0.48.1 (using Parser 2.4.0.0, running on ruby 2.4.0 x86_64-darwin16)
bug

Most helpful comment

I've synced up the two lists for now, but down the road this duplication should really be taken care of.

All 4 comments

Seems like an oversight on our part. Guess we should merge those lists and ideally rely on the configuration so users can change the list themselves.

I've synced up the two lists for now, but down the road this duplication should really be taken care of.

Is this still an issue?

@ryanhageman Thank you for mentioning. This issue has been solved by edge RuboCop with #5882.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

herwinw picture herwinw  路  3Comments

mikegee picture mikegee  路  3Comments

kirrmann picture kirrmann  路  3Comments

AndreiMotinga picture AndreiMotinga  路  3Comments

cabello picture cabello  路  3Comments