Search code examples
c#visual-studioresharperridereditorconfig

.editorconfig dotnet naming setting with Resharper


I am needing some help in understanding some of the behaviour related to .editorconfig file and how it behaves in relation to naming convention and inheritance. So I would like to introduce a naming styling for a certain project something akin to SomeType_RestOfTheName. However, I only want this name change to apply to a certain project not globally to the solution. This means I have end up with a structure similar to:

+ <root>
    - Root.sln
    - .editorconfig // has the root = true flag
    + test
        + project
            - project.csproj    
            - .editorconfig

The names are arbitrary.
Now the .editorconfig under the project folder is the one I have added and it has the following contents:

[*]
# Microsoft .NET properties
dotnet_naming_rule.types_and_namespaces_rule.import_to_resharper = as_predefined
dotnet_naming_rule.types_and_namespaces_rule.resharper_style = AaBb, SomeType_ + AaBb
dotnet_naming_rule.types_and_namespaces_rule.severity = warning
dotnet_naming_rule.types_and_namespaces_rule.style = upper_camel_case_style
dotnet_naming_rule.types_and_namespaces_rule.symbols = types_and_namespaces_symbols
dotnet_naming_style.lower_camel_case_style.capitalization = camel_case
dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case
dotnet_naming_symbols.types_and_namespaces_symbols.applicable_accessibilities = *
dotnet_naming_symbols.types_and_namespaces_symbols.applicable_kinds = namespace,class,struct,enum,delegate

As you can tell the other settings will be inherited from the .editorconfig in the root, and only the target project will have the specific naming convention.
NOTE: This works it does apply the appropriate naming style.
Now for my question.
If I move or comment out any of those settings above the whole naming convention fails with warnings. Why is that? Do all of these settings need to be configured together for it to work? And in respect to inheritance of the .editorconfig files; if I were to move all those settings expect the dotnet_naming_rule.types_and_namespaces_rule.resharper_style = AaBb, SomeType_ + AaBb setting to the root .editorconfig file the naming convention fails as well? Why is that? I thought that it would either use default or find the values in the root to the root .editorconfig?
Not this happens in both Rider and VS + Resharper, so not sure it is a Resharper or Rider related thing, or if it has to do with how some settings need to defined (i.e. the need to all be set together)?


Solution

  • For anyone that is curious, this was more of a user misunderstanding than an issue. On the MS documentation regarding naming styles in the .editorconfig file there is this line:

    All naming rule properties are required for a rule to take effect.
    

    Pretty much after playing around with the .editorconfig setting for naming I realized I was misunderstanding the structure a tad. Below I have modified the structure from above, hopefully for anyone that comes across this it makes sense:

    [*]
    # Microsoft .NET properties - SomeType_ naming rule block
    dotnet_naming_rule.sometype_prefix_rule.import_to_resharper = as_predefined
    dotnet_naming_rule.sometype_prefix_rule.resharper_style = AaBb, SomeType_ + AaBb
    dotnet_naming_rule.sometype_prefix_rule.severity = warning
    dotnet_naming_rule.sometype_prefix_rule.style = upper_camel_case_style
    dotnet_naming_rule.sometype_prefix_rule.symbols = sometype_prefix_symbols
    dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case
    dotnet_naming_symbols.sometype_prefix_symbols.applicable_accessibilities = *
    dotnet_naming_symbols.sometype_prefix_symbols.applicable_kinds = namespace,class,struct,enum,delegate
    

    But it boils down to the fact that you define a custom rule with a custom name, and you have to configure all the relavent properties otherwise the definition is malformed and not applied.