AddAnyFile icon indicating copy to clipboard operation
AddAnyFile copied to clipboard

[Feature] The created file should conform to the .editorconfig rules (or other defaults set by the user)

Open sander1095 opened this issue 4 years ago • 2 comments

Description

If you currently create a .cs file, the file is just created without conforming to the rules of an .editorconfig in the project. This is a bit of shame, because it requires either manual editing of the created file or changes to the templates of this extension. This wastes the developers time and makes the extension difficult to use for multiple projecs with different code styles.

I think it would be a nice addition to make the file conform to the .editorconfig of the project, or the formatting preferences of the user's IDE. Perhaps an abstraction for this already exists because format document in VS listens to the editorconfig or if that odes not exist, to the VS settings.

This also covers #50 and #67.

Steps to reproduce

Expected behavior:

  • Create a new .cs file
  • Have an editorconfig that would make the created cs file look different than what is created
  • the created .cs should be formatted as required by the editorconfig.

Actual behavior:

  • the file looks different!

Example

  • have an .editorconfig file with the following in it: csharp_style_namespace_declarations = file_scoped:warning
  • Create .cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SomeNamespace
{
    public class Foo
    {

    }
}

If this extension would format the file according to the rules of the editorconfig (and format it after creation), it could look like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SomeNamespace;

public class Foo
{

}

Benefits

  • You could use this extension in multiple projects/multiple teams and creating a file in each project would look the way it should, without needing any manual changes
  • The extension automatically supports new syntax thanks to new rules in the editorconfig.

sander1095 avatar Dec 30 '21 11:12 sander1095

Perhaps this should be a new issue, but perhaps the extension should also take a look if something like ImplicitUsings are used in the project. That way the using statements might not be required if they are already imported globally.

sander1095 avatar Dec 30 '21 11:12 sander1095

Was just looking for if there are possible settings I could set to make it not use blocked/braces based namespace.

ahmad2smile avatar Jan 01 '22 22:01 ahmad2smile