Skip to content

Commit

Permalink
Updating editorconfigs with open braces on same line as control blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
lookbusy1344 committed May 4, 2024
1 parent a5ba530 commit 04aeacd
Show file tree
Hide file tree
Showing 14 changed files with 373 additions and 306 deletions.
36 changes: 8 additions & 28 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# New config, for UI apps
# This keeps open-braces on same line for code blocks
# 04 May 2024

# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true

Expand Down Expand Up @@ -113,31 +117,6 @@ csharp_preferred_modifier_order = public,private,protected,internal,file,static,
csharp_style_prefer_readonly_struct = true
csharp_style_prefer_readonly_struct_member = true

# Code-block preferences
csharp_prefer_braces = false
csharp_prefer_simple_using_statement = true
csharp_style_namespace_declarations = block_scoped
csharp_style_prefer_method_group_conversion = true
csharp_style_prefer_top_level_statements = true

# Expression-level preferences
csharp_prefer_simple_default_expression = true
csharp_style_deconstructed_variable_declaration = true
csharp_style_implicit_object_creation_when_type_is_apparent = true
csharp_style_inlined_variable_declaration = true
csharp_style_prefer_index_operator = true
csharp_style_prefer_local_over_anonymous_function = true
csharp_style_prefer_null_check_over_type_check = true
csharp_style_prefer_range_operator = true
csharp_style_prefer_tuple_swap = true
csharp_style_prefer_utf8_string_literals = true
csharp_style_throw_expression = true
csharp_style_unused_value_assignment_preference = discard_variable
csharp_style_unused_value_expression_statement_preference = discard_variable

# 'using' directive preferences
csharp_using_directive_placement = outside_namespace

# New line preferences
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true
Expand All @@ -149,11 +128,12 @@ csharp_style_allow_embedded_statements_on_same_line_experimental = true

# New line preferences
csharp_new_line_before_catch = true
csharp_new_line_before_else = true
csharp_new_line_before_else = false
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = all
csharp_new_line_before_open_brace = methods, types, events, local_functions, anonymous_methods, anonymous_types, properties, indexers, accessors
# OTHER OPTS: lambdas, control_blocks, all, none
csharp_new_line_between_query_expression_clauses = true

# Indentation preferences
Expand Down Expand Up @@ -277,7 +257,7 @@ dotnet_style_qualification_for_event = false:silent
[*.{cs,cshtml,razor}]
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:warning
csharp_prefer_braces = false:suggestion
csharp_prefer_braces = true:suggestion
csharp_style_namespace_declarations = file_scoped:warning
csharp_style_prefer_method_group_conversion = true:suggestion
csharp_style_prefer_top_level_statements = false:warning
Expand Down
8 changes: 5 additions & 3 deletions CliOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ public CliOptions()
private int GetMaxParallelism()
{
var p = Environment.ProcessorCount;
if (IsSSD) return p;
if (IsSSD) {
return p;
}

// spinning disk, so use half the cores.
p /= 2;
if (p < 1) p = 1;
return p;

return Math.Max(p, 1);
}

/// <summary>
Expand Down
9 changes: 3 additions & 6 deletions DiskQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@ internal static class DiskQuery
public static bool IsSSD(DirectoryInfo dir)
{
var driveLetter = dir.Root.FullName[..1];
try
{
try {
using var drive = new ManagementObject($"win32_logicaldisk.deviceid=\"{driveLetter}:\"");
drive.Get();
var mediatype = drive["MediaType"];
return mediatype switch
{
return mediatype switch {
uint n when n == 12 => true,
_ => false
// null => false,
//_ => throw new Exception($"Unknown media type: {mediatype}")
};
}
catch (ManagementException)
{
catch (ManagementException) {
#if DEBUG
throw;
#else
Expand Down
25 changes: 17 additions & 8 deletions GitVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,45 @@ public class VersionInfo

public string GetHash(int? len = null)
{
if (string.IsNullOrEmpty(Version) && string.IsNullOrEmpty(GitHash))
if (string.IsNullOrEmpty(Version) && string.IsNullOrEmpty(GitHash)) {
return "(unknown)";
}

GitHash ??= string.Empty;

if (len == null)
if (len == null) {
return GitHash;
else
} else {
return $"{GitHash[..len.Value]}{(GitModified ? "+" : string.Empty)}";
}
}

public string GetVersionHash(int? len = null)
{
if (string.IsNullOrEmpty(Version) && string.IsNullOrEmpty(GitHash))
if (string.IsNullOrEmpty(Version) && string.IsNullOrEmpty(GitHash)) {
return "(unknown)";
}

GitHash ??= string.Empty;

if (len == null)
if (len == null) {
return $"v{Version} - {GitHash}";
else
} else {
return $"v{Version} - {GitHash[..len.Value]}{(GitModified ? "+" : string.Empty)}";
}
}

public static VersionInfo Get()
{
var assembly = Assembly.GetExecutingAssembly();
if (assembly == null) return VersionInfo.Empty;
if (assembly == null) {
return VersionInfo.Empty;
}

var verinfo = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
if (verinfo == null) return VersionInfo.Empty;
if (verinfo == null) {
return VersionInfo.Empty;
}

var items = verinfo.InformationalVersion.Split('+', 2);
var version = items[0];
Expand Down
51 changes: 30 additions & 21 deletions GlobSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ internal static class GlobSearch
public static string[] FindFiles(string path, IReadOnlyList<Glob> globs, CancellationToken token)
{
var files = new List<string>(100);
foreach (var g in globs)
foreach (var g in globs) {
FindFilesRecursivelyInternal(ref files, path, g, token);
}

return files
.OrderBy(s => s)
Expand All @@ -29,20 +30,25 @@ private static void FindFilesRecursivelyInternal(ref List<string> files, string
{
token.ThrowIfCancellationRequested();

foreach (var file in Directory.GetFiles(path))
if (g.IsMatch(Path.GetFileName(file)))
foreach (var file in Directory.GetFiles(path)) {
if (g.IsMatch(Path.GetFileName(file))) {
files.Add(file);
}
}

foreach (var dir in Directory.GetDirectories(path, "*", diroptions))
foreach (var dir in Directory.GetDirectories(path, "*", diroptions)) {
FindFilesRecursivelyInternal(ref files, dir, g, token);
}
}

/// <summary>
/// Use globs to find files recursively, in parallel
/// </summary>
public static string[] ParallelFindFiles(string path, IReadOnlyList<Glob> globs, int parallelthreads, Action<int>? progress, CancellationToken cancellationtoken)
{
if (parallelthreads <= 1) return FindFiles(path, globs, cancellationtoken);
if (parallelthreads <= 1) {
return FindFiles(path, globs, cancellationtoken);
}

var count = 0;
var results = new ConcurrentBag<List<string>>();
Expand All @@ -52,45 +58,46 @@ public static string[] ParallelFindFiles(string path, IReadOnlyList<Glob> globs,

// we need 2 buffers, so we can swap them. One is iterated in parallel, the other is build up for the next iteration

while (!currentbuffer.IsEmpty)
{
while (!currentbuffer.IsEmpty) {
cancellationtoken.ThrowIfCancellationRequested();

count += currentbuffer.Count;
progress?.Invoke(count);

_ = Parallel.ForEach(currentbuffer, new ParallelOptions { MaxDegreeOfParallelism = parallelthreads, CancellationToken = cancellationtoken }, (folder) =>
{
_ = Parallel.ForEach(currentbuffer, new ParallelOptions { MaxDegreeOfParallelism = parallelthreads, CancellationToken = cancellationtoken }, (folder) => {
cancellationtoken.ThrowIfCancellationRequested();
// add subdirectories to the queue, to be processed in parallel on the next batch
foreach (var dir in Directory.GetDirectories(folder, "*", diroptions))
foreach (var dir in Directory.GetDirectories(folder, "*", diroptions)) {
nextbuffer.Add(dir);
}
// now find the files that match the globs
var candidates = Directory.GetFiles(folder);
List<string>? found = null;
foreach (var c in candidates)
{
foreach (var c in candidates) {
cancellationtoken.ThrowIfCancellationRequested();
var size = candidates.Length > 10 ? 10 : candidates.Length;
var filename = Path.GetFileName(c);
foreach (var g in globs)
if (g.IsMatch(filename))
{
foreach (var g in globs) {
if (g.IsMatch(filename)) {
found ??= new List<string>(size);
found.Add(c);
break;
}
}
}
if (found?.Count > 0)
if (found?.Count > 0) {
results.Add(found);
}
});

// if no new folders were added, we are done
if (nextbuffer.IsEmpty) break;
if (nextbuffer.IsEmpty) {
break;
}

currentbuffer.Clear(); // clear the processed items

Expand All @@ -113,13 +120,15 @@ public static string[] RecursiveFindFiles(string path, IReadOnlyList<string> out
var searchoptions = new EnumerationOptions { RecurseSubdirectories = true, IgnoreInaccessible = true };
var results = new ConcurrentBag<string[]>();

_ = Parallel.ForEach(outerpatterns, new ParallelOptions { MaxDegreeOfParallelism = parallelthreads, CancellationToken = token }, pattern =>
{
if (string.IsNullOrEmpty(pattern)) return;
_ = Parallel.ForEach(outerpatterns, new ParallelOptions { MaxDegreeOfParallelism = parallelthreads, CancellationToken = token }, pattern => {
if (string.IsNullOrEmpty(pattern)) {
return;
}
var files = Directory.GetFiles(path, pattern, searchoptions);
if (files.Length > 0)
if (files.Length > 0) {
results.Add(files);
}
});

// merge the results from each task into single sorted array
Expand Down
Loading

0 comments on commit 04aeacd

Please sign in to comment.