Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Reported line numbers are sometimes incorrect #138

Closed
TEHEK opened this issue Nov 22, 2015 · 4 comments · May be fixed by electrode-io/electrode-docgen#7 or yashwanth-t/node#2
Closed

Reported line numbers are sometimes incorrect #138

TEHEK opened this issue Nov 22, 2015 · 4 comments · May be fixed by electrode-io/electrode-docgen#7 or yashwanth-t/node#2

Comments

@TEHEK
Copy link

TEHEK commented Nov 22, 2015

let comment = `
/**
 * Test class
 * @extends {BaseClass}
 * @constructor
 * @param {string} name
 */
`;

doctrine.parse(comment, {unwrap: true, lineNumbers: true});


{ description: '/**\nTest class',
  tags: 
   [ { title: 'extends',
       description: null,
       lineNumber: 3,
       type: [Object],
       name: null },
     { title: 'constructor',
       description: null,
       lineNumber: 5,
       type: null,
       name: null },
     { title: 'param',
       description: '/',
       lineNumber: 7,
       type: [Object],
       name: 'name' } ] }

Constructor's lineNumber is 5, but should be 4.
Param's lineNumber is 7. Should be 5

Also, notice the param's description.

@TEHEK
Copy link
Author

TEHEK commented Nov 22, 2015

A little experiment:

'use strict';

var doctrine = require('../lib/doctrine');

var Rules = {
    // http://usejsdoc.org/tags-access.html
    'access': ['parseAccess'],
    // http://usejsdoc.org/tags-alias.html
    'alias': ['parseNamePath', 'ensureEnd'],
    // http://usejsdoc.org/tags-augments.html
    'augments': ['parseType', 'parseNamePathOptional', 'ensureEnd'],
    // http://usejsdoc.org/tags-constructor.html
    'constructor': ['parseType', 'parseNamePathOptional', 'ensureEnd'],
    // Synonym: http://usejsdoc.org/tags-constructor.html
    'class': ['parseType', 'parseNamePathOptional', 'ensureEnd'],
    // Synonym: http://usejsdoc.org/tags-extends.html
    'extends': ['parseType', 'parseNamePathOptional', 'ensureEnd'],
    // http://usejsdoc.org/tags-deprecated.html
    'deprecated': ['parseDescription'],
    // http://usejsdoc.org/tags-global.html
    'global': ['ensureEnd'],
    // http://usejsdoc.org/tags-inner.html
    'inner': ['ensureEnd'],
    // http://usejsdoc.org/tags-instance.html
    'instance': ['ensureEnd'],
    // http://usejsdoc.org/tags-kind.html
    'kind': ['parseKind'],
    // http://usejsdoc.org/tags-mixes.html
    'mixes': ['parseNamePath', 'ensureEnd'],
    // http://usejsdoc.org/tags-mixin.html
    'mixin': ['parseNamePathOptional', 'ensureEnd'],
    // http://usejsdoc.org/tags-member.html
    'member': ['parseType', 'parseNamePathOptional', 'ensureEnd'],
    // http://usejsdoc.org/tags-method.html
    'method': ['parseNamePathOptional', 'ensureEnd'],
    // http://usejsdoc.org/tags-module.html
    'module': ['parseType', 'parseNamePathOptional', 'ensureEnd'],
    // Synonym: http://usejsdoc.org/tags-method.html
    'func': ['parseNamePathOptional', 'ensureEnd'],
    // Synonym: http://usejsdoc.org/tags-method.html
    'function': ['parseNamePathOptional', 'ensureEnd'],
    // Synonym: http://usejsdoc.org/tags-member.html
    'var': ['parseType', 'parseNamePathOptional', 'ensureEnd'],
    // http://usejsdoc.org/tags-name.html
    'name': ['parseNamePath', 'ensureEnd'],
    // http://usejsdoc.org/tags-namespace.html
    'namespace': ['parseType', 'parseNamePathOptional', 'ensureEnd'],
    // http://usejsdoc.org/tags-private.html
    'private': ['parseType', 'parseDescription'],
    // http://usejsdoc.org/tags-protected.html
    'protected': ['parseType', 'parseDescription'],
    // http://usejsdoc.org/tags-public.html
    'public': ['parseType', 'parseDescription'],
    // http://usejsdoc.org/tags-readonly.html
    'readonly': ['ensureEnd'],
    // http://usejsdoc.org/tags-requires.html
    'requires': ['parseNamePath', 'ensureEnd'],
    // http://usejsdoc.org/tags-since.html
    'since': ['parseDescription'],
    // http://usejsdoc.org/tags-static.html
    'static': ['ensureEnd'],
    // http://usejsdoc.org/tags-summary.html
    'summary': ['parseDescription'],
    // http://usejsdoc.org/tags-this.html
    'this': ['parseNamePath', 'ensureEnd'],
    // http://usejsdoc.org/tags-todo.html
    'todo': ['parseDescription'],
    // http://usejsdoc.org/tags-typedef.html
    'typedef': ['parseType', 'parseNamePathOptional'],
    // http://usejsdoc.org/tags-variation.html
    'variation': ['parseVariation'],
    // http://usejsdoc.org/tags-version.html
    'version': ['parseDescription']
};

for (var tag in Rules) {
  var comment = [
    '/**',
    ' * @' + tag,
    ' * @dummy',
    ' */'
  ].join('\n');
  var t = doctrine.parse(comment, {unwrap: true, sloppy: true, lineNumbers: true});
  if (t.tags[1] && t.tags[1].lineNumber != 2) {
    console.error('Wrong: ', tag);
    continue;
  }
  console.log('OK:   ', tag);
}

Prints:

OK:     access
OK:     alias
Wrong:  augments
Wrong:  constructor
Wrong:  class
Wrong:  extends
OK:     deprecated
OK:     global
OK:     inner
OK:     instance
OK:     kind
OK:     mixes
Wrong:  mixin
Wrong:  member
Wrong:  method
Wrong:  module
Wrong:  func
Wrong:  function
Wrong:  var
OK:     name
Wrong:  namespace
OK:     private
OK:     protected
OK:     public
OK:     readonly
OK:     requires
OK:     since
OK:     static
OK:     summary
OK:     this
OK:     todo
OK:     typedef
OK:     variation
OK:     version

I suspect that parseNamePathOptional is responsible.

TEHEK pushed a commit to TEHEK/doctrine that referenced this issue Nov 23, 2015
@nzakas
Copy link
Member

nzakas commented Nov 23, 2015

The line number should be 5 because you have an initial newline right after the back tick. So "@constructor" is actually on line 5. That said, "@param" should be on line 6, so this looks like parameter parsing is the root problem.

@TEHEK
Copy link
Author

TEHEK commented Nov 23, 2015

Yes, there's a new line, but that shouldn't count as it is outside the jsdoc comment.

@nzakas
Copy link
Member

nzakas commented Nov 23, 2015

Ah, good point!

TEHEK pushed a commit to TEHEK/doctrine that referenced this issue Nov 24, 2015
…ed when parsing tags resulting in sometimes incorrect reported lineNumber.

(fixes eslint#138)
TEHEK pushed a commit to TEHEK/doctrine that referenced this issue Nov 25, 2015
Fixing issue where input was not consumed via advance() but was skipped when
parsing tags resulting in sometimes incorrect reported lineNumber.
TEHEK pushed a commit to TEHEK/doctrine that referenced this issue Nov 25, 2015
Fixing issue where input was not consumed via advance() but was skipped when
parsing tags resulting in sometimes incorrect reported lineNumber.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants