Browse Source

style: Update code style

Bruce Wayne 4 years ago
parent
commit
22a115f142
34 changed files with 70 additions and 116 deletions
  1. 65 51
      .editorconfig
  2. 4 0
      .gitignore
  3. 0 2
      NatTypeTester-Console/Program.cs
  4. 0 5
      NatTypeTester.ViewModels/MainWindowViewModel.cs
  5. 0 3
      NatTypeTester.ViewModels/RFC3489ViewModel.cs
  6. 0 3
      NatTypeTester.ViewModels/RFC5780ViewModel.cs
  7. 0 1
      NatTypeTester.ViewModels/ValueConverters/StringToIPEndpointTypeConverter.cs
  8. 0 1
      NatTypeTester/App.xaml.cs
  9. 0 1
      NatTypeTester/Dialogs/DisposableContentDialog.cs
  10. 0 2
      NatTypeTester/MainWindow.xaml.cs
  11. 0 2
      NatTypeTester/Utils/Extensions.cs
  12. 0 1
      NatTypeTester/Views/RFC3489View.xaml.cs
  13. 0 1
      NatTypeTester/Views/RFC5780View.xaml.cs
  14. 0 4
      STUN/Client/IStunClient.cs
  15. 0 3
      STUN/Client/StunClient3489.cs
  16. 0 3
      STUN/Client/StunClient5389UDP.cs
  17. 0 1
      STUN/HostnameEndpoint.cs
  18. 0 1
      STUN/Messages/StunAttribute.cs
  19. 0 1
      STUN/Messages/StunAttributeValues/AddressStunAttributeValue.cs
  20. 0 1
      STUN/Messages/StunAttributeValues/ChangeRequestStunAttributeValue.cs
  21. 0 1
      STUN/Messages/StunAttributeValues/ErrorCodeStunAttributeValue.cs
  22. 0 2
      STUN/Messages/StunAttributeValues/IStunAttributeValue.cs
  23. 0 2
      STUN/Messages/StunAttributeValues/UnknownStunAttributeValue.cs
  24. 0 2
      STUN/Messages/StunAttributeValues/UselessStunAttributeValue.cs
  25. 0 1
      STUN/Messages/StunAttributeValues/XorMappedAddressStunAttributeValue.cs
  26. 0 3
      STUN/Messages/StunMessage5389.cs
  27. 0 3
      STUN/Proxy/IUdpProxy.cs
  28. 0 3
      STUN/Proxy/NoneUdpProxy.cs
  29. 0 4
      STUN/Proxy/Socks5UdpProxy.cs
  30. 0 2
      STUN/Utils/AttributeExtensions.cs
  31. 0 2
      UnitTest/StunClien5389UDPTest.cs
  32. 0 2
      UnitTest/StunClient3489Test.cs
  33. 0 2
      UnitTest/XorMappedTest.cs
  34. 1 0
      common.props

+ 65 - 51
.editorconfig

@@ -6,8 +6,9 @@ root = true
 charset = utf-8
 
 # 缩进和间距
-indent_style = space
 indent_size = 4
+indent_style = space
+tab_width = 4
 
 # 新行首选项
 end_of_line = crlf
@@ -36,66 +37,71 @@ dotnet_sort_system_directives_first = false
 file_header_template = unset
 
 # this. 和 Me. 首选项
-dotnet_style_qualification_for_event = false:warning
-dotnet_style_qualification_for_field = false:warning
-dotnet_style_qualification_for_method = false:warning
-dotnet_style_qualification_for_property = false:warning
+dotnet_style_qualification_for_event = false:suggestion
+dotnet_style_qualification_for_field = false
+dotnet_style_qualification_for_method = false:suggestion
+dotnet_style_qualification_for_property = false:suggestion
 
 # 语言关键字与 bcl 类型首选项
 dotnet_style_predefined_type_for_locals_parameters_members = true:warning
 dotnet_style_predefined_type_for_member_access = true:warning
 
 # 括号首选项
-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_arithmetic_binary_operators = never_if_unnecessary
+dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary
 dotnet_style_parentheses_in_other_operators = never_if_unnecessary:warning
-dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:silent
+dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary
 
 # 修饰符首选项
-dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning
+dotnet_style_require_accessibility_modifiers = for_non_interface_members
 
 # 表达式级首选项
 dotnet_style_coalesce_expression = true:warning
-dotnet_style_collection_initializer = true:warning
+dotnet_style_collection_initializer = true
 dotnet_style_explicit_tuple_names = true:warning
+dotnet_style_namespace_match_folder = true
 dotnet_style_null_propagation = true:warning
-dotnet_style_object_initializer = true:warning
+dotnet_style_object_initializer = true
 dotnet_style_operator_placement_when_wrapping = beginning_of_line
 dotnet_style_prefer_auto_properties = true:warning
 dotnet_style_prefer_compound_assignment = true:warning
-dotnet_style_prefer_conditional_expression_over_assignment = true:silent
-dotnet_style_prefer_conditional_expression_over_return = true:silent
-dotnet_style_prefer_inferred_anonymous_type_member_names = true:silent
-dotnet_style_prefer_inferred_tuple_names = true:silent
+dotnet_style_prefer_conditional_expression_over_assignment = true
+dotnet_style_prefer_conditional_expression_over_return = true
+dotnet_style_prefer_inferred_anonymous_type_member_names = true
+dotnet_style_prefer_inferred_tuple_names = true
 dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
 dotnet_style_prefer_simplified_boolean_expressions = true:warning
-dotnet_style_prefer_simplified_interpolation = true:suggestion
+dotnet_style_prefer_simplified_interpolation = true
 
 # 字段首选项
-dotnet_style_readonly_field = true:suggestion
+dotnet_style_readonly_field = true
 
 # 参数首选项
-dotnet_code_quality_unused_parameters = all:warning
+dotnet_code_quality_unused_parameters = all
 
 # 禁止显示首选项
-dotnet_remove_unnecessary_suppression_exclusions = none
+dotnet_remove_unnecessary_suppression_exclusions = 0
+
+# 新行首选项
+dotnet_style_allow_multiple_blank_lines_experimental = false
+dotnet_style_allow_statement_immediately_after_block_experimental = true
 
 #### c# 编码约定 ####
 
 # var 首选项
-csharp_style_var_elsewhere = true:silent
-csharp_style_var_for_built_in_types = true:warning
-csharp_style_var_when_type_is_apparent = true:warning
+csharp_style_var_elsewhere = false:suggestion
+csharp_style_var_for_built_in_types = false:suggestion
+csharp_style_var_when_type_is_apparent = false:suggestion
 
 # Expression-bodied 成员
-csharp_style_expression_bodied_accessors = when_on_single_line:warning
-csharp_style_expression_bodied_constructors = false:suggestion
-csharp_style_expression_bodied_indexers = when_on_single_line:warning
-csharp_style_expression_bodied_lambdas = when_on_single_line:suggestion
-csharp_style_expression_bodied_local_functions = false:suggestion
-csharp_style_expression_bodied_methods = false:suggestion
-csharp_style_expression_bodied_operators = false:suggestion
-csharp_style_expression_bodied_properties = when_on_single_line:warning
+csharp_style_expression_bodied_accessors = true:suggestion
+csharp_style_expression_bodied_constructors = false:warning
+csharp_style_expression_bodied_indexers = true:suggestion
+csharp_style_expression_bodied_lambdas = true:suggestion
+csharp_style_expression_bodied_local_functions = false:warning
+csharp_style_expression_bodied_methods = false:warning
+csharp_style_expression_bodied_operators = false:warning
+csharp_style_expression_bodied_properties = true:suggestion
 
 # 模式匹配首选项
 csharp_style_pattern_matching_over_as_with_null_check = true:warning
@@ -105,30 +111,38 @@ csharp_style_prefer_pattern_matching = true:warning
 csharp_style_prefer_switch_expression = true:warning
 
 # Null 检查首选项
-csharp_style_conditional_delegate_call = true:warning
+csharp_style_conditional_delegate_call = true
 
 # 修饰符首选项
-csharp_prefer_static_local_function = true:suggestion
-csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
+csharp_prefer_static_local_function = true
+csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
 
 # 代码块首选项
-csharp_prefer_braces = true:warning
-csharp_prefer_simple_using_statement = true:suggestion
+csharp_prefer_braces = true:suggestion
+csharp_prefer_simple_using_statement = true:warning
+csharp_style_namespace_declarations = file_scoped:warning
 
 # 表达式级首选项
 csharp_prefer_simple_default_expression = true:warning
-csharp_style_deconstructed_variable_declaration = true:suggestion
+csharp_style_deconstructed_variable_declaration = true
+csharp_style_implicit_object_creation_when_type_is_apparent = true:warning
 csharp_style_inlined_variable_declaration = true:warning
-csharp_style_pattern_local_over_anonymous_function = true:suggestion
+csharp_style_pattern_local_over_anonymous_function = true
 csharp_style_prefer_index_operator = true:warning
-csharp_style_prefer_range_operator = true:suggestion
-csharp_style_throw_expression = true:suggestion
-csharp_style_unused_value_assignment_preference = discard_variable:silent
-csharp_style_unused_value_expression_statement_preference = discard_variable:none
+csharp_style_prefer_null_check_over_type_check = true:warning
+csharp_style_prefer_range_operator = true:warning
+csharp_style_throw_expression = true
+csharp_style_unused_value_assignment_preference = discard_variable
+csharp_style_unused_value_expression_statement_preference = discard_variable
 
 # "using" 指令首选项
 csharp_using_directive_placement = outside_namespace:warning
 
+# 新行首选项
+csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
+csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false
+csharp_style_allow_embedded_statements_on_same_line_experimental = true
+
 #### C# 格式规则 ####
 
 # 新行首选项
@@ -145,7 +159,7 @@ csharp_indent_block_contents = true
 csharp_indent_braces = false
 csharp_indent_case_contents = true
 csharp_indent_case_contents_when_block = false
-csharp_indent_labels = flush_left
+csharp_indent_labels = one_less_than_current
 csharp_indent_switch_labels = true
 
 # 空格键首选项
@@ -156,7 +170,7 @@ 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_around_declaration_statements = ignore
 csharp_space_before_colon_in_inheritance_clause = true
 csharp_space_before_comma = false
 csharp_space_before_dot = false
@@ -195,25 +209,25 @@ dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
 # 符号规范
 
 dotnet_naming_symbols.interface.applicable_kinds = interface
-dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal
+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
-dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal
+dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
 dotnet_naming_symbols.types.required_modifiers = 
 
 dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
-dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal
+dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
 dotnet_naming_symbols.non_field_members.required_modifiers = 
 
 # 命名样式
 
-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.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.required_suffix = 
+dotnet_naming_style.begins_with_i.word_separator = 
 dotnet_naming_style.begins_with_i.capitalization = pascal_case

+ 4 - 0
.gitignore

@@ -360,3 +360,7 @@ MigrationBackup/
 
 # Fody - auto-generated XML schema
 FodyWeavers.xsd
+
+# JetBrains Rider
+.idea/
+*.sln.iml

+ 0 - 2
NatTypeTester-Console/Program.cs

@@ -1,9 +1,7 @@
 using Dns.Net.Clients;
 using STUN;
 using STUN.Client;
-using System;
 using System.Net;
-using System.Threading;
 
 //stun.qq.com:3478 0.0.0.0:0
 var server = @"stun.syncthing.net";

+ 0 - 5
NatTypeTester.ViewModels/MainWindowViewModel.cs

@@ -4,12 +4,7 @@ using Microsoft.VisualStudio.Threading;
 using NatTypeTester.Models;
 using ReactiveUI;
 using STUN;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
 using System.Reactive.Linq;
-using System.Threading.Tasks;
 using Volo.Abp.DependencyInjection;
 
 namespace NatTypeTester.ViewModels;

+ 0 - 3
NatTypeTester.ViewModels/RFC3489ViewModel.cs

@@ -8,13 +8,10 @@ using STUN;
 using STUN.Client;
 using STUN.Proxy;
 using STUN.StunResult;
-using System;
 using System.Net;
 using System.Net.Sockets;
 using System.Reactive;
 using System.Reactive.Linq;
-using System.Threading;
-using System.Threading.Tasks;
 
 namespace NatTypeTester.ViewModels;
 

+ 0 - 3
NatTypeTester.ViewModels/RFC5780ViewModel.cs

@@ -8,13 +8,10 @@ using STUN;
 using STUN.Client;
 using STUN.Proxy;
 using STUN.StunResult;
-using System;
 using System.Net;
 using System.Net.Sockets;
 using System.Reactive;
 using System.Reactive.Linq;
-using System.Threading;
-using System.Threading.Tasks;
 
 namespace NatTypeTester.ViewModels;
 

+ 0 - 1
NatTypeTester.ViewModels/ValueConverters/StringToIPEndpointTypeConverter.cs

@@ -1,6 +1,5 @@
 using JetBrains.Annotations;
 using ReactiveUI;
-using System;
 using System.Net;
 using Volo.Abp.DependencyInjection;
 

+ 0 - 1
NatTypeTester/App.xaml.cs

@@ -1,7 +1,6 @@
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Hosting;
 using Splat.Microsoft.Extensions.DependencyInjection;
-using System;
 using System.Windows;
 using Volo.Abp;
 

+ 0 - 1
NatTypeTester/Dialogs/DisposableContentDialog.cs

@@ -1,5 +1,4 @@
 using ModernWpf.Controls;
-using System;
 
 namespace NatTypeTester.Dialogs;
 

+ 0 - 2
NatTypeTester/MainWindow.xaml.cs

@@ -3,8 +3,6 @@ using ModernWpf.Controls;
 using NatTypeTester.ViewModels;
 using ReactiveMarbles.ObservableEvents;
 using ReactiveUI;
-using System;
-using System.Linq;
 using System.Reactive.Disposables;
 using Volo.Abp.DependencyInjection;
 

+ 0 - 2
NatTypeTester/Utils/Extensions.cs

@@ -1,6 +1,4 @@
 using NatTypeTester.Dialogs;
-using System;
-using System.Threading.Tasks;
 
 namespace NatTypeTester.Utils;
 

+ 0 - 1
NatTypeTester/Views/RFC3489View.xaml.cs

@@ -3,7 +3,6 @@ using NatTypeTester.Utils;
 using NatTypeTester.ViewModels;
 using ReactiveMarbles.ObservableEvents;
 using ReactiveUI;
-using System;
 using System.Reactive.Disposables;
 using System.Reactive.Linq;
 using System.Windows.Input;

+ 0 - 1
NatTypeTester/Views/RFC5780View.xaml.cs

@@ -3,7 +3,6 @@ using NatTypeTester.Utils;
 using NatTypeTester.ViewModels;
 using ReactiveMarbles.ObservableEvents;
 using ReactiveUI;
-using System;
 using System.Reactive.Disposables;
 using System.Reactive.Linq;
 using System.Windows.Input;

+ 0 - 4
STUN/Client/IStunClient.cs

@@ -1,7 +1,3 @@
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-
 namespace STUN.Client;
 
 public interface IStunClient : IDisposable

+ 0 - 3
STUN/Client/StunClient3489.cs

@@ -4,13 +4,10 @@ using STUN.Messages;
 using STUN.Proxy;
 using STUN.StunResult;
 using STUN.Utils;
-using System;
 using System.Buffers;
 using System.Diagnostics;
 using System.Net;
 using System.Net.Sockets;
-using System.Threading;
-using System.Threading.Tasks;
 
 namespace STUN.Client;
 

+ 0 - 3
STUN/Client/StunClient5389UDP.cs

@@ -4,15 +4,12 @@ using STUN.Messages;
 using STUN.Proxy;
 using STUN.StunResult;
 using STUN.Utils;
-using System;
 using System.Buffers;
 using System.Diagnostics;
 using System.Diagnostics.CodeAnalysis;
 using System.Net;
 using System.Net.Sockets;
 using System.Runtime.CompilerServices;
-using System.Threading;
-using System.Threading.Tasks;
 
 namespace STUN.Client;
 

+ 0 - 1
STUN/HostnameEndpoint.cs

@@ -1,4 +1,3 @@
-using System;
 using System.Diagnostics.CodeAnalysis;
 using System.Net;
 using System.Net.Sockets;

+ 0 - 1
STUN/Messages/StunAttribute.cs

@@ -1,7 +1,6 @@
 using Microsoft;
 using STUN.Enums;
 using STUN.Messages.StunAttributeValues;
-using System;
 using System.Buffers.Binary;
 using System.Security.Cryptography;
 

+ 0 - 1
STUN/Messages/StunAttributeValues/AddressStunAttributeValue.cs

@@ -1,6 +1,5 @@
 using Microsoft;
 using STUN.Enums;
-using System;
 using System.Buffers.Binary;
 using System.Net;
 using System.Net.Sockets;

+ 0 - 1
STUN/Messages/StunAttributeValues/ChangeRequestStunAttributeValue.cs

@@ -1,5 +1,4 @@
 using Microsoft;
-using System;
 
 namespace STUN.Messages.StunAttributeValues;
 

+ 0 - 1
STUN/Messages/StunAttributeValues/ErrorCodeStunAttributeValue.cs

@@ -1,5 +1,4 @@
 using Microsoft;
-using System;
 using System.Text;
 
 namespace STUN.Messages.StunAttributeValues;

+ 0 - 2
STUN/Messages/StunAttributeValues/IStunAttributeValue.cs

@@ -1,5 +1,3 @@
-using System;
-
 namespace STUN.Messages.StunAttributeValues;
 
 public interface IStunAttributeValue

+ 0 - 2
STUN/Messages/StunAttributeValues/UnknownStunAttributeValue.cs

@@ -1,8 +1,6 @@
 using Microsoft;
 using STUN.Enums;
-using System;
 using System.Buffers.Binary;
-using System.Collections.Generic;
 
 namespace STUN.Messages.StunAttributeValues;
 

+ 0 - 2
STUN/Messages/StunAttributeValues/UselessStunAttributeValue.cs

@@ -1,5 +1,3 @@
-using System;
-
 namespace STUN.Messages.StunAttributeValues;
 
 /// <summary>

+ 0 - 1
STUN/Messages/StunAttributeValues/XorMappedAddressStunAttributeValue.cs

@@ -1,5 +1,4 @@
 using Microsoft;
-using System;
 using System.Buffers.Binary;
 using System.Net;
 

+ 0 - 3
STUN/Messages/StunMessage5389.cs

@@ -1,10 +1,7 @@
 using Microsoft;
 using STUN.Enums;
-using System;
 using System.Buffers.Binary;
-using System.Collections.Generic;
 using System.Diagnostics;
-using System.Linq;
 using System.Security.Cryptography;
 
 namespace STUN.Messages;

+ 0 - 3
STUN/Proxy/IUdpProxy.cs

@@ -1,8 +1,5 @@
-using System;
 using System.Net;
 using System.Net.Sockets;
-using System.Threading;
-using System.Threading.Tasks;
 
 namespace STUN.Proxy;
 

+ 0 - 3
STUN/Proxy/NoneUdpProxy.cs

@@ -1,9 +1,6 @@
 using Microsoft;
-using System;
 using System.Net;
 using System.Net.Sockets;
-using System.Threading;
-using System.Threading.Tasks;
 
 namespace STUN.Proxy;
 

+ 0 - 4
STUN/Proxy/Socks5UdpProxy.cs

@@ -3,14 +3,10 @@ using Socks5.Clients;
 using Socks5.Enums;
 using Socks5.Models;
 using Socks5.Utils;
-using System;
 using System.Buffers;
-using System.IO;
 using System.Net;
 using System.Net.Sockets;
 using System.Runtime.CompilerServices;
-using System.Threading;
-using System.Threading.Tasks;
 
 namespace STUN.Proxy;
 

+ 0 - 2
STUN/Utils/AttributeExtensions.cs

@@ -1,8 +1,6 @@
 using STUN.Enums;
 using STUN.Messages;
 using STUN.Messages.StunAttributeValues;
-using System;
-using System.Linq;
 using System.Net;
 
 namespace STUN.Utils;

+ 0 - 2
UnitTest/StunClien5389UDPTest.cs

@@ -7,8 +7,6 @@ using STUN.Enums;
 using STUN.Messages;
 using STUN.StunResult;
 using System.Net;
-using System.Threading;
-using System.Threading.Tasks;
 
 namespace UnitTest;
 

+ 0 - 2
UnitTest/StunClient3489Test.cs

@@ -8,8 +8,6 @@ using STUN.Messages;
 using STUN.Utils;
 using System.Net;
 using System.Net.Sockets;
-using System.Threading;
-using System.Threading.Tasks;
 using static STUN.Utils.AttributeExtensions;
 
 namespace UnitTest;

+ 0 - 2
UnitTest/XorMappedTest.cs

@@ -1,8 +1,6 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using STUN.Enums;
 using STUN.Messages.StunAttributeValues;
-using System;
-using System.Linq;
 using System.Net;
 
 namespace UnitTest;

+ 1 - 0
common.props

@@ -1,6 +1,7 @@
 <Project>
   <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
     <LangVersion>latest</LangVersion>
     <Nullable>enable</Nullable>
     <Authors>HMBSbige</Authors>