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

add support for @param tags w/o a type #16

Merged
merged 3 commits into from
Jan 6, 2014

Conversation

dtao
Copy link
Contributor

@dtao dtao commented Jan 6, 2014

According to the JsDoc docs, the @param tag does not require a type. So this should be legal:

/**
 * @param somebody
 */
function sayHello(somebody) {
    alert('Hello ' + somebody);
}

This patch updates doctrine to parse the @param tag just fine in this case, w/ a type of null.

@dtao
Copy link
Contributor Author

dtao commented Jan 6, 2014

My bad—I completely forgot to run all the tests (only ran my test!). I will fix momentarily.

dtao added 2 commits January 6, 2014 08:00
These tests were actually covering the same scenario as the "param typeless"
test; but they were expecting failures (doctrine should now handle this case).
This is admittedly pretty hacky. The fundamental problem is that the original
code was written to enforce that @param tags must have types. This actually
isn't the case; so to fix that I added logic to check if a @param has a "type"
but no name, to cover this case:

    @param foo

In the above example the param would initially be parsed as having a "type" of
foo and no name; my fixer-up logic switched these around so foo becomes the
name and the type becomes null.

But now here is a problem case:

    @param {string} [foo]

The above is a "sloppy" declaration where foo is an optional param w/ a type of
string. Problem is that w/o the sloppy option set, parseName will return
undefined for name, which will trigger the logic previously described for
fixing the case w/ typeless params.

My solution is to handle this specific scenario at the end of next(): check for
a tag w/ a name, no type, and a description starting with '['; if this pattern
is found, revert things to the way they were. Hopefully @Constellation can come
up with a (much!) better approach for dealing with all this.
dtao added a commit to dtao/autodoc that referenced this pull request Jan 6, 2014
This is to handle typeless params, until eslint/doctrine#16 is
merged.
@dtao
Copy link
Contributor Author

dtao commented Jan 6, 2014

I believe this PR should be good to go now (w/ caveats: see the epic comment in that last commit).

@Constellation
Copy link
Member

Very nice. Merging.

Constellation added a commit that referenced this pull request Jan 6, 2014
add support for @param tags w/o a type
@Constellation Constellation merged commit 61a6df3 into eslint:master Jan 6, 2014
@Constellation
Copy link
Member

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants