Skip to content

Commit

Permalink
More EditorConfig settings (#953)
Browse files Browse the repository at this point in the history
* Extend Editor Config

* Format whitespace

* Remove and sort usings
  • Loading branch information
jnyrup authored and dennisdoomen committed Nov 5, 2018
1 parent b74b041 commit 5455f2c
Show file tree
Hide file tree
Showing 95 changed files with 251 additions and 205 deletions.
100 changes: 97 additions & 3 deletions .editorconfig
Expand Up @@ -17,12 +17,106 @@ indent_size = 2
# Xml config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
indent_style = space
tab_width = 2
indent_size = 2

[*.{md,json}]
indent_style = space
tab_width = 4
indent_size = 4

[*.cs]
indent_style = space
tab_width = 4
indent_size = 4

# New line preferences
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true

# Indentation preferences
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = one_less_than_current

# avoid this. unless absolutely necessary
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion

# only use var when it's obvious what the variable type is
csharp_style_var_for_built_in_types = false:none
csharp_style_var_when_type_is_apparent = false:none
csharp_style_var_elsewhere = false:suggestion

# use language keywords instead of BCL types
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

# name all constant fields using PascalCase
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style

dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.required_modifiers = const

dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# Code style defaults
dotnet_sort_system_directives_first = true
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = false

# Expression-level preferences
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion

# Expression-bodied members
csharp_style_expression_bodied_methods = true:none
csharp_style_expression_bodied_constructors = false:none
csharp_style_expression_bodied_operators = false:none
csharp_style_expression_bodied_properties = true:none
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none

# Pattern matching
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

# Null checking preferences
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

# Space preferences
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 = do_not_ignore
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
1 change: 1 addition & 0 deletions FluentAssertions.sln.DotSettings
Expand Up @@ -70,6 +70,7 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
Expand Down
1 change: 0 additions & 1 deletion Src/FluentAssertions/AssertionExtensions.Actions.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using FluentAssertions.Common;
using FluentAssertions.Specialized;
Expand Down
1 change: 0 additions & 1 deletion Src/FluentAssertions/AssertionOptions.cs
@@ -1,7 +1,6 @@
#region

using System;
using FluentAssertions.Common;
using FluentAssertions.Equivalency;

#endregion
Expand Down
4 changes: 1 addition & 3 deletions Src/FluentAssertions/CallerIdentifier.cs
@@ -1,10 +1,8 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using FluentAssertions.Common;
using FluentAssertions.Execution;

namespace FluentAssertions
{
Expand Down Expand Up @@ -66,7 +64,7 @@ private static string ExtractVariableNameFrom(StackFrame frame)

if ((line != null) && (column != 0) && (line.Length > 0))
{
string statement = line.Substring(Math.Min(column - 1, line.Length -1));
string statement = line.Substring(Math.Min(column - 1, line.Length - 1));

logger(statement);

Expand Down
Expand Up @@ -254,7 +254,7 @@ public AndConstraint<GenericCollectionAssertions<T>> OnlyHaveUniqueItems<TKey>(E
? unordered.OrderBy(keySelector, comparer)
: unordered.OrderByDescending(keySelector, comparer);

var orderString = propertyExpression.GetMemberPath();
string orderString = propertyExpression.GetMemberPath().ToString();
orderString = orderString == "\"\"" ? string.Empty : " by " + orderString;

Execute.Assertion
Expand Down
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand Down
@@ -1,6 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
Expand Down
@@ -1,7 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
Expand Down
Expand Up @@ -67,7 +67,7 @@ internal static CSharpAccessModifier GetCSharpAccessModifier(this FieldInfo fiel
return CSharpAccessModifier.ProtectedInternal;
}

if(fieldInfo.IsFamilyAndAssembly)
if (fieldInfo.IsFamilyAndAssembly)
{
return CSharpAccessModifier.PrivateProtected;
}
Expand Down
15 changes: 11 additions & 4 deletions Src/FluentAssertions/Common/ExpressionExtensions.cs
Expand Up @@ -5,10 +5,11 @@
using System.Reflection;

using FluentAssertions.Equivalency;
using FluentAssertions.Equivalency.Selection;

namespace FluentAssertions.Common
{
public static class ExpressionExtensions
internal static class ExpressionExtensions
{
public static SelectedMemberInfo GetSelectedMemberInfo<T, TValue>(this Expression<Func<T, TValue>> expression)
{
Expand Down Expand Up @@ -79,16 +80,21 @@ public static class ExpressionExtensions
}

/// <summary>
/// Gets a dotted path of property names representing the property expression. E.g. Parent.Child.Sibling.Name.
/// Gets a dotted path of property names representing the property expression, including the declaring type.
/// </summary>
public static string GetMemberPath<TDeclaringType, TPropertyType>(
/// <example>
/// E.g. Parent.Child.Sibling.Name.
/// </example>
public static MemberPath GetMemberPath<TDeclaringType, TPropertyType>(
this Expression<Func<TDeclaringType, TPropertyType>> expression)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression), "Expected an expression, but found <null>.");
}

Type declaringType = typeof(TDeclaringType);

var segments = new List<string>();
Expression node = expression;

Expand All @@ -113,6 +119,7 @@ public static class ExpressionExtensions
node = memberExpression.Expression;

segments.Add(memberExpression.Member.Name);
declaringType = memberExpression.Member.DeclaringType;
break;

case ExpressionType.ArrayIndex:
Expand Down Expand Up @@ -146,7 +153,7 @@ public static class ExpressionExtensions

string[] reversedSegments = segments.AsEnumerable().Reverse().ToArray();
string segmentPath = string.Join(".", reversedSegments);
return segmentPath.Replace(".[", "[");
return new MemberPath(declaringType, segmentPath.Replace(".[", "["));
}

internal static string GetMethodName(Expression<Action> action)
Expand Down
2 changes: 1 addition & 1 deletion Src/FluentAssertions/Common/FullFrameworkReflector.cs
Expand Up @@ -32,7 +32,7 @@ private bool IsRelevant(Assembly ass)

private static bool IsDynamic(Assembly assembly)
{
return (assembly.GetType().FullName == "System.Reflection.Emit.AssemblyBuilder") ||
return (assembly.GetType().FullName == "System.Reflection.Emit.AssemblyBuilder") ||
(assembly.GetType().FullName == "System.Reflection.Emit.InternalAssemblyBuilder");
}

Expand Down
Expand Up @@ -2,17 +2,22 @@
using System.Collections.Generic;
using System.Linq;

namespace FluentAssertions.Equivalency.Selection
namespace FluentAssertions.Common
{
/// <summary>
/// Encapsulates a dotted candidate to a (nested) member of a type.
/// Encapsulates a dotted candidate to a (nested) member of a type as well as the
/// declaring type of the deepest member.
/// </summary>
internal class MemberPath
{
private readonly Type declaringType;
private readonly string dottedPath;
private readonly List<string> segments = new List<string>();

public MemberPath(string dottedPath)
public MemberPath(Type declaringType, string dottedPath)
{
this.declaringType = declaringType;
this.dottedPath = dottedPath;
segments.AddRange(Segmentize(dottedPath));
}

Expand All @@ -21,23 +26,37 @@ public bool IsParentOrChildOf(string candidate)
return IsParent(candidate) || IsChild(candidate);
}

public bool IsSameAs(string candidate, Type memberDeclaringType)
{
string[] candidateSegments = Segmentize(candidate);

return candidateSegments.SequenceEqual(segments) && memberDeclaringType == declaringType;
}

private bool IsChild(string candidate)
{
string[] candidateSegments = Segmentize(candidate);

return candidateSegments.Take(segments.Count).SequenceEqual(segments);
return candidateSegments.Take(segments.Count).SequenceEqual(segments) &&
candidateSegments.Length > segments.Count;
}

private bool IsParent(string candidate)
{
string[] candidateSegments = Segmentize(candidate);

return candidateSegments.SequenceEqual(segments.Take(candidateSegments.Length));
return candidateSegments.SequenceEqual(segments.Take(candidateSegments.Length))
&& candidateSegments.Length < segments.Count;
}

private static string[] Segmentize(string dottedPath)
{
return dottedPath.Split(new[] { '.', '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
}

public override string ToString()
{
return dottedPath;
}
}
}
1 change: 0 additions & 1 deletion Src/FluentAssertions/Common/Services.cs
@@ -1,6 +1,5 @@
using System;
using FluentAssertions.Execution;
using FluentAssertions.Formatting;

namespace FluentAssertions.Common
{
Expand Down
12 changes: 1 addition & 11 deletions Src/FluentAssertions/Common/StringExtensions.cs
@@ -1,20 +1,10 @@
using System;
using System.Linq;
using FluentAssertions.Formatting;

namespace FluentAssertions.Common
{
internal static class StringExtensions
{
/// <summary>
/// Finds the first index at which the <paramref name="value"/> does not match the <paramref name="expected"/>
/// string anymore, including the exact casing.
/// </summary>
public static int IndexOfFirstMismatch(this string value, string expected)
{
return IndexOfFirstMismatch(value, expected, StringComparison.CurrentCulture);
}

/// <summary>
/// Finds the first index at which the <paramref name="value"/> does not match the <paramref name="expected"/>
/// string anymore, accounting for the specified <paramref name="stringComparison"/>.
Expand Down Expand Up @@ -84,7 +74,7 @@ public static bool IsNullOrEmpty(this string value)
/// </remarks>
public static string Combine(this string @this, string other, string separator = ".")
{
if(@this.Length == 0)
if (@this.Length == 0)
{
return (other.Length != 0) ? other : string.Empty;
}
Expand Down
2 changes: 0 additions & 2 deletions Src/FluentAssertions/Equivalency/AssertionContext.cs
@@ -1,5 +1,3 @@
using System.Reflection;

namespace FluentAssertions.Equivalency
{
internal class AssertionContext<TSubject> : IAssertionContext<TSubject>
Expand Down
@@ -1,5 +1,4 @@
using System;
using System.Reflection;

namespace FluentAssertions.Equivalency
{
Expand Down
2 changes: 1 addition & 1 deletion Src/FluentAssertions/Equivalency/ConversionSelector.cs
Expand Up @@ -51,7 +51,7 @@ public bool RequiresConversion(IMemberInfo info)

public override string ToString()
{
if(inclusions.Count == 0 && exclusions.Count == 0)
if (inclusions.Count == 0 && exclusions.Count == 0)
{
return "Without automatic conversion.";
}
Expand Down
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;

using FluentAssertions.Execution;
Expand Down
@@ -1,4 +1,3 @@
using System;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
Expand Down
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down

0 comments on commit 5455f2c

Please sign in to comment.