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

Don't enforce cops after __END__ #1541

Closed
lloeki opened this issue Dec 30, 2014 · 7 comments
Closed

Don't enforce cops after __END__ #1541

lloeki opened this issue Dec 30, 2014 · 7 comments
Labels

Comments

@lloeki
Copy link
Contributor

lloeki commented Dec 30, 2014

__END__ can be used to mark the end of a Ruby file, and the remainder can be used as raw data. Homebrew uses this to include simple patches straight inside its formulas.

@bbatsov
Copy link
Collaborator

bbatsov commented Jan 7, 2015

I'm not sure RuboCop should handle this or parser. @whitequark what do you think? Perhaps parser should simply ignore code after __END__.

@whitequark
Copy link

Parser ignores code after __END__.

$ ruby-parse -e $'foo\n__END__\nbar'
(send nil :foo)

@jonas054
Copy link
Collaborator

jonas054 commented Jan 8, 2015

I think the only cops that have a problem with __END__ are the ones that examine code line-by-line:

  • Metrics/LineLength
  • Style/EndOfLine
  • Style/CommentIndentation
  • Style/Tab
  • Style/TrailingWhitespace
  • Style/TrailingBlankLines [Edit: Added this one after @lloeki's comment below]

Does that sound about right, @lloeki, or did you run into problems with other cops?

@bbatsov
Copy link
Collaborator

bbatsov commented Jan 8, 2015

Yeah, you're probably right.

@lloeki
Copy link
Contributor Author

lloeki commented Jan 8, 2015

Those are the ones I encountered:

Style/TrailingWhitespace:
    Enabled: false
Style/Tab:
    Enabled: false
Style/TrailingBlankLines:
    Enabled: false

@thomthom
Copy link
Contributor

thomthom commented Dec 4, 2017

I'm running into Lint/Syntax errors in text after __END__ when the file is using Carriage Returns for new lines:

image

image

We are using RuboCop to review third party source code where we ran into this scenario.

I looks like Ruby's String#lines only splits at \n. So when we have these odd files with \r then RuboCop fails to stop at __END__.

image

Could an alternative be to use .split(/\n\r|\r\n|\n|\r/)?

Had this been our own code we could fix it by saving with different line endings. But since we use RuboCop to review third party source for extensions to our application we cannot easily do that. And since Ruby files with \r for line endings still evaluates it would be a challenge to argue that we enforce such a given line ending style.

@jonas054
Copy link
Collaborator

  1. Syntax errors come from the parser gem, and RuboCop just picks them up and presents them.
  2. Ruby on Ubuntu rejects the given example code. I've tried with ruby-2.3, 2.4 and 2.5.
$ ruby -wc /tmp/1541.rb 
/tmp/1541.rb:1: warning: encountered \r in middle of line, treated as a mere space
/tmp/1541.rb:1: syntax error, unexpected tIDENTIFIER, expecting end-of-input
Version 1.0.30 - Feb 7 2016
                   ^~~~~~~

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

5 participants