Skip to content

Commit

Permalink
Merge pull request #97 from thomasclaudiushuber/issue/83
Browse files Browse the repository at this point in the history
Add EnforceExtendedAnalyzerRules attribute and clean up code
  • Loading branch information
thomasclaudiushuber authored Dec 10, 2023
2 parents 7825aae + bc5e89e commit eae8787
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 18 deletions.
70 changes: 69 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggest
#Style - Modifier preferences

#when this rule is set to a list of modifiers, prefer the specified ordering.
csharp_preferred_modifier_order = public,private,internal,protected,readonly,virtual:suggestion
csharp_preferred_modifier_order = public,private,internal,protected,static, readonly,virtual:suggestion

#Style - Pattern matching

Expand All @@ -122,3 +122,71 @@ dotnet_style_qualification_for_property = false:suggestion


file_header_template = ***********************************************************************\n⚡ MvvmGen => https://github.com/thomasclaudiushuber/mvvmgen\nCopyright © by Thomas Claudius Huber\nLicensed under the MIT license => See LICENSE file in repository root\n***********************************************************************
csharp_indent_labels = one_less_than_current
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_prefer_static_local_function = true:suggestion
csharp_style_prefer_readonly_struct = true:suggestion
csharp_style_prefer_readonly_struct_member = true:suggestion

[*.{cs,vb}]
#### Naming styles ####

# 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_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications

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
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, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

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.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.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_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
end_of_line = crlf
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ namespace MvvmGen.Model
{
public class ViewModelToGenerateTests
{
private ViewModelToGenerate _viewModelToGenerate1;
private ViewModelToGenerate _viewModelToGenerate2;
private readonly ViewModelToGenerate _viewModelToGenerate1;
private readonly ViewModelToGenerate _viewModelToGenerate2;
private static readonly string[] commandNames = new[] { "SaveCommand" };

public ViewModelToGenerateTests()
{
Expand Down Expand Up @@ -214,7 +215,7 @@ public void ShouldNotBeEqualDifferentCommandInvalidationsToGenerate2()
{
var list = (List<CommandInvalidationToGenerate>)_viewModelToGenerate2.CommandInvalidationsToGenerate!;

list.Add(new CommandInvalidationToGenerate("LastName", new[] { "SaveCommand" }));
list.Add(new CommandInvalidationToGenerate("LastName", commandNames));

Assert.NotEqual(_viewModelToGenerate1, _viewModelToGenerate2);
}
Expand All @@ -225,7 +226,7 @@ public void ShouldNotBeEqualDifferentCommandInvalidationsToGenerate3()
var list = (List<CommandInvalidationToGenerate>)_viewModelToGenerate2.CommandInvalidationsToGenerate!;

list.Clear();
list.Add(new CommandInvalidationToGenerate("LastName", new[] { "SaveCommand" }));
list.Add(new CommandInvalidationToGenerate("LastName", commandNames));

Assert.NotEqual(_viewModelToGenerate1, _viewModelToGenerate2);
}
Expand Down Expand Up @@ -428,36 +429,36 @@ private static void FillAllProperties(ViewModelToGenerate viewModelToGenerate)

viewModelToGenerate.PropertiesToGenerate = new List<PropertyToGenerate>
{
new PropertyToGenerate("FirstName","string","_firstName",false)
new("FirstName","string","_firstName",false)
};

viewModelToGenerate.CommandsToGenerate = new List<CommandToGenerate>
{
new CommandToGenerate(new CommandMethod("OnSave"),"SaveCommand")
new(new CommandMethod("OnSave"),"SaveCommand")
};

viewModelToGenerate.CommandInvalidationsToGenerate = new List<CommandInvalidationToGenerate>
{
new CommandInvalidationToGenerate("FirstName",new []{"SaveCommand"})
new("FirstName", commandNames)
};

viewModelToGenerate.InjectionsToGenerate = new List<InjectionToGenerate> {
new InjectionToGenerate("IEventAggregator","EventAggregator"){ PropertyAccessModifier ="public"}
new("IEventAggregator","EventAggregator"){ PropertyAccessModifier ="public"}
};

viewModelToGenerate.BaseClassInjectionsToGenerate = new List<InjectionToGenerate> {
new InjectionToGenerate("IEventAggregator","EventAggregator"){ PropertyAccessModifier ="public"}
new("IEventAggregator","EventAggregator"){ PropertyAccessModifier ="public"}
};

viewModelToGenerate.ViewModelFactoryToGenerate = new FactoryToGenerate("FactoryClassName", "FactoryInterfaceName", "CustomReturnType");
viewModelToGenerate.ViewModelInterfaceToGenerate = new InterfaceToGenerate("InterfaceName")
{
Properties = new List<InterfaceProperty> { new InterfaceProperty("FirstName", "string", false) },
Properties = new List<InterfaceProperty> { new("FirstName", "string", false) },
Methods = new List<InterfaceMethod>
{
new InterfaceMethod("OnSave","void", false)
new("OnSave","void", false)
{
Parameters = new List<InterfaceMethodParameter>{new InterfaceMethodParameter("parameter","object")}
Parameters = new List<InterfaceMethodParameter>{new("parameter","object")}
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static class ModelMemberInspector
if (modelTypedConstant.Value.Value is INamedTypeSymbol model)
{
wrappedModelType = $"{model}";
wrappedModelPropertyName = wrappedModelPropertyName ?? "Model";
wrappedModelPropertyName ??= "Model";
var members = GetAllMembers(model);
foreach (var member in members)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ internal static IEnumerable<InjectionToGenerate> Inspect(INamedTypeSymbol? viewM
var count = 1;
foreach (var injectionToGenerate in duplicatePropertyGroup)
{
injectionToGenerate.PropertyName = injectionToGenerate.PropertyName + count++;
injectionToGenerate.PropertyName += count++;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Configurations>Debug;Release;MvvmGen_PureCodeGeneration</Configurations>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' != 'MvvmGen_PureCodeGeneration'">
Expand Down
6 changes: 3 additions & 3 deletions src/MvvmGen.SourceGenerators/ViewModelGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
InheritFromViewModelBase = ViewModelBaseClassInspector.Inspect(viewModelClassSymbol, viewModelBaseClassSymbol),
CommandsToGenerate = commandsToGenerate,
PropertiesToGenerate = propertiesToGenerate,
CommandInvalidationsToGenerate = commandInvalidationsToGenerate
CommandInvalidationsToGenerate = commandInvalidationsToGenerate,
WrappedModelPropertyName = ViewModelAttributeInspector.InspectModelPropertyName(viewModelAttributeData),
WrappedModelPropertiesToIgnore = ViewModelAttributeInspector.InspectModelPropertiesToIgnore(viewModelAttributeData)
};

viewModelToGenerate.WrappedModelPropertyName = ViewModelAttributeInspector.InspectModelPropertyName(viewModelAttributeData);
viewModelToGenerate.WrappedModelPropertiesToIgnore = ViewModelAttributeInspector.InspectModelPropertiesToIgnore(viewModelAttributeData);
viewModelToGenerate.WrappedModelType =
ModelMemberInspector.Inspect(viewModelAttributeData,
viewModelToGenerate.PropertiesToGenerate,
Expand Down

0 comments on commit eae8787

Please sign in to comment.