Skip to content

csharpier does not respect editorconfig specific c# rules #1214

@ghost

Description

Issue

Csharpier fails to adhere to the specified guidelines for .cs files.

.editorconfig

root = true

[*]
charset = utf-8
tab_width = 2
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 200

[*.{cs}]
indent_size = 4
tab_width = 4

Bonus: We do use [*.{cs,csx}] and [*.{cs}] sometimes. It would be nice if the "more specific" rule takes precedence. eg [.{cs}] is used ultimately for formatting.
But probably an override mechanism is necessary: base editor config rules + override with [*.{cs,csx}] + override with [*.{cs}], which results in formatting with indent_size = 4

Example:

[*]
charset = utf-8
tab_width = 2
indent_size = 2

[*.{cs,csx}]
indent_size = 3
tab_width = 3

[*.{cs}]
indent_size = 4
tab_width = 4

This example results in formatting with indent_size = 4

Input:

namespace X;

public class Resolver
{
    private const int SinglePhase = 1;

    public int Resolve(object source)
    {
        if (source is not string)
        {
            return default;
        }

        return 0;
    }
}

Output:

namespace X;

public class Resolver
{
  private const int SinglePhase = 1;

  public int Resolve(object source)
  {
    if (source is not string)
    {
      return default;
    }

    return 0;
  }
}

Expected behavior:

Csharpier does not change Input. Formatting Input results in Input

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions