Skip to content

Finish Operation Doc Comment Validation #3852

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

InsertCreativityHere
Copy link
Member

This PR finishes implementing #2998.

Now the parser will:

  • reject @param foo if foo isn't the name of an operation parameter
  • reject @return if it's applied to a void operation
  • reject @throws Foo if Foo isn't in it's exception specific (or derived from an exception that is)

We also now reject duplicate tags.
So a comment can't have more than one @deprecated, or more than one @return.
And for 'named' tags, you can't use the same name more than once either.

@param foo this is totally fine (if you have a parameter named `foo`)
@param Foo this will be rejected, because you already did `@param foo`.
@param bar totally fine because it's a different name.

Comment on lines +558 to +560
else if (
parseNamedCommentLine(l, throwsTag, name, lineText) ||
parseNamedCommentLine(l, exceptionTag, name, lineText))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We support @exception as an alias for @throws, and used to parse/validate them separately.
I combined them both into a single block to avoid code-duplication.

@InsertCreativityHere InsertCreativityHere marked this pull request as ready for review April 14, 2025 19:53
// Check that the '@param <name>' corresponds to an actual parameter in the operation.
const ParameterList params = operationTarget->parameters();
const auto paramNameCheck = [&name](const ParameterPtr& param) { return param->name() == name; };
if (std::find_if(params.begin(), params.end(), paramNameCheck) == params.end())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use std::none_of. I would also put the lambda inline, no need to give it a name.
https://en.cppreference.com/w/cpp/algorithm/all_any_none_of.

@@ -522,47 +522,88 @@ Slice::DocComment::parseFrom(const ContainedPtr& p, DocLinkFormatter linkFormatt

if (parseNamedCommentLine(l, paramTag, name, lineText))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be really nice to avoid naming anying l!

if (std::find_if(exceptionSpec.begin(), exceptionSpec.end(), exceptionCheck) == exceptionSpec.end())
{
const string msg = "'" + actualTag + " " + name + "': this exception is not listed in " +
"(or a sub-exception of) this operation's exception specification";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sentence is not grammatically correct.

// Check if this is a duplicate tag. If it is, ignore it and issue a warning.
if (comment._parameters.count(name) != 0)
{
const string msg = "ignoring duplicate doc-comment tag: '" + paramTag + " " + name + "'";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const string msg = "ignoring duplicate doc-comment tag: '" + paramTag + " " + name + "'";
const string msg = "duplicate doc-comment tag: '" + paramTag + " " + name + "'";

Comment on lines +589 to +590
const string msg = "'" + actualTag + " " + name + "': this exception is not listed in " +
"(or a sub-exception of) this operation's exception specification";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like:

const string msg = "'" + actualTag + " " + name +
"': this exception is neither listed in nor derived from any exception in the operation's exception specification";

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 this pull request may close these issues.

3 participants