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

Style/FileName: false positive when inspecting file in non-current directory #1598

Closed
zenspider opened this issue Jan 26, 2015 · 4 comments
Closed
Assignees
Labels

Comments

@zenspider
Copy link

I have this on the top of my Rakefile:

-*- ruby -*-

and rubocop warns me about using snake case for file names.

@zenspider zenspider changed the title emacs mode lines are not understood Style/FileName: emacs mode lines are not understood Jan 27, 2015
@bbatsov
Copy link
Collaborator

bbatsov commented Jan 27, 2015

Rakefile is supposed to be a whitelisted name, so I'm not sure what's wrong here. Maybe some config problem? The Emacs comment has nothing do with this cop (the message is simply associated with the first line in the file).

P.S. If you're using Emacs 24.4+ this comment is redundant.

@jonas054 jonas054 added the bug label Jan 27, 2015
@jonas054
Copy link
Collaborator

I can confirm that there's a bug here, though I have not found that the emacs mode line makes any difference. Here's what I've found.

  • If I run rubocop and give it a directory that is not equal to, and not a subdirectory of, the current directory, then a Rakefile in the inspected directory is not inspected.
  • If I give the absolute path to the Rakefile as an argument (still from a different directory tree), then the file is checked and Style/FileName reports an offense.

I think both of these are bugs. The behavior is different if I run from the inspected directory without arguments.

 /tmp$ find 1598 -ls
4457280    4 drwxrwxr-x   3 jonas    jonas        4096 jan 27 19:05 1598
4459479    4 drwxrwxr-x   2 jonas    jonas        4096 jan 27 19:05 1598/other
4458731    4 -rw-rw-r--   1 jonas    jonas         822 jan 27 18:58 1598/Rakefile
 /tmp$ cd 1598/other/
 /tmp/1598/other$ rubocop /tmp/1598/
Inspecting 0 files


0 files inspected, no offenses detected
 /tmp/1598/other$ rubocop /tmp/1598/Rakefile 
Inspecting 1 file
C

Offenses:

/tmp/1598/Rakefile:1:1: C: Use snake_case for source file names.
# encoding: utf-8
^

1 file inspected, 1 offense detected
 /tmp/1598/other$ cd ..
 /tmp/1598$ rubocop
Inspecting 1 file
.

1 file inspected, no offenses detected

@jonas054 jonas054 self-assigned this Jan 27, 2015
@zenspider
Copy link
Author

Ah. sorry. Feel free to change the title since the modeline has nothing to do with it. I assumed it was relevant.

@zenspider
Copy link
Author

@jonas054 I wasn't running rubocop that way... lemme try to get a repro.

ETA: I got nothing. Sorry. I don't remember how this came up exactly. OH. Maybe I do. I think I was running it via a private gem install relative to the current directory. So the pathing idea is probably the same.

@jonas054 jonas054 changed the title Style/FileName: emacs mode lines are not understood Style/FileName: false positive when inspecting non-current directory Jan 28, 2015
@jonas054 jonas054 changed the title Style/FileName: false positive when inspecting non-current directory Style/FileName: false positive when inspecting file in non-current directory Jan 28, 2015
bbatsov added a commit that referenced this issue Jan 29, 2015
[Fix #1598] Match absolute path too in Config#file_to_include?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants