Skip to content

Commit

Permalink
Update use-stable-resource-identifiers linter rule to support multipl…
Browse files Browse the repository at this point in the history
…e violations on the same root (Azure#7910)
  • Loading branch information
jeskew authored Aug 9, 2022
1 parent 57d74bb commit 359458d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@ param snap string
"Resource identifiers should be reproducible outside of their initial deployment context. Resource storage's 'name' identifier is potentially nondeterministic due to its use of the 'utcNow' function (storage.name -> pop -> snap (default value) -> utcNow('F')).",
"Resource identifiers should be reproducible outside of their initial deployment context. Resource storage's 'name' identifier is potentially nondeterministic due to its use of the 'utcNow' function (storage.name -> pop -> crackle -> snap (default value) -> utcNow('F'))."
)]
[DataRow(@"
param location string = resourceGroup().location
param snap string = '${newGuid()}${newGuid()}${utcNow('u')}'
var crackle = snap
var pop = '${snap}${crackle}'
resource storage 'Microsoft.Storage/storageAccounts@2021-09-01' = {
name: pop
location: location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
}",
"Resource identifiers should be reproducible outside of their initial deployment context. Resource storage's 'name' identifier is potentially nondeterministic due to its use of the 'newGuid' function (storage.name -> pop -> snap (default value) -> newGuid()).",
"Resource identifiers should be reproducible outside of their initial deployment context. Resource storage's 'name' identifier is potentially nondeterministic due to its use of the 'newGuid' function (storage.name -> pop -> snap (default value) -> newGuid()).",
"Resource identifiers should be reproducible outside of their initial deployment context. Resource storage's 'name' identifier is potentially nondeterministic due to its use of the 'utcNow' function (storage.name -> pop -> snap (default value) -> utcNow('u')).",
"Resource identifiers should be reproducible outside of their initial deployment context. Resource storage's 'name' identifier is potentially nondeterministic due to its use of the 'newGuid' function (storage.name -> pop -> crackle -> snap (default value) -> newGuid()).",
"Resource identifiers should be reproducible outside of their initial deployment context. Resource storage's 'name' identifier is potentially nondeterministic due to its use of the 'newGuid' function (storage.name -> pop -> crackle -> snap (default value) -> newGuid()).",
"Resource identifiers should be reproducible outside of their initial deployment context. Resource storage's 'name' identifier is potentially nondeterministic due to its use of the 'utcNow' function (storage.name -> pop -> crackle -> snap (default value) -> utcNow('u'))."
)]
[DataTestMethod]
public void TestRule(string text, params string[] expectedMessages)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ private class Visitor : SyntaxVisitor
"utcNow",
};
private readonly SemanticModel model;
private readonly Dictionary<string, string> pathsToNonDeterministicFunctionsUsed = new();
private readonly List<(string, string)> pathsToNonDeterministicFunctionsUsed = new();
private readonly LinkedList<Symbol> pathSegments = new();

internal Visitor(SemanticModel model)
{
this.model = model;
}

internal IEnumerable<KeyValuePair<string, string>> PathsToNonDeterministicFunctionsUsed => pathsToNonDeterministicFunctionsUsed;
internal IEnumerable<(string path, string functionName)> PathsToNonDeterministicFunctionsUsed => pathsToNonDeterministicFunctionsUsed;

public override void VisitFunctionCallSyntax(FunctionCallSyntax syntax)
{
if (NonDeterministicFunctionNames.Contains(syntax.Name.IdentifierName))
{
pathsToNonDeterministicFunctionsUsed.Add(FormatPath(syntax.ToText()), syntax.Name.IdentifierName);
pathsToNonDeterministicFunctionsUsed.Add((FormatPath(syntax.ToText()), syntax.Name.IdentifierName));
}
base.VisitFunctionCallSyntax(syntax);
}
Expand Down

0 comments on commit 359458d

Please sign in to comment.