Skip to content

Line numbers are wrong if magic comments are used #425

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

Closed
jeremyevans opened this issue Sep 21, 2016 · 0 comments · Fixed by #580
Closed

Line numbers are wrong if magic comments are used #425

jeremyevans opened this issue Sep 21, 2016 · 0 comments · Fixed by #580

Comments

@jeremyevans
Copy link
Contributor

If you use a magic comment, the line numbers are wrong as they treat the first non-magic comment line as line 1. This probably needs fixing in lib/rdoc/encoding.rb.

Example:

$ cat a.rb && rdoc24 a.rb > /dev/null 2>&1 && fgrep line doc/Object.html
def a; end
            <pre><span class="ruby-comment"># File a.rb, line 1</span>
$ cat a2.rb && rdoc24 a2.rb > /dev/null 2>&1 && fgrep line doc/Object.html
# encoding: utf-8
def a; end
            <pre><span class="ruby-comment"># File a2.rb, line 1</span>
$ cat a3.rb && rdoc24 a3.rb > /dev/null 2>&1 && fgrep line doc/Object.html
# encoding: utf-8
# frozen-string-literal: true
def a; end
            <pre><span class="ruby-comment"># File a3.rb, line 1</span>
$ cat a4.rb && rdoc24 a4.rb > /dev/null 2>&1 && fgrep line doc/Object.html
# encoding: utf-8
# frozen-string-literal: true

def a; end
            <pre><span class="ruby-comment"># File a4.rb, line 2</span>
aycabta added a commit to aycabta/rdoc that referenced this issue Jan 1, 2018
RDoc::Encoding.read_file removes magic comments, after that, Ruby parser
processes the content. So method line number is reduced by the amount of
the magic comment lines.

This commit fixes it by that changes the behavior of
RDoc::Encoding.read_file to not remove magic comments.

This closes ruby#425.

...But please wait for merging, this branch outputs strange documents.
I'll add some commits to this branch later.
aycabta added a commit to aycabta/rdoc that referenced this issue Jan 1, 2018
RDoc::Encoding.read_file removes magic comments, after that, Ruby parser
processes the content. So method line number is reduced by the amount of
the magic comment lines.

This commit fixes it by that changes the behavior of
RDoc::Encoding.read_file to not remove magic comments.

This closes ruby#425.

...But please wait for merging, this branch outputs strange documents.
I'll add some commits to this branch later.
aycabta added a commit to aycabta/rdoc that referenced this issue Jan 10, 2018
RDoc::Encoding.read_file removes magic comments, after that, Ruby parser
processes the content. So method line number is reduced by the amount of
the magic comment lines.

This commit fixes it by that changes the behavior of
RDoc::Encoding.read_file to not remove magic comments.

This closes ruby#425.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant