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

refactor: Use collection expression for array #157

Merged
merged 1 commit into from
Jun 3, 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
8 changes: 4 additions & 4 deletions src/Constants/EnvironmentNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace DotEnv.Core;

internal class EnvironmentNames
{
public static IReadOnlyList<string> Development { get; } = new[] { "development", "dev"};
public static IReadOnlyList<string> Test { get; } = new[] { "test" };
public static IReadOnlyList<string> Staging { get; } = new[] { "staging" };
public static IReadOnlyList<string> Production { get; } = new[] { "production", "prod"};
public static IReadOnlyList<string> Development { get; } = ["development", "dev"];
public static IReadOnlyList<string> Test { get; } = ["test"];
public static IReadOnlyList<string> Staging { get; } = ["staging"];
public static IReadOnlyList<string> Production { get; } = ["production", "prod"];
}
2 changes: 1 addition & 1 deletion src/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal static class StringExtensions
/// <param name="count">The maximum number of elements expected in the array.</param>
/// <returns>An array that contains at most count substrings from this instance that are delimited by separator.</returns>
public static string[] Split(this string str, char separator, int count)
=> str.Split(new[] { separator }, count);
=> str.Split([separator], count);

/// <summary>
/// Determines whether this string instance starts with the specified character.
Expand Down
4 changes: 2 additions & 2 deletions src/Loader/EnvLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public IEnvironmentVariablesProvider LoadEnv(out EnvValidationResult result)
var copyEnvFiles = envFiles.ToArray();
envFiles.Clear();

AddOptionalEnvFiles(environment is not null ? new[] { $".env.{environment}.local" } : new[] { EnvDevelopmentLocalName, EnvDevLocalName });
AddOptionalEnvFiles(environment is not null ? [$".env.{environment}.local"] : [EnvDevelopmentLocalName, EnvDevLocalName]);
AddOptionalEnvFiles(EnvLocalName);
AddOptionalEnvFiles(environment is not null ? new[] { $".env.{environment}" } : new[] { EnvDevelopmentName, EnvDevName });
AddOptionalEnvFiles(environment is not null ? [$".env.{environment}"] : [EnvDevelopmentName, EnvDevName]);
AddOptionalEnvFiles(EnvName);

// The .env files that were added with the 'AddEnvFile' method are added at the end of the collection.
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/EnvParser.ConfigurationMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public IEnvParser AllowOverwriteExistingVars()
public IEnvParser SetCommentChar(char commentChar)
{
_configuration.CommentChar = commentChar;
_configuration.InlineCommentChars = new[] { $" {commentChar}", $"\t{commentChar}" };
_configuration.InlineCommentChars = [$" {commentChar}", $"\t{commentChar}"];
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Parser/EnvParser.HelperMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private bool IsQuoted(string text)
private string RemoveQuotes(string text)
{
_ = text ?? throw new ArgumentNullException(nameof(text));
return text.Trim().Trim(new[] { SingleQuote, DoubleQuote });
return text.Trim().Trim([SingleQuote, DoubleQuote]);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/EnvParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace DotEnv.Core;
/// <inheritdoc cref="IEnvParser" />
public partial class EnvParser : IEnvParser
{
private static readonly string[] s_newLines = new[] { "\r\n", "\n", "\r" };
private static readonly string[] s_newLines = ["\r\n", "\n", "\r"];

private const string ExportPrefix = "export ";
private const char DoubleQuote = '"';
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/EnvParserOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal class EnvParserOptions
/// Gets or sets the characters indicating the beginning of a inline comment
/// that will be used as delimiter in the <see cref="EnvParser.RemoveInlineComment" /> method.
/// </summary>
public string[] InlineCommentChars { get; set; } = new[] { " #", "\t#" };
public string[] InlineCommentChars { get; set; } = [" #", "\t#"];

/// <summary>
/// A character that separates a key-value pair. Its default value is <c>=</c>.
Expand Down
Loading