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

Reformat code #14386

Merged
merged 1 commit into from
Jun 24, 2024
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 @@ -168,4 +168,4 @@ public void NoPropertyDeclarationOrDereference_Passes(string text)
test['false']
]
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void AddCodeFix(TextSpan span, string replacement, string description)
private static bool TryGetValidIdentifierToken(SyntaxBase syntax, [NotNullWhen(true)] out string? validToken)
{
if (syntax is StringSyntax stringSyntax &&
stringSyntax.TryGetLiteralValue() is {} literalValue)
stringSyntax.TryGetLiteralValue() is { } literalValue)
{
if (Lexer.IsValidIdentifier(literalValue) &&
// exclude non-contextual keywords like 'nul and 'true' - see https://github.com/Azure/bicep/issues/13347.
Expand Down
4 changes: 2 additions & 2 deletions src/Bicep.Core/Analyzers/Linter/Rules/UseSafeAccessRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override IEnumerable<IDiagnostic> AnalyzeInternal(SemanticModel model, Di
{
foreach (var ternary in SyntaxAggregator.AggregateByType<TernaryOperationSyntax>(model.Root.Syntax))
{
if (SemanticModelHelper.TryGetNamedFunction(model, SystemNamespaceType.BuiltInName, "contains", ternary.ConditionExpression) is not {} functionCall ||
if (SemanticModelHelper.TryGetNamedFunction(model, SystemNamespaceType.BuiltInName, "contains", ternary.ConditionExpression) is not { } functionCall ||
functionCall.Arguments.Length != 2)
{
continue;
Expand Down Expand Up @@ -60,4 +60,4 @@ public override IEnumerable<IDiagnostic> AnalyzeInternal(SemanticModel model, Di
CoreResources.UseSafeAccessRule_MessageFormat);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Bicep.Core/Syntax/SyntaxFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public static ArrayAccessSyntax CreateArrayAccess(SyntaxBase @base, bool safe, S
=> new(@base, LeftSquareToken, safe ? QuestionToken : null, accessExpression, RightSquareToken);

public static SyntaxBase CreateSafeAccess(SyntaxBase @base, SyntaxBase accessExpression)
=> (accessExpression is StringSyntax stringAccess && stringAccess.TryGetLiteralValue() is {} stringValue) ?
=> (accessExpression is StringSyntax stringAccess && stringAccess.TryGetLiteralValue() is { } stringValue) ?
CreatePropertyAccess(@base, true, stringValue) :
CreateArrayAccess(@base, true, accessExpression);

Expand Down
11 changes: 6 additions & 5 deletions src/Bicep.Decompiler/TemplateConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ private SyntaxBase ParseJToken(JToken? value)
};

private SyntaxBase ParseJTokenExpression(JTokenExpression expression)
=> expression.Value switch {
=> expression.Value switch
{
// we don't want to parse expressions inside an expression - e.g. "[concat('[concat()]')]"
JValue value => ParseJValue(value, permitExpressions: false),
_ => throw new NotImplementedException($"Unrecognized expression {ExpressionsEngine.SerializeExpression(expression)}"),
Expand Down Expand Up @@ -716,10 +717,10 @@ private static ExpressionSyntax ParseIntegerJToken(JValue value)
private SyntaxBase ParseJValue(JValue value, bool permitExpressions)
=> value.Type switch
{
JTokenType.String or
JTokenType.Uri or
JTokenType.Date => permitExpressions ?
ParseString(value.ToString(CultureInfo.InvariantCulture), value) :
JTokenType.String or
JTokenType.Uri or
JTokenType.Date => permitExpressions ?
ParseString(value.ToString(CultureInfo.InvariantCulture), value) :
SyntaxFactory.CreateStringLiteral(value.ToString(CultureInfo.InvariantCulture)),
JTokenType.Float => SyntaxFactory.CreateFunctionCall("json",
SyntaxFactory.CreateStringLiteral(value.ToString(CultureInfo.InvariantCulture))),
Expand Down
Loading