-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle operator precedence correctly in
use-safe-access
linter rule…
… codefix (#14710) Handle operator precedence correctly in `use-safe-access` linter rule codefix Closes #14705
- Loading branch information
1 parent
f1a3db5
commit 7ad70af
Showing
5 changed files
with
124 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
namespace Bicep.Core.Parsing; | ||
|
||
public static class TokenTypeHelper | ||
{ | ||
public static int GetOperatorPrecedence(TokenType tokenType) => tokenType switch | ||
{ | ||
// the absolute values are not important here | ||
TokenType.Modulo or | ||
TokenType.Asterisk or | ||
TokenType.Slash => 100, | ||
|
||
TokenType.Plus or | ||
TokenType.Minus => 90, | ||
|
||
TokenType.RightChevron or | ||
TokenType.GreaterThanOrEqual or | ||
TokenType.LeftChevron or | ||
TokenType.LessThanOrEqual => 80, | ||
|
||
TokenType.Equals or | ||
TokenType.NotEquals or | ||
TokenType.EqualsInsensitive or | ||
TokenType.NotEqualsInsensitive => 70, | ||
|
||
// if we add bitwise operators in the future, they should go here | ||
TokenType.LogicalAnd => 50, | ||
TokenType.LogicalOr => 40, | ||
TokenType.DoubleQuestion => 30, | ||
|
||
_ => -1, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters