Skip to content
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

Place BCP132 on the last dangling decorator #1407

Merged
merged 1 commit into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ var partialObject = {
xxxxx


// BCP132 should be on the line below the decorator
@minLength()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,10 @@ xxxxx
//@[0:5) [BCP007 (Error)] This declaration type is not recognized. Specify a parameter, variable, resource, or output declaration. |xxxxx|


// BCP132 should be on the line below the decorator
@minLength()
//@[0:12) [BCP132 (Error)] Expected a declaration after the decorator. |@minLength()|


//@[0:0) [BCP132 (Error)] Expected a declaration after the decorator. ||



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,4 @@ var partialObject = {
@sys.secure()
xxxxx

// BCP132 should be on the line below the decorator
@minLength()
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ var partialObject = {
xxxxx


// BCP132 should be on the line below the decorator
@minLength()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2527,8 +2527,6 @@ xxxxx
//@[5:8) NewLine |\n\n\n|


// BCP132 should be on the line below the decorator
//@[51:52) NewLine |\n|
@minLength()
//@[0:21) MissingDeclarationSyntax
//@[0:12) DecoratorSyntax
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1578,8 +1578,6 @@ xxxxx
//@[5:8) NewLine |\n\n\n|


// BCP132 should be on the line below the decorator
//@[51:52) NewLine |\n|
@minLength()
//@[0:1) At |@|
//@[1:10) Identifier |minLength|
Expand Down
9 changes: 3 additions & 6 deletions src/Bicep.Core/Parsing/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,12 @@ public ProgramSyntax Program()
declarationOrToken is MissingDeclarationSyntax missingDeclaration &&
!missingDeclaration.HasParseErrors())
{
// If there are dangling decorators and we hit EOF, ask users to add a declration.
// Set the span of the diagnostic so that it's on the line below the last decorator.
var lastNewLine = missingDeclaration.LeadingNodes.Last(node => node is Token { Type: TokenType.NewLine });
var diagnosticSpan = new TextSpan(lastNewLine.Span.Position + 2, 0);

// If there are dangling decorators and we hit EOF and there's no other decorator parsing error,
// ask users to add a declration.
var skippedTriviaSyntax = new SkippedTriviaSyntax(
reader.Peek().Span,
Enumerable.Empty<SyntaxBase>(),
DiagnosticBuilder.ForPosition(diagnosticSpan).ExpectDeclarationAfterDecorator().AsEnumerable());
DiagnosticBuilder.ForPosition(missingDeclaration.Decorators.Last()).ExpectDeclarationAfterDecorator().AsEnumerable());

declarationsOrTokens.Add(skippedTriviaSyntax);
}
Expand Down