I suggest you ...

Allow user-defined project-wide variables/properties

I've been factorizing my rules across all my projects and I've been reduced to set the maximum violation allowed among each project as the default value. Allowing developers in the lower count projects to violate rules more than I would like to.

I came by a little trick using my project prefix to do something like this :

warnif count > 0

let Prefix1ProjectCount = (from p in Projects where p.Name.StartsWith("Prefix1") select p).Count()
let Prefix2ProjectCount = (from p in Projects where p.Name.StartsWith("Prefix2") select p).Count()

let Prefix1CeilCount = 42
let Prefix2CeilCount = 18
let DefaultCeilCount = 0

// If project containes Prefix1 projects use Prefix1 ceil
// Else if project containes Prefix2 projects use Prefix2 ceil
// Else use Default ceil
let violationCeilCount = (Prefix1ProjectCount > 0 ? Prefix1CeilCount : (Prefix2ProjectCount > 0 ? Prefix2CeilCount : DefaultCeilCount))

let allViolations = (from f in Fields where /* Any filter matching my rule */) select f)

let allViolationsCount = allViolations.Count()

from violation in allViolations where allViolationsCount > violationCeilCount select violation

The problem being the loss of the violation count in the "#Items" column in the results.
It would be really nice to be able to define project-wide values/property (like the built-in JustMyCode) so it's possible to do something like :

ProjectFile :
...
<Properties>
<Property Name="MyRuleAllowedViolationCount" Value="42" />
</Properties>
<RuleFiles>
<RuleFile Active="True" Path=".\MyRuleFile.cdrules" />
</RuleFiles>
...

RuleFile :
...
<Query Active="True" DisplayList="True" DisplayStat="True" DisplaySelectionView="False" IsCriticalRule="True"><![CDATA[// <Name>My rule name</Name>
warnif count > MyRuleAllowedViolationCount
from f in Fields where /* Any filter matching my rule */ select f
]]></Query>
...

7 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    GARCIN DavidGARCIN David shared this idea  ·   ·  Admin →

    1 comment

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • GARCIN DavidGARCIN David commented  · 

        It would also be nice to be able to execute queries before the warnif keyword

      Feedback and Knowledge Base