Handle doc parameters for templated functions better

This commit is contained in:
Sebastian Wilzbach 2017-02-20 06:27:37 +01:00
parent 4b0f61bb98
commit 40b3f0d211
1 changed files with 33 additions and 2 deletions

View File

@ -85,6 +85,9 @@ class ProperlyDocumentedPublicFunctions : BaseAnalyzer
{ {
setLastDdocParams(decl.name.line, decl.name.column, decl.comment); setLastDdocParams(decl.name.line, decl.name.column, decl.comment);
checkDdocParams(decl.name.line, decl.name.column, decl.templateParameters); checkDdocParams(decl.name.line, decl.name.column, decl.templateParameters);
withinTemplate = true;
scope(exit) withinTemplate = false;
decl.accept(this); decl.accept(this);
} }
@ -120,8 +123,9 @@ class ProperlyDocumentedPublicFunctions : BaseAnalyzer
checkDdocParams(decl.name.line, decl.name.column, decl.templateParameters); checkDdocParams(decl.name.line, decl.name.column, decl.templateParameters);
enum voidType = tok!"void"; enum voidType = tok!"void";
if (decl.returnType is null || decl.returnType.type2.builtinType != voidType) if (decl.returnType is null || decl.returnType.type2.builtinType != voidType)
if (!(comment.isDitto || comment.sections.any!(s => s.name == "Returns"))) if (!(comment.isDitto || withinTemplate || comment.sections.any!(s => s.name == "Returns")))
addErrorMessage(decl.name.line, decl.name.column, MISSING_RETURNS_KEY, MISSING_RETURNS_MESSAGE); addErrorMessage(decl.name.line, decl.name.column, MISSING_RETURNS_KEY, MISSING_RETURNS_MESSAGE);
} }
@ -129,6 +133,7 @@ class ProperlyDocumentedPublicFunctions : BaseAnalyzer
private: private:
bool islastSeenVisibilityLabelPublic; bool islastSeenVisibilityLabelPublic;
bool withinTemplate;
static struct Function static struct Function
{ {
@ -161,7 +166,7 @@ private:
import std.array : array; import std.array : array;
const comment = parseComment(commentText, null); const comment = parseComment(commentText, null);
if (!comment.isDitto) if (!comment.isDitto && !withinTemplate)
{ {
// check old function for invalid ddoc params // check old function for invalid ddoc params
if (lastSeenFun.active) if (lastSeenFun.active)
@ -676,3 +681,29 @@ template bar(string val){}
stderr.writeln("Unittest for ProperlyDocumentedPublicFunctions passed."); stderr.writeln("Unittest for ProperlyDocumentedPublicFunctions passed.");
} }
unittest
{
assertAnalyzerWarnings(q{
/**
* Ddoc for the inner function appears here.
* This function is declared this way to allow for multiple variable-length
* template argument lists.
* ---
* abcde!("a", "b", "c")(100, x, y, z);
* ---
* Params:
* Args = foo
* U = bar
* T = barr
* varargs = foobar
* t = foo
* Returns: bar
*/
template abcde(Args ...) {
auto abcde(T, U...)(T t, U varargs) {
/// ....
}
}
}c, sac);
}