Skip to content

Commit

Permalink
Fix dangling doc comments in structures (smithy-lang#1776)
Browse files Browse the repository at this point in the history
Due to differences in how structures are parsed vs lists and maps,
dangling doc comments were not being handled properly on structure
shapes. Our tests were only verifying the behavior for maps, so it
wasn't caught initially. With these changes, proper warnings are
emitted when there are dangling doc comments in a structure shape.
  • Loading branch information
milesziemer authored and Steven Yuan committed Aug 11, 2023
1 parent b372f11 commit 2fd4d3d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,10 @@ private void parseMember(LoadOperation.DefineShape operation, Set<String> define
if (tokenizer.getCurrentToken() == IdlToken.RBRACE) {
if (memberTraits.size() == 1
&& memberTraits.get(0).getTraitType() == IdlTraitParser.TraitType.DOC_COMMENT) {
IdlTraitParser.Result danglingDocComment = memberTraits.get(0);
SourceLocation sourceLocation = danglingDocComment.getValue().getSourceLocation();
String value = danglingDocComment.getValue().toString();
emit(LoaderUtils.emitBadDocComment(sourceLocation, value));
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
[WARNING] -: Found documentation comments ('///') attached to nothing. Documentation comments must appear on their own lines, directly before shapes and members, and before any traits. The invalid comments were: Invalid 3 (before use) | Model.BadDocumentationComment
[WARNING] -: Found documentation comments ('///') attached to nothing. Documentation comments must appear on their own lines, directly before shapes and members, and before any traits. The invalid comments were: Invalid 4 (inside trait)\nInvalid 5 (not before traits)\nValid docs for Foo | Model.BadDocumentationComment
[WARNING] -: Found documentation comments ('///') attached to nothing. Documentation comments must appear on their own lines, directly before shapes and members, and before any traits. The invalid comments were: Invalid 6 (not before traits)\nInvalid 7 (inside shape line)\nInvalid 8 (dangling) | Model.BadDocumentationComment
[WARNING] -: Found documentation comments ('///') attached to nothing. Documentation comments must appear on their own lines, directly before shapes and members, and before any traits. The invalid comments were: Invalid 9 (dangling) | Model.BadDocumentationComment
[WARNING] -: Found documentation comments ('///') attached to nothing. Documentation comments must appear on their own lines, directly before shapes and members, and before any traits. The invalid comments were: Invalid 9 (not before traits)\nInvalid 10 (dangling) | Model.BadDocumentationComment
[WARNING] -: Found documentation comments ('///') attached to nothing. Documentation comments must appear on their own lines, directly before shapes and members, and before any traits. The invalid comments were: Invalid 11 (dangling) | Model.BadDocumentationComment
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ map Foo
/// Invalid 8 (dangling)
}

/// Invalid 9 (dangling)
structure Bar {
@required
/// Invalid 9 (not before traits)
baz: Boolean
/// Invalid 10 (dangling)
}

/// Invalid 11 (dangling)

0 comments on commit 2fd4d3d

Please sign in to comment.