Rubocop: "Use snake_case for source file names." false positive for style linter

Created on 8 Jul 2015  路  10Comments  路  Source: rubocop-hq/rubocop

I have the following offense:

lib/check-server-accounts.rb:1:1: C: Use snake_case for source file names.
require 'check_server_accounts/options_parser'
^

It looks like the regex of this cop is not correct.

It should be changed to:

SNAKE_CASE = /^[\/\da-z_]+$/

Most helpful comment

lib/check-server-accounts.rb

For whomever else stumbles upon this:

It's referring to the name of the file it's checking, not the first line of code.

I thought it was a bug too when it appeared to be complaining about the shebang.

All 10 comments

@zedtux See my comment in response to your comment on issue #1496

The regexp is correct. See https://en.m.wikipedia.org/wiki/Snake_case

+1

lib/check-server-accounts.rb

For whomever else stumbles upon this:

It's referring to the name of the file it's checking, not the first line of code.

I thought it was a bug too when it appeared to be complaining about the shebang.

Silly me, I didn't get it until now.
Thanks for pointing this out again.

This should really be more clear about what's happening. If the file name is the issue, there should be a better warning message that says so. Either that, or this needs better documentation.

@lorentrogers No argument from me. :-) I guess we should change this message.

Awesome - I'll put together a PR soon.

馃憤

So, I am new to Visual studio code, new to the ruby extension, new to rubocop extension, new to ruby programing. I think I got everything installed right. Something complained that my file should be named main, so I changed that. then when I installed rubocop it complained that the file name doesn't match.
(The name of this source file (``) should use snake_case. (convention:Style/FileName)' at: '1,1' source: ''), So I changed it to main_1.rb . I have no ideal what the error is complaining about! But I still have the error, put it in google and found this. What is ( snake_case) file name. Duh!

Looks like a problem with the editor integration. What the error message is saying is "you've given a file called '' (i.e., an empty name) to RuboCop, and that file name is not snake case". This means that it doesn't consist of lower case letters, digits and underscores.

Editors typically call RuboCop with the --stdin FILE option, but passing an empty string will not result in any inspection, so I'm not sure how you'd get that error.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tedPen picture tedPen  路  3Comments

mlammers picture mlammers  路  3Comments

printercu picture printercu  路  3Comments

Aqualon picture Aqualon  路  3Comments

benoittgt picture benoittgt  路  3Comments