danielpalme / ReportGenerator

ReportGenerator converts coverage reports generated by coverlet, OpenCover, dotCover, Visual Studio, NCover, Cobertura, JaCoCo, Clover, gcov or lcov into human readable reports in various formats.
https://reportgenerator.io
Apache License 2.0
2.58k stars 281 forks source link

Net config filters are not handled properly #604

Closed hivenet-emmanuel-titan closed 1 year ago

hivenet-emmanuel-titan commented 1 year ago

Describe the bug If a .netconfig file is defined with assemblyfilters, or classfilters, they are not taken into account.

To Reproduce

  1. Create a .netconfig file, and specify some assemblyfilters (In my case, was : assemblyfilters = -*.Test, to exclude my tests projects and classfilters = -*.g.cs to exclude generated files)
  2. run reportgenerator on cmd.
  3. filters are not applied

Maybe because default values of command line takes precedence over .netconfig file ?

[ReportGenerator]
    assemblyfilters =-*.g.cs
    classfilters =-*.Test
    reports = coverage.xml
    targetdir = coveragereport
danielpalme commented 1 year ago

If you use a .netconfig file, the values are only applied if you don't specify the corresponding command line parameter. Command line always takes precedence.

See: https://github.com/danielpalme/ReportGenerator/blob/d472d5d95eaf7806969e1f814d71ad7e810dcc68/src/ReportGenerator.Core/ReportConfigurationBuilder.cs#L136-L148

The idea is, that you put common values in the .netconfig file and only specify additional/deviating values on the command line.

hivenet-emmanuel-titan commented 1 year ago

I do not use any command line parameter

danielpalme commented 1 year ago

Maybe your .netconfig file is formatted in the wrong way? Maybe you need a space after the "="?

[ReportGenerator]
    assemblyfilters = "-*.g.cs"
    classfilters = "-*.Test"
    reports = coverage.xml
    targetdir = coveragereport
hivenet-emmanuel-titan commented 1 year ago

Nope, doesn't work. Tried with the exact config you gave, and command line reportgenerator I still have my \<projectName>.Test projects inside report.

And console output shows that .g.cs files are not excluded :

2023-04-19T11:52:05: File 'C:\Users\DuAel\source\repos\hive-cloudbridge\HiveCloudBridge.Common\System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\ModelGenerationContext.Volume.g.cs' does not exist (any more).

danielpalme commented 1 year ago

Thanks for the console output. Now I think I know what's wrong.

There are 3 filter options in ReportGenerator:

image

According to your console output you are trying to filter certain files. For files you have to use filefilters. Filefilters can be used to filter files within a class. If all files of a class are filtered, the whole class will be filtered.

E.g.

[ReportGenerator]
    filefilters = "-*.g.cs"
    classfilters = "-*.Test"
    reports = coverage.xml
    targetdir = coveragereport
hivenet-emmanuel-titan commented 1 year ago

Works like a charm, thanks