Skip to content

Commit

Permalink
chore: Use collection expression (#14318)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meir017 authored Jun 13, 2024
1 parent 2a38b06 commit eae676e
Show file tree
Hide file tree
Showing 201 changed files with 1,092 additions and 1,200 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ dotnet_diagnostic.IDE0005.severity = none
# Private member is unused
dotnet_diagnostic.IDE0051.severity = warning

# Use collection expression for array
dotnet_diagnostic.IDE0300.severity = warning
dotnet_style_prefer_collection_expression = true
# Use collection expression for empty
dotnet_diagnostic.IDE0301.severity = warning
# Use collection expression for stackalloc
dotnet_diagnostic.IDE0302.severity = warning
# Use collection expression for `Create()
dotnet_diagnostic.IDE0303.severity = warning
# Use collection expression for builder
dotnet_diagnostic.IDE0304.severity = warning
# Use collection expression for fluent
dotnet_diagnostic.IDE0305.severity = warning

# Unused local variables
dotnet_diagnostic.CA1804.severity = warning
# Private methods that are not called from any other code
Expand Down
18 changes: 9 additions & 9 deletions src/Bicep.Cli.IntegrationTests/BuildCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public async Task Build_Valid_SingleFile_WithProviderDeclarationStatement(
.AddSingleton(settings.ClientFactory)
.AddSingleton(settings.TemplateSpecRepositoryFactory);
})
.RunAsync(new[] { "build", bicepFilePath }, CancellationToken.None));
.RunAsync(["build", bicepFilePath], CancellationToken.None));

// ASSERT
// 6. assert 'bicep build' completed successfully
Expand Down Expand Up @@ -411,9 +411,9 @@ public async Task Build_WithNonExistentOutDir_ShouldFail_WithExpectedErrorMessag
error.Should().MatchRegex(@"The specified output directory "".*outputdir"" does not exist");
}

[DataRow(new string[] { })]
[DataRow(new[] { "--diagnostics-format", "defAULt" })]
[DataRow(new[] { "--diagnostics-format", "sArif" })]
[DataRow([])]
[DataRow(["--diagnostics-format", "defAULt"])]
[DataRow(["--diagnostics-format", "sArif"])]
[DataTestMethod]
public async Task Build_WithOutDir_ShouldSucceed(string[] args)
{
Expand All @@ -429,7 +429,7 @@ public async Task Build_WithOutDir_ShouldSucceed(string[] args)
var expectedOutputFile = Path.Combine(outputFileDir, "input.json");

File.Exists(expectedOutputFile).Should().BeFalse();
var (output, error, result) = await Bicep(new[] { "build", "--outdir", outputFileDir, bicepPath }.Concat(args).ToArray());
var (output, error, result) = await Bicep(["build", "--outdir", outputFileDir, bicepPath, .. args]);

File.Exists(expectedOutputFile).Should().BeTrue();
output.Should().BeEmpty();
Expand Down Expand Up @@ -477,7 +477,7 @@ public async Task Build_WithOutDir_ShouldSucceed(string[] args)
[DataTestMethod]
public async Task Build_InvalidInputPaths_ShouldProduceExpectedError(string badPath, string[] args, string expectedErrorRegex)
{
var (output, error, result) = await Bicep(new[] { "build" }.Concat(args).Append(badPath).ToArray());
var (output, error, result) = await Bicep(["build", .. args, badPath]);

result.Should().Be(1);
output.Should().BeEmpty();
Expand Down Expand Up @@ -544,8 +544,8 @@ public async Task Build_WithInvalidBicepConfig_ShouldProduceConfigurationError()
error.Should().StartWith($"{inputFile}(1,1) : Error BCP271: Failed to parse the contents of the Bicep configuration file \"{configurationPath}\" as valid JSON: Expected depth to be zero at the end of the JSON payload. There is an open JSON object or array that should be closed. LineNumber: 8 | BytePositionInLine: 0.");
}

[DataRow(new string[] { })]
[DataRow(new[] { "--diagnostics-format", "defAULt" })]
[DataRow([])]
[DataRow(["--diagnostics-format", "defAULt"])]
[DataTestMethod]
public async Task Build_WithValidBicepConfig_ShouldProduceOutputFileAndExpectedError(string[] args)
{
Expand Down Expand Up @@ -574,7 +574,7 @@ public async Task Build_WithValidBicepConfig_ShouldProduceOutputFileAndExpectedE
var expectedOutputFile = Path.Combine(testOutputPath, "main.json");

File.Exists(expectedOutputFile).Should().BeFalse();
var (output, error, result) = await Bicep(new[] { "build", "--outdir", testOutputPath, inputFile }.Concat(args).ToArray());
var (output, error, result) = await Bicep(["build", "--outdir", testOutputPath, inputFile, .. args]);

File.Exists(expectedOutputFile).Should().BeTrue();
result.Should().Be(0);
Expand Down
8 changes: 4 additions & 4 deletions src/Bicep.Cli.IntegrationTests/BuildParamsCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,9 @@ public async Task Build_bicepparam_should_fail_with_error_diagnostics_for_regist
result.Stderr.Should().Contain("main.bicepparam(1,7) : Error BCP192: Unable to restore the artifact with reference \"br:mockregistry.io/parameters/basic:v1\": Mock registry request failure.");
}

[DataRow(new string[] { })]
[DataRow(new[] { "--diagnostics-format", "defAULt" })]
[DataRow(new[] { "--diagnostics-format", "sArif" })]
[DataRow([])]
[DataRow(["--diagnostics-format", "defAULt"])]
[DataRow(["--diagnostics-format", "sArif"])]
[TestMethod]
public async Task BuildParams_supports_sarif_diagnostics_format(string[] args)
{
Expand All @@ -459,7 +459,7 @@ param unusedParam int
var expectedOutputFile = FileHelper.GetResultFilePath(TestContext, "main.json", outputPath);

File.Exists(expectedOutputFile).Should().BeFalse();
var (output, error, result) = await Bicep(new[] { "build-params", inputFile }.Concat(args).ToArray());
var (output, error, result) = await Bicep(["build-params", inputFile, .. args]);

File.Exists(expectedOutputFile).Should().BeTrue();
output.Should().BeEmpty();
Expand Down
6 changes: 3 additions & 3 deletions src/Bicep.Cli.IntegrationTests/DecompileCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public class DecompileCommandTests : TestBase
}
}";

private readonly string[] DecompilationDisclaimer = new[]
{
private readonly string[] DecompilationDisclaimer =
[
"WARNING: Decompilation is a best-effort process, as there is no guaranteed mapping from ARM JSON to Bicep Template or Bicep Parameters.",
"You may need to fix warnings and errors in the generated bicep/bicepparam file(s), or decompilation may fail entirely if an accurate conversion is not possible.",
"If you would like to report any issues or inaccurate conversions, please see https://github.com/Azure/bicep/issues."
};
];


[TestMethod]
Expand Down
6 changes: 3 additions & 3 deletions src/Bicep.Cli.IntegrationTests/DecompileParamsCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ namespace Bicep.Cli.IntegrationTests
[TestClass]
public class DecompileParamsCommandTests : TestBase
{
private readonly string[] DecompilationDisclaimer = new[]
{
private readonly string[] DecompilationDisclaimer =
[
"WARNING: Decompilation is a best-effort process, as there is no guaranteed mapping from ARM JSON to Bicep Template or Bicep Parameters.",
"You may need to fix warnings and errors in the generated bicep/bicepparam file(s), or decompilation may fail entirely if an accurate conversion is not possible.",
"If you would like to report any issues or inaccurate conversions, please see https://github.com/Azure/bicep/issues."
};
];


[TestMethod]
Expand Down
28 changes: 14 additions & 14 deletions src/Bicep.Cli.IntegrationTests/JsonRpcCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,20 @@ await RunServerTest(
async (client, token) =>
{
var response = await client.GetMetadata(new("/main.bicep"), token);
response.Metadata.Should().Equal(new GetMetadataResponse.MetadataDefinition[] {
response.Metadata.Should().Equal([
new("description", "my file"),
});
response.Parameters.Should().Equal(new GetMetadataResponse.SymbolDefinition[] {
]);
response.Parameters.Should().Equal([
new(new(new(2, 0), new(3, 16)), "foo", new(null, "string"), "foo param"),
new(new(new(5, 0), new(7, 1)), "inlineType", new(null, "{ sdf: string }"), null),
new(new(new(9, 0), new(9, 23)), "declaredType", new(new(new(11, 0), new(15, 1)), "asdf"), null),
});
response.Outputs.Should().Equal(new GetMetadataResponse.SymbolDefinition[] {
]);
response.Outputs.Should().Equal([
new(new(new(17, 0), new(18, 23)), "bar", new(null, "string"), "bar output"),
});
response.Exports.Should().Equal(new GetMetadataResponse.ExportDefinition[] {
]);
response.Exports.Should().Equal([
new(new(new(11, 0), new(15, 1)), "asdf", "TypeAlias", "asdf type"),
});
]);
});
}

Expand Down Expand Up @@ -176,15 +176,15 @@ await RunServerTest(
async (client, token) =>
{
var response = await client.GetDeploymentGraph(new("/main.bicep"), token);
response.Nodes.Should().Equal(new GetDeploymentGraphResponse.Node[] {
response.Nodes.Should().Equal([
new(new(new(4, 0), new(7, 1)), "bar", "My.Rp/foo", true, null),
new(new(new(9, 0), new(12, 1)), "baz", "My.Rp/foo", false, null),
new(new(new(0, 0), new(2, 1)), "foo", "My.Rp/foo", false, null),
});
response.Edges.Should().Equal(new GetDeploymentGraphResponse.Edge[] {
]);
response.Edges.Should().Equal([
new("bar", "foo"),
new("baz", "bar"),
});
]);
});
}

Expand Down Expand Up @@ -218,13 +218,13 @@ await RunServerTest(
{
var response = await client.GetFileReferences(new("/main.bicepparam"), token);

response.FilePaths.Should().Equal(new[] {
response.FilePaths.Should().Equal([
"/bicepconfig.json",
"/invalid.txt",
"/main.bicep",
"/main.bicepparam",
"/valid.txt",
});
]);
});
}
}
8 changes: 4 additions & 4 deletions src/Bicep.Cli.IntegrationTests/PublishCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public async Task Publish_AllValidDataSets_ShouldSucceed(string testName, DataSe
requiredArgs.Add("--with-source");
}

string[] args = requiredArgs.ToArray();
string[] args = [.. requiredArgs];

var (output, error, result) = await Bicep(settings, args);
result.Should().Be(0);
Expand Down Expand Up @@ -219,14 +219,14 @@ public async Task Publish_AllValidDataSets_ShouldSucceed(string testName, DataSe

// publish the same content again with --force
requiredArgs.Add("--force");
var (output3, error3, result3) = await Bicep(settings, requiredArgs.ToArray());
var (output3, error3, result3) = await Bicep(settings, [.. requiredArgs]);
result3.Should().Be(0);
output3.Should().BeEmpty();
AssertNoErrors(error3);

// compile to get what the new expected main.json should be
List<string> buildArgs = new() { "build", bicepFilePath, "--outfile", $"{compiledFilePath}.modified" };
var (output4, error4, result4) = await Bicep(settings, buildArgs.ToArray());
var (output4, error4, result4) = await Bicep(settings, [.. buildArgs]);
result4.Should().Be(0);
output4.Should().BeEmpty();
AssertNoErrors(error4);
Expand Down Expand Up @@ -320,7 +320,7 @@ public async Task Publish_ValidArmTemplateFile_WithSource_ShouldFail()
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), clientFactory, templateSpecRepositoryFactory);

var args = new List<string> { "publish", compiledFilePath, "--target", $"br:{registryStr}/{repository}:v1", "--with-source" };
var (output, error, result) = await Bicep(settings, args.ToArray());
var (output, error, result) = await Bicep(settings, [.. args]);
result.Should().Be(1);
output.Should().BeEmpty();
error.Should().MatchRegex("Cannot publish with source when the target is an ARM template file.");
Expand Down
6 changes: 3 additions & 3 deletions src/Bicep.Cli.IntegrationTests/PublishProviderCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task Publish_provider_should_succeed()

List<string> requiredArgs = new() { "publish-provider", indexPath, "--target", $"br:{registryStr}/{repository}:{version}" };

string[] args = requiredArgs.ToArray();
string[] args = [.. requiredArgs];

var result = await Bicep(settings, args);
result.Should().Succeed().And.NotHaveStdout();
Expand All @@ -62,13 +62,13 @@ public async Task Publish_provider_should_succeed()
saBodyType.Properties.Keys.Should().Contain("name", "location", "properties", "sku", "tags");

// publishing without --force should fail
result = await Bicep(settings, requiredArgs.ToArray());
result = await Bicep(settings, [.. requiredArgs]);
result.Should().Fail().And.HaveStderrMatch("*The Provider \"*\" already exists. Use --force to overwrite the existing provider.*");

// test with force
requiredArgs.Add("--force");

var result2 = await Bicep(settings, requiredArgs.ToArray());
var result2 = await Bicep(settings, [.. requiredArgs]);
result2.Should().Succeed().And.NotHaveStdout();

// verify the provider was published
Expand Down
Loading

0 comments on commit eae676e

Please sign in to comment.