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

TrailingBlankLines should not trigger on empty file with single blank line #993

Closed
JeanMertz opened this issue Apr 11, 2014 · 9 comments
Closed
Assignees
Labels

Comments

@JeanMertz
Copy link

Files with a single (empty) line should not trigger TrailingBlankLines: Final newline missing..

@jonas054
Copy link
Collaborator

True.

@jonas054 jonas054 added the bug label Apr 11, 2014
@jonas054 jonas054 self-assigned this Apr 11, 2014
@jonas054
Copy link
Collaborator

I get the following results when I run rubocop -D (0.20.1 or latest master) on an entirely empty file and one with just a newline under Ruby 1.9.3:

/tmp/993/newline.rb:1:1: C: Encoding: Missing utf-8 encoding comment.
/tmp/993/empty.rb:1:1: C: Encoding: Missing utf-8 encoding comment.
/tmp/993/empty.rb:1:1: C: TrailingBlankLines: Final newline missing.

I think it's wrong to report any offense for an empty file, while the report about encoding comment for newline.rb is ok.

@JeanMertz
Copy link
Author

@jonas054 is there any reason to add the encoding comment when there is no content (besides the \n) in the file? It seems weird to me to force an encoding comment on an empty file.

(I'm using Ruby 2.1 myself, so didn't run into the warning you described)

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 12, 2014

I guess it doesn't make sense to run cops on blank files.

@JeanMertz
Copy link
Author

@bbatsov except for the ones that act on something other than the content (for example, the snake case naming one).

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 12, 2014

Yep, you're totally right.

@jonas054
Copy link
Collaborator

@JeanMertz You have to draw the line somewhere. I'd like to draw it between an empty file and a non-empty file. If there is at least one character, then the file has an encoding.

@JeanMertz
Copy link
Author

@jonas054 seems reasonable. Although what about @bbatsov's (slightly modified) proposal of not running any content cops on empty files? I'm not sure if there's already such a classification (ie. if the cop checks the file, or the contents of the file), but that would completely solve this issue.

@jonas054
Copy link
Collaborator

No there is no such classification, so we would need to introduce a special case for one cop in generic code. That's not so good. I prefer to fix the problem in Encoding and TrailingBlankLines, and then add a high level spec example checking that no offenses are reported for an empty file.

bbatsov added a commit that referenced this issue Apr 18, 2014
[Fix #993] Don't report offenses for an empty file
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