nunit.analyzers icon indicating copy to clipboard operation
nunit.analyzers copied to clipboard

NuGet package should provide AllDisabled ruleset\config

Open payn-git opened this issue 11 months ago • 7 comments

Similar to Microsoft analyzers approach. NuGet package should always provide configuration for .ruleset and .config files with all rules listed as disabled. This is very often used on projects where project config derive from all disabled configuration and only individual rules required by project are enabled. Currently such all disabled ruleset have to be manually updated every time when new rule is included.. Simply replacing whole file with new version is much easier from maintenance point of view. As one doesn't need to spend time trying to figure out which rules was added to start with.

payn-git avatar Mar 18 '24 13:03 payn-git

@payn-git Just to be sure I understand, but you mean something like this dotnet/roslyn-analyzers#1718 that provides a lot of rulesets?

image

mikkelbu avatar Mar 18 '24 14:03 mikkelbu

Yes that's correct. Although, Im mostly interested only in AllDisabled variation of it as all projects are setup differently and I don't know anybody who have all enabled or all enabled per category etc. However, if all disabled\enabled\default version will be provided that would not harm anybody. Also please be aware that Microsoft provide both *.ruleset and also new *.config. In all our projects we use *.ruleset as that's more flexible than config files.

payn-git avatar Mar 18 '24 18:03 payn-git

@payn-git Microsoft has deprecated rulesets. But I see they still supplies them with the analyzer.

Just out of interest, why do you think rulesets are more flexible? Is that because you can reference them conditionally?

At my work we use .globalconfig files to share configuration between projects. They have similar format as .editorconfig and can be referenced in a Directory.Build.props like:

  <ItemGroup>
    <GlobalAnalyzerConfigFiles Include="$(NUnitAnalyzerConfigLocation)" />
  </ItemGroup>

@mikkelbu We should create these files automatically and check them in test to ensure new rules got added. Similar to what we for the documentation index.

manfred-brands avatar Mar 18 '24 23:03 manfred-brands

Its about ruleset hierarchy itself. In my personal POV Microsoft did terrible job with *.EditroConfig files which work on folder hierarchy structure. In old ruleset we can enforce rulesets hierarchy from any locations by using include which is widely used in corporate big projects. So I can do something like this. As far as I know there is not direct inclusion possible with *.EditroConfig. There was request in Git for Microsoft to provide same ability instead of cluttering folder structure approach, but as far as I know it was never resolved. One of those things which was perfectly fine, but Microsoft had to change them to make things worse :).

payn-git avatar Mar 19 '24 13:03 payn-git

Ruleset config example which was cut off from previous comment. <RuleSet Name="AllDisabled" Description="AllDisabled ruleset makes sure all analyzers are disabled by default." ToolsVersion="15.0"> <Include Path=".\AllDisabledRulesets\codingBot.analyzers.ruleset" Action="Default"/> <Include Path=".\AllDisabledRulesets\projectSpecificanalyzers.ruleset" Action="Default"/> <Include Path=".\AllDisabledRulesets\microsoft.netanalyzers.ruleset" Action="Default"/> <Include Path=".\AllDisabledRulesets\microsoft.threading.ruleset" Action="Default"/> <Include Path=".\AllDisabledRulesets\nunit.analyzers.ruleset" Action="Default"/> </RuleSet>

payn-git avatar Mar 19 '24 13:03 payn-git

@mikkelbu @manfred-brands I have a related question: is it possible to enable all NUnit.Analyzers diagnostics but not other diagnostics/rules?

Bartleby2718 avatar Apr 01 '24 02:04 Bartleby2718

@Bartleby2718 I presume you don't want to see the default Microsoft Rules? You can disable them by setting EnableNetAnalyzers to false.

manfred-brands avatar Apr 01 '24 03:04 manfred-brands