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

use-resource-symbol-reference linter rule: detect .name access as well as .id #12917

Merged
merged 1 commit into from
Jan 4, 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 @@ -27,6 +27,21 @@ public void Codefix_handles_list_functions_with_reference_based_id_and_apiversio
name: 'stgName'
}

var blah = stg.listKeys().keys
");

[TestMethod]
public void Codefix_handles_list_functions_with_reference_based_name_and_apiversion() => AssertCodeFix(@"
resource stg 'Microsoft.Storage/storageAccounts@2022-09-01' existing = {
name: 'stgName'
}

var blah = listKe|ys(stg.name, stg.apiVersion).keys
", @"
resource stg 'Microsoft.Storage/storageAccounts@2022-09-01' existing = {
name: 'stgName'
}

var blah = stg.listKeys().keys
");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public override IEnumerable<IDiagnostic> AnalyzeInternal(SemanticModel model, Di
private IEnumerable<DeclaredResourceMetadata> AnalyzeResourceId(SemanticModel model, SyntaxBase syntax)
{
if (syntax is PropertyAccessSyntax idProp &&
idProp.PropertyName.NameEquals("id") &&
(idProp.PropertyName.NameEquals("id") || idProp.PropertyName.NameEquals("name")) &&
model.ResourceMetadata.TryLookup(idProp.BaseExpression) is DeclaredResourceMetadata idResource)
{
yield return idResource;
Expand Down
Loading