0

I have the following lines defined in my .editorconfig file:

# Ignore paths
[Assets/NRSDK/*]

[Assets/VLCUnity/*]

generated_code = true

But they are ineffective, every time I run dotnet-format it still format everything under them. Is it feature broken? What can be done to make it honoured?

tribbloid
  • 4,026
  • 14
  • 64
  • 103
  • 1
    `[Assets/NRSDK/*]` and `[Assets/VLCUnity/*]` are separate section headers. You need to use `[{Assets/NRSDK/*,Assets/VLCUnity/*}]` as your section header or repeat the name/value pair for both sections. – Jonathan Dodds Aug 06 '23 at 23:06
  • 1
    `generated_code` is used by the code analyzers but from the documentation it is not clear if `dotnet format` honors the `generated_code` value for all sub-commands. – Jonathan Dodds Aug 06 '23 at 23:16
  • 1
    Have you tried `dotnet format --exclude Assets/NRSDK Assets/VLCUnity`? – Jonathan Dodds Aug 06 '23 at 23:17
  • @JonathanDodds yes, and it only excludes "Assets/NRSDK", the other was ignored as an irrelevant argument – tribbloid Aug 09 '23 at 18:57
  • 1
    The documentation says "A space-separated list of relative file or folder paths to exclude from formatting." Do you try variants like `dotnet format --exclude "Assets/NRSDK Assets/VLCUnity"` or `dotnet format --exclude Assets/NRSDK --exclude Assets/VLCUnity`? – Jonathan Dodds Aug 09 '23 at 20:40
  • 1
    @JonathanDodds Thanks a lot `dotnet format --exclude Assets/NRSDK --exclude Assets/VLCUnity` does work. Would you like to write an answer so I can accept it? – tribbloid Aug 09 '23 at 22:38

2 Answers2

1

Try --exclude option, this is an example from docs

dotnet format --include ./src/ ./tests/ --exclude ./src/submodule-a/
iAlij
  • 26
  • 4
1

For the given .editorconfig content, [Assets/NRSDK/*] and [Assets/VLCUnity/*] are separate section headers. They don't combine. Use [{Assets/NRSDK/*,Assets/VLCUnity/*}] as the section header or duplicate the name/value pairs for both sections.

It appears that generated_code = true, while used by code analyzers, may not be recognized or honored by dotnet format. (Maybe that should be a feature request.)

The format subcommand has an --exclude switch. The switch can appear multiple times in the same command line.

The following should work:

dotnet format --exclude Assets/NRSDK --exclude Assets/VLCUnity
Jonathan Dodds
  • 2,654
  • 1
  • 10
  • 14