Skip to content

Commit

Permalink
.editorconfig; lang version; nuget updates
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitz committed Jul 5, 2021
1 parent 111b771 commit 477fca3
Show file tree
Hide file tree
Showing 14 changed files with 223 additions and 46 deletions.
175 changes: 175 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
root = true


[*.{cs,vb}]
indent_size = 4
indent_style = space
end_of_line = crlf
insert_final_newline = true

dotnet_separate_import_directive_groups = false
dotnet_sort_system_directives_first = false

dotnet_style_qualification_for_event = false:suggestion
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_property = false:suggestion

dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:silent
dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:silent

dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent

dotnet_style_coalesce_expression = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_object_initializer = true:suggestion
dotnet_style_operator_placement_when_wrapping = end_of_line
dotnet_style_prefer_auto_properties = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion


# Naming rules

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_private_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_private_members_should_be_pascal_case.symbols = non_private_members
dotnet_naming_rule.non_private_members_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.private_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.private_members_should_be_pascal_case.symbols = private_members
dotnet_naming_rule.private_members_should_be_pascal_case.style = camel_case

dotnet_naming_ruke.non_private_fields_should_be_canel_case.severity = suggestion
dotnet_naming_ruke.non_private_fields_should_be_canel_case.symbols = non_private_fields
dotnet_naming_ruke.non_private_fields_should_be_canel_case.style = camel_case


# Symbols for use with naming rules

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum, delegate
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_private_members.applicable_kinds = property, method, event
dotnet_naming_symbols.non_private_members.applicable_accessibilities = public, internal, protected, private_protected, protected_internal

dotnet_naming_symbols.private_members.applicable_kinds = property, method, field, event
dotnet_naming_symbols.private_members.applicable_accessibilities = private

dotnet_naming_symbols.non_private_fields.applicable_kinds = field
dotnet_naming_symbols.non_private_fields.applicable_accessibilities = internal, protected, private_protected, protected_internal


# Naming styles

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.camel_case.required_prefix =
dotnet_naming_style.camel_case.required_suffix =
dotnet_naming_style.camel_case.word_separator =
dotnet_naming_style.camel_case.capitalization = camel_case


[*.cs]
csharp_new_line_before_catch = false
csharp_new_line_before_else = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = none
csharp_new_line_between_query_expression_clauses = true

csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = true
csharp_indent_labels = one_less_than_current
csharp_indent_switch_labels = true

csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false

csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true

csharp_prefer_braces = true:warning

csharp_style_expression_bodied_constructors = true:suggestion
csharp_style_expression_bodied_methods = true:suggestion
csharp_style_expression_bodied_properties = true:suggestion

csharp_prefer_simple_default_expression = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion

csharp_style_var_elsewhere = true:suggestion
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion

csharp_preferred_modifier_order = internal,protected,public,private,static,readonly,abstract,override,sealed,virtual:suggestion

csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion


[*.vb]
visual_basic_preferred_modifier_order = partial,default,private,protected,public,friend,notoverridable,overridable,mustoverride,overloads,overrides,mustinherit,notinheritable,static,shared,shadows,readonly,writeonly,dim,const,withevents,widening,narrowing,custom,async,iterator:silent
visual_basic_style_unused_value_assignment_preference = unused_local_variable:suggestion
visual_basic_style_unused_value_expression_statement_preference = unused_local_variable:silent
6 changes: 3 additions & 3 deletions Debuggee/Debuggee.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net472;netstandard2.0;netcoreapp2.0</TargetFrameworks>
<RootNamespace>ExpressionTreeVisualizer.Debuggee</RootNamespace>
<AssemblyName>ExpressionTreeVisualizer.Debuggee</AssemblyName>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<DefineConstants>VISUALIZER_DEBUGGEE</DefineConstants>
Expand All @@ -28,8 +28,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ZSpitz.Util" Version="0.1.81" />
<PackageReference Include="ExpressionTreeToString" Version="3.2.53" />
<PackageReference Include="ZSpitz.Util" Version="0.1.105" />
<PackageReference Include="ExpressionTreeToString" Version="3.4.63" />
<Reference Include="Microsoft.VisualStudio.DebuggerVisualizers">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.DebuggerVisualizers.dll</HintPath>
<Private>false</Private>
Expand Down
2 changes: 1 addition & 1 deletion Debuggee/Periscope.Debuggee
12 changes: 6 additions & 6 deletions Package/Package.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net472;netcoreapp3.1;net5.0-windows</TargetFrameworks>
<RootNamespace>ExpressionTreeVisualizer</RootNamespace>
<AssemblyName>ExpressionTreeVisualizer.UI</AssemblyName>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<UseWPF>true</UseWPF>
Expand All @@ -27,10 +27,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ExpressionTreeToString" Version="3.2.53" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
<PackageReference Include="ZSpitz.Util" Version="0.1.81" />
<PackageReference Include="ZSpitz.Util.Wpf" Version="0.1.81" />
<PackageReference Include="ExpressionTreeToString" Version="3.4.63" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.31" />
<PackageReference Include="ZSpitz.Util" Version="0.1.105" />
<PackageReference Include="ZSpitz.Util.Wpf" Version="0.1.105" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="MultiSelectTreeView" Version="1.0.9" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Serialization/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override Config Clone() =>
#else
public Config Clone() =>
#endif
new Config {
new() {
Formatter = Formatter,
Language = Language,
Path = Path
Expand Down
30 changes: 15 additions & 15 deletions Serialization/ExpressionNodeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ExpressionNodeData {
.SelectMany(x => new[] { x, typeof(IEnumerable<>).MakeGenericType(x) })
.ToHashSet();

private static readonly Dictionary<Type, List<(string @namespace, string typename)>> baseTypes = new Dictionary<Type, List<(string @namespace, string typename)>>();
private static readonly Dictionary<Type, List<(string @namespace, string typename)>> baseTypes = new();

private static readonly Dictionary<Type, string[]> factoryMethodNamesByType =
typeof(Expression).GetMethods()
Expand Down Expand Up @@ -110,7 +110,7 @@ private ExpressionNodeData(

var (evaluated, value) = valueExtractor.GetValue(expr);
if (evaluated) {
StringValue = StringValue(value!, language); // TODO value is allowed to be null
StringValue = StringValue(value, language); // TODO value is allowed to be null
EnableValueInNewWindow = value is { } && value.GetType().InheritsFromOrImplementsAny(NodeTypes);
}

Expand Down Expand Up @@ -142,7 +142,7 @@ private ExpressionNodeData(
NodeType = callSiteBinder.BinderType().ToString();
break;
default:
NodeType = o.GetType().FriendlyName(language);
NodeType = o.GetType().FriendlyName(language)!;
break;
}

Expand All @@ -161,11 +161,10 @@ private ExpressionNodeData(
var typename = o.GetType().BaseTypes(false, true).First(x => !x.IsGenericType && x.IsPublic && properties.All(prp => x.GetProperty(prp.Name) is { })); // because the FullName of generic types is often the fully-qualified name
if (parentWatchExpression.IsNullOrWhitespace()) {
var formatString = "{0}";
if (language == CSharp) {
WatchExpressionFormatString = $"(({typename}){formatString})";
} else { // VisualBasic
WatchExpressionFormatString = $"CType({formatString}, {typename})";
}
WatchExpressionFormatString =
language == CSharp ?
$"(({typename}){formatString})" :
$"CType({formatString}, {typename})";
} else {
var watchPathFromParent = PathFromParent;
if (language == CSharp) {
Expand All @@ -179,14 +178,15 @@ private ExpressionNodeData(
// populate Children
var preferredOrder = PreferredPropertyOrders.FirstOrDefault(x => x.type.IsAssignableFrom(type)).propertyNames;
Children = properties
.OrderBy(prp => {
if (preferredOrder == null) { return -1; }
return Array.IndexOf(preferredOrder, prp.Name);
})
.OrderBy(prp =>
preferredOrder is not null ?
Array.IndexOf(preferredOrder, prp.Name) :
-1
)
.ThenBy(prp => prp.Name)
.SelectMany(prp => {
if (prp.PropertyType.InheritsFromOrImplements<IEnumerable>()) {
return (prp.GetValue(o) as IEnumerable).Cast<object>().Select((x, index) => ($"{prp.Name}[{index}]", x, prp));
return (prp.GetValue(o) as IEnumerable)!.Cast<object>().Select((x, index) => ($"{prp.Name}[{index}]", x, prp));
} else {
return new[] { (prp.Name, prp.GetValue(o)!, prp) };
}
Expand All @@ -213,14 +213,14 @@ private ExpressionNodeData(
Globals.FactoryMethodNames.TryGetValue(((Expression)o).NodeType, out factoryMethodName);
}
if (factoryMethodName.IsNullOrWhitespace()) {
var publicType = o.GetType().BaseTypes(false, true).FirstOrDefault(x => !x.IsInterface && x.IsPublic);
var publicType = o.GetType().BaseTypes(false, true).First(x => !x.IsInterface && x.IsPublic);
factoryMethodNamesByType.TryGetValue(publicType, out _factoryMethodNames!);
} else {
_factoryMethodNames = new[] { factoryMethodName };
}
}

public EndNodeData EndNodeData => new EndNodeData {
public EndNodeData EndNodeData => new() {
Closure = Closure,
Name = Name,
Type = ReflectionTypeName,
Expand Down
2 changes: 1 addition & 1 deletion Serialization/VisualizerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class VisualizerData {
public VisualizerData(object o, Config? config = null) {
Config = config ?? new Config();
if (!Config.Path.IsNullOrWhitespace()) {
o = ((Expression)ResolvePath(o, Config.Path)).ExtractValue();
o = ((Expression)ResolvePath(o, Config.Path)!).ExtractValue()!;
}
Source = Renderers.Invoke(Config.Formatter, o, Config.Language, out var pathSpans);

Expand Down
7 changes: 4 additions & 3 deletions Tests.Visualizer/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<RootNamespace>ExpressionTreeVisualizer.Tests</RootNamespace>
<AssemblyName>ExpressionTreeVisualizer.Tests</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ExpressionTreeToString" Version="3.2.53" />
<PackageReference Include="ExpressionTreeToString" Version="3.4.63" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="ExpressionTreeTestObjects" Version="1.0.18" />
<PackageReference Include="ExpressionTreeTestObjects" Version="1.0.21" />
<PackageReference Include="ZSpitz.Util" Version="0.1.105" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion UI/ViewModels/EndNodeGroupViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class EndNodeGroupViewModel : Selectable<EndNodeData> {
public EndNodeGroupViewModel(EndNodeData model, IEnumerable<ExpressionNodeDataViewModel> nodes) : base(model) {
Nodes = nodes.ToReadOnlyCollection();

void handler(object s, PropertyChangedEventArgs e) {
void handler(object? s, PropertyChangedEventArgs e) {
if (e.PropertyName != nameof(IsSelected)) { return; }
IsSelected = Nodes.Any(x => x.IsSelected);
}
Expand Down
7 changes: 5 additions & 2 deletions UI/ViewModels/VisualizerDataViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ public ExpressionNodeDataViewModel FindNodeBySpan(int start, int length) {
//if (start < NodeData.Span.start || end > NodeData.SpanEnd) { throw new ArgumentOutOfRangeException(); }
var current = Root;
while (true) {
var child = current.Children.SingleOrDefault(x => x.Model.Span.start <= start && x.Model.SpanEnd >= end);
var child =
(start, length) == (0,0) ?
current.Children.FirstOrDefault(x => x.Model.Span == (0,0)) :
current.Children.SingleOrDefault(x => x.Model.Span.start <= start && x.Model.SpanEnd >= end);
if (child == null) { break; }
current = child;
}
Expand Down Expand Up @@ -127,4 +130,4 @@ public string WindowTitle {
}
}
}
}
}
4 changes: 2 additions & 2 deletions UI/VisualizerDataControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void HelpContextMenu_Loaded(object sender, RoutedEventArgs e) {
listData.RemoveLast();
}

listData.ForEachT((header, url) => {
foreach (var (header, url) in listData) {
if (header == "---") {
menu.Items.Add(new Separator());
return;
Expand All @@ -90,7 +90,7 @@ private void HelpContextMenu_Loaded(object sender, RoutedEventArgs e) {
};
mi.Click += (s1, e1) => Process.Start(url);
menu.Items.Add(mi);
});
}

void addSeparator() {
if (listData.None() || listData.Last().header == "---") { return; }
Expand Down
2 changes: 1 addition & 1 deletion Visualizer/Periscope
Loading

0 comments on commit 477fca3

Please sign in to comment.