Skip to content
Open
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
19 changes: 11 additions & 8 deletions src/Bicep.Core.IntegrationTests/UserDefinedTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public void Masked_types_still_accessible_via_qualified_reference()
");

result.Should().HaveDiagnostics(new[] {
("no-unused-types", DiagnosticLevel.Warning, "Type \"string\" is declared but never used."),
("no-unused-params", DiagnosticLevel.Warning, "Parameter \"stringParam\" is declared but never used."),
});
}
Expand Down Expand Up @@ -153,8 +154,10 @@ param intParam constrainedInt
result.Should().HaveDiagnostics(new[] {
("BCP308", DiagnosticLevel.Error, "The decorator \"minLength\" may not be used on statements whose declared type is a reference to a user-defined type."),
("BCP308", DiagnosticLevel.Error, "The decorator \"maxLength\" may not be used on statements whose declared type is a reference to a user-defined type."),
("no-unused-types", DiagnosticLevel.Warning, "Type \"constrainedStringAlias\" is declared but never used."),
("BCP308", DiagnosticLevel.Error, "The decorator \"minValue\" may not be used on statements whose declared type is a reference to a user-defined type."),
("BCP308", DiagnosticLevel.Error, "The decorator \"maxValue\" may not be used on statements whose declared type is a reference to a user-defined type."),
("no-unused-types", DiagnosticLevel.Warning, "Type \"constrainedIntAlias\" is declared but never used."),
("BCP308", DiagnosticLevel.Error, "The decorator \"minLength\" may not be used on statements whose declared type is a reference to a user-defined type."),
("BCP308", DiagnosticLevel.Error, "The decorator \"maxLength\" may not be used on statements whose declared type is a reference to a user-defined type."),
("BCP308", DiagnosticLevel.Error, "The decorator \"secure\" may not be used on statements whose declared type is a reference to a user-defined type."),
Expand Down Expand Up @@ -529,7 +532,7 @@ param constrainedString string?
param sealedObject {}?
");

result.Should().NotHaveAnyDiagnostics();
result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics();
}

[TestMethod]
Expand Down Expand Up @@ -746,7 +749,7 @@ public void Union_types_with_single_normalized_member_compile_without_error()
type union = 'a' | 'a'
""");

result.Should().NotHaveAnyDiagnostics();
result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics();

result.Template.Should().NotBeNull();
result.Template!.Should().HaveValueAtPath("definitions.union", JToken.Parse("""
Expand All @@ -765,7 +768,7 @@ public void Nullable_union_types_do_not_include_null_in_allowed_values_constrain
type unionWithOneMember = null | 'a'
""");

result.Should().NotHaveAnyDiagnostics();
result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics();

result.Template.Should().NotBeNull();
result.Template!.Should().HaveValueAtPath("definitions.union", JToken.Parse("""
Expand Down Expand Up @@ -1201,7 +1204,7 @@ public void Invalid_type_property_access_raises_diagnostic(string accessExpressi
type test2 = {{accessExpression}}
""");

result.Should().HaveDiagnostics(new[]
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
{
(expectedErrorCode, DiagnosticLevel.Error, expectedErrorMessage),
});
Expand Down Expand Up @@ -1308,7 +1311,7 @@ public void Invalid_type_index_access_raises_diagnostic(string accessExpression,
type test2 = {{accessExpression}}
""");

result.Should().HaveDiagnostics(new[]
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
{
(expectedErrorCode, DiagnosticLevel.Error, expectedErrorMessage),
});
Expand Down Expand Up @@ -1377,7 +1380,7 @@ public void Invalid_additional_properties_access_raises_diagnostic(string access
type test2 = {{accessExpression}}
""");

result.Should().HaveDiagnostics(new[]
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
{
(expectedErrorCode, DiagnosticLevel.Error, expectedErrorMessage),
});
Expand Down Expand Up @@ -1487,7 +1490,7 @@ public void Invalid_type_items_access_raises_diagnostic(string accessExpression,
type test2 = {{accessExpression}}
""");

result.Should().HaveDiagnostics(new[]
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
{
(expectedErrorCode, DiagnosticLevel.Error, expectedErrorMessage),
});
Expand Down Expand Up @@ -1654,7 +1657,7 @@ public void Parameterized_types_should_require_parameterization()
new ServiceBuilder().WithFeatureOverrides(new(TestContext)),
"""type t = resourceInput""");

result.Should().HaveDiagnostics([
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics([
("BCP384", DiagnosticLevel.Error, """The "resourceInput<ResourceTypeIdentifier>" type requires 1 argument(s)."""),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var aliasedBar = mod2.foo
//@[04:14) [no-unused-vars (Warning)] Variable "aliasedBar" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-vars) |aliasedBar|

type fizzes = fizz[]
//@[05:11) [no-unused-types (Warning)] Type "fizzes" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |fizzes|

param fizzParam mod2.fizz
//@[06:15) [no-unused-params (Warning)] Parameter "fizzParam" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-params) |fizzParam|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,60 @@
type invalid1 = resourceInput
//@[005:013) [no-unused-types (Warning)] Type "invalid1" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |invalid1|
//@[016:029) [BCP384 (Error)] The "resourceInput<ResourceTypeIdentifier>" type requires 1 argument(s). (bicep https://aka.ms/bicep/core-diagnostics#BCP384) |resourceInput|

type invalid2 = resourceInput<>
//@[005:013) [no-unused-types (Warning)] Type "invalid2" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |invalid2|
//@[029:031) [BCP071 (Error)] Expected 1 argument, but got 0. (bicep https://aka.ms/bicep/core-diagnostics#BCP071) |<>|

type invalid3 = resourceInput<'abc', 'def'>
//@[005:013) [no-unused-types (Warning)] Type "invalid3" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |invalid3|
//@[029:043) [BCP071 (Error)] Expected 1 argument, but got 2. (bicep https://aka.ms/bicep/core-diagnostics#BCP071) |<'abc', 'def'>|
type invalid4 = resourceInput<hello>
//@[005:013) [no-unused-types (Warning)] Type "invalid4" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |invalid4|
//@[030:035) [BCP070 (Error)] Argument of type "{ bar: Astronomer.Astro/organizations }" is not assignable to parameter of type "string". (bicep https://aka.ms/bicep/core-diagnostics#BCP070) |hello|
type invalid5 = resourceInput<'Microsoft.Storage/storageAccounts'>
//@[005:013) [no-unused-types (Warning)] Type "invalid5" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |invalid5|
//@[030:065) [BCP029 (Error)] The resource type is not valid. Specify a valid resource type of format "<type-name>@<apiVersion>". (bicep https://aka.ms/bicep/core-diagnostics#BCP029) |'Microsoft.Storage/storageAccounts'|
type invalid6 = resourceInput<'Microsoft.Storage/storageAccounts@'>
//@[005:013) [no-unused-types (Warning)] Type "invalid6" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |invalid6|
//@[030:066) [BCP029 (Error)] The resource type is not valid. Specify a valid resource type of format "<type-name>@<apiVersion>". (bicep https://aka.ms/bicep/core-diagnostics#BCP029) |'Microsoft.Storage/storageAccounts@'|
type invalid7 = resourceInput<'Microsoft.Storage/storageAccounts@hello'>
//@[005:013) [no-unused-types (Warning)] Type "invalid7" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |invalid7|
//@[030:071) [BCP029 (Error)] The resource type is not valid. Specify a valid resource type of format "<type-name>@<apiVersion>". (bicep https://aka.ms/bicep/core-diagnostics#BCP029) |'Microsoft.Storage/storageAccounts@hello'|
type invalid8 = resourceInput<'notARealNamespace:Microsoft.Storage/storageAccounts@2022-09-01'>
//@[005:013) [no-unused-types (Warning)] Type "invalid8" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |invalid8|
//@[030:094) [BCP208 (Error)] The specified namespace "notARealNamespace" is not recognized. Specify a resource reference using one of the following namespaces: "az", "sys". (bicep https://aka.ms/bicep/core-diagnostics#BCP208) |'notARealNamespace:Microsoft.Storage/storageAccounts@2022-09-01'|
type invalid9 = resourceInput<':Microsoft.Storage/storageAccounts@2022-09-01'>
//@[005:013) [no-unused-types (Warning)] Type "invalid9" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |invalid9|
//@[030:077) [BCP029 (Error)] The resource type is not valid. Specify a valid resource type of format "<type-name>@<apiVersion>". (bicep https://aka.ms/bicep/core-diagnostics#BCP029) |':Microsoft.Storage/storageAccounts@2022-09-01'|
type invalid10 = resourceInput<'abc' 'def'>
//@[005:014) [no-unused-types (Warning)] Type "invalid10" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |invalid10|
//@[030:043) [BCP071 (Error)] Expected 1 argument, but got 2. (bicep https://aka.ms/bicep/core-diagnostics#BCP071) |<'abc' 'def'>|
//@[037:037) [BCP236 (Error)] Expected a new line or comma character at this location. (bicep https://aka.ms/bicep/core-diagnostics#BCP236) ||
type invalid11 = resourceInput<123>
//@[005:014) [no-unused-types (Warning)] Type "invalid11" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |invalid11|
//@[031:034) [BCP070 (Error)] Argument of type "123" is not assignable to parameter of type "string". (bicep https://aka.ms/bicep/core-diagnostics#BCP070) |123|
type invalid12 = resourceInput<resourceGroup()>
//@[005:014) [no-unused-types (Warning)] Type "invalid12" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |invalid12|
//@[030:047) [BCP071 (Error)] Expected 1 argument, but got 2. (bicep https://aka.ms/bicep/core-diagnostics#BCP071) |<resourceGroup()>|
//@[044:044) [BCP236 (Error)] Expected a new line or comma character at this location. (bicep https://aka.ms/bicep/core-diagnostics#BCP236) ||
//@[045:045) [BCP243 (Error)] Parentheses must contain exactly one expression. (bicep https://aka.ms/bicep/core-diagnostics#BCP243) ||

type thisIsWeird = resourceInput</*
//@[005:016) [no-unused-types (Warning)] Type "thisIsWeird" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |thisIsWeird|
//@[019:098) [BCP394 (Error)] Resource-derived type expressions must dereference a property within the resource body. Using the entire resource body type is not permitted. (bicep https://aka.ms/bicep/core-diagnostics#BCP394) |resourceInput</*\n*/'Astronomer.Astro/organizations@2023-08-01-preview'\n/// >\n>|
*/'Astronomer.Astro/organizations@2023-08-01-preview'
/// >
>

type interpolated = resourceInput<'Microsoft.${'Storage'}/storageAccounts@2022-09-01'>
//@[005:017) [no-unused-types (Warning)] Type "interpolated" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |interpolated|
//@[034:085) [BCP032 (Error)] The value must be a compile-time constant. (bicep https://aka.ms/bicep/core-diagnostics#BCP032) |'Microsoft.${'Storage'}/storageAccounts@2022-09-01'|

@sealed()
//@[000:009) [BCP386 (Error)] The decorator "sealed" may not be used on statements whose declared type is a reference to a resource-derived type. (bicep https://aka.ms/bicep/core-diagnostics#BCP386) |@sealed()|
type shouldNotBeSealable = resourceInput<'Microsoft.Storage/storageAccounts@2022-09-01'>
//@[005:024) [no-unused-types (Warning)] Type "shouldNotBeSealable" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |shouldNotBeSealable|
//@[027:088) [BCP394 (Error)] Resource-derived type expressions must dereference a property within the resource body. Using the entire resource body type is not permitted. (bicep https://aka.ms/bicep/core-diagnostics#BCP394) |resourceInput<'Microsoft.Storage/storageAccounts@2022-09-01'>|

type hello = {
Expand All @@ -50,14 +65,19 @@ type hello = {
}

type typoInPropertyName = resourceInput<'Microsoft.Storage/storageAccounts@2023-01-01'>.nom
//@[005:023) [no-unused-types (Warning)] Type "typoInPropertyName" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |typoInPropertyName|
//@[088:091) [BCP053 (Error)] The type "Microsoft.Storage/storageAccounts" does not contain property "nom". Available properties include "apiVersion", "asserts", "dependsOn", "eTag", "extendedLocation", "id", "identity", "kind", "location", "managedBy", "managedByExtended", "name", "plan", "properties", "scale", "sku", "tags", "type", "zones". (bicep https://aka.ms/bicep/core-diagnostics#BCP053) |nom|
type typoInPropertyName2 = resourceInput<'Microsoft.KeyVault/vaults@2022-07-01'>.properties.accessPolicies[*].tenatId
//@[005:024) [no-unused-types (Warning)] Type "typoInPropertyName2" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |typoInPropertyName2|
//@[110:117) [BCP083 (Error)] The type "AccessPolicyEntry" does not contain property "tenatId". Did you mean "tenantId"? (bicep https://aka.ms/bicep/core-diagnostics#BCP083) |tenatId|
type typoInPropertyName3 = resourceInput<'Microsoft.KeyVault/vaults@2022-07-01'>.properties[*].accessPolicies.tenantId
//@[005:024) [no-unused-types (Warning)] Type "typoInPropertyName3" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |typoInPropertyName3|
//@[091:094) [BCP390 (Error)] The array item type access operator ('[*]') can only be used with typed arrays. (bicep https://aka.ms/bicep/core-diagnostics#BCP390) |[*]|
type typoInPropertyName4 = resourceInput<'Microsoft.Web/customApis@2016-06-01'>.properties.connectionParameters.*.tyype
//@[005:024) [no-unused-types (Warning)] Type "typoInPropertyName4" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |typoInPropertyName4|
//@[114:119) [BCP083 (Error)] The type "ConnectionParameter" does not contain property "tyype". Did you mean "type"? (bicep https://aka.ms/bicep/core-diagnostics#BCP083) |tyype|
type typoInPropertyName5 = resourceInput<'Microsoft.Web/customApis@2016-06-01'>.properties.*.connectionParameters.type
//@[005:024) [no-unused-types (Warning)] Type "typoInPropertyName5" is declared but never used. (bicep core linter https://aka.ms/bicep/linter-diagnostics#no-unused-types) |typoInPropertyName5|
//@[091:092) [BCP389 (Error)] The type "CustomApiPropertiesDefinition" does not declare an additional properties type. (bicep https://aka.ms/bicep/core-diagnostics#BCP389) |*|

module mod 'modules/mod.json' = {
Expand Down
Loading
Loading