/Community

A Support Community for SubMain Products
in Search
Welcome to SubMain Community Sign in | Join | Help

exclude a scope

Last post 03-10-2008, 10:06 AM by Serge B.. 8 replies.
Sort Posts: Previous Next
  •  05-02-2007, 8:49 AM 186

    exclude a scope

    Hi,

     We have a guideline that member fields should start with m_ (e.g. m_engineType). I can indeed make such a rule.

    For static member fields however, we use s_ (e.g. s_dataProtection). Also this rule can be made fairly easy, changing the scope to Static only.

    The problem is that the m_ rule is also executed for the static member fields, even though Static is not ticked in the Scope. I guess that's because the scope includes "Private", and that this field is indeed also private.

     

    Is there a way to solve this?
     

  •  05-02-2007, 9:00 AM 188 in reply to 186

    Re: exclude a scope

    You are right it's tricky when your field is both private and static in the scenario you described.

    I don't have solution off the top of my head but I will this by the other dev team folks this week and get back to you.

    Thank you for the feedback! 

     


    Thank you,
    Serge Baranovsky
    http://submain.com - .NET Developer Tools  |  Microsoft VB MVP  |  http://vbcity.com - VB Developer Community
    » » (Static Code Analysis + Automatic Refactoring) / Painless Coding Guidelines = CodeIt.Right - http://submain.com/codeit.right
    » » C#/VB .NET Coding Guidelines - FREE 100+ page ebook (PDF) http://submain.com/guidelines
  •  02-29-2008, 8:20 AM 456 in reply to 188

    Huh? [:^)] Re: exclude a scope

    Hi Serge,

    In the mean time I bought a license, but actually forgot this was still a pending issue.

    Is there already a way to solve it? E.g. a hidden NonStatic scope classification that I could add in the xml file?
     

    Filed under:
  •  03-04-2008, 1:30 AM 457 in reply to 456

    Re: exclude a scope

    Hi Jurgen,

    Currently this only can be worked around with a custom rule.

    We are willing to develop that rule for you - please just tell us exactly what you want to achieve  

     


    Thank you,
    Serge Baranovsky
    http://submain.com - .NET Developer Tools  |  Microsoft VB MVP  |  http://vbcity.com - VB Developer Community
    » » (Static Code Analysis + Automatic Refactoring) / Painless Coding Guidelines = CodeIt.Right - http://submain.com/codeit.right
    » » C#/VB .NET Coding Guidelines - FREE 100+ page ebook (PDF) http://submain.com/guidelines
  •  03-05-2008, 12:29 AM 458 in reply to 457

    Re: exclude a scope

    Hi Serge,

    These are our naming conventions:

     

    Property

    Pascal Case

    Enum

    Pascal Case

    Const / readonly

    Pascal Case.

    Static field

    Prefix s_ and Camel Case. E.g. static int s_nextId;

    Note the small letter after s_!

    Instance field

    Prefix m_ and Camel Case. E.g. int m_stationPosition.
    Note the small letter after m_!

    Variable

    Camel Case: int stationPosition;

    Parameter

    Camel Case: (int stationPosition,…)

    The problem lays in the fact that we want to see from the name whether a field is static or not.

    So, for static fields we use the prefix s_ followed by Camel Case: e.g. s_nextId.

    For non-static member fields we use the prefix m_ followed by Camel Case e.g. m_stationPosition;

    As you can see, this is not possible as is with Codeit.Right since

    1) all conditions are "or'd"

    2) all rules are checked. There is no way to chnage the order and to say "if this rule aplies, don't check that other rule any more".

    Thanks for helping me out!

     
    Jurgen
     

    Filed under:
  •  03-05-2008, 11:19 PM 459 in reply to 458

    Re: exclude a scope

    Thank you Jurgen. We will work with this.

    Thank you,
    Serge Baranovsky
    http://submain.com - .NET Developer Tools  |  Microsoft VB MVP  |  http://vbcity.com - VB Developer Community
    » » (Static Code Analysis + Automatic Refactoring) / Painless Coding Guidelines = CodeIt.Right - http://submain.com/codeit.right
    » » C#/VB .NET Coding Guidelines - FREE 100+ page ebook (PDF) http://submain.com/guidelines
  •  03-06-2008, 11:41 AM 460 in reply to 459

    Re: exclude a scope

    Attachment: CustomRules_t459.zip

    Jurgen,

    Please find two custom rules attached to this post (with source code).

    You will need to copy the CustomRules\CustomRules\bin\Debug\CustomRules.dll file to "c:\Program Files\SubMain\CodeIt.Right\Rules\" and then add the two new rules to your profile - http://community.submain.com/blogs/howto/archive/2008/01/24/how-to-add-rule-to-user-profile.aspx

    Alternatively, you can merge the inner part of the SubMain.CodeItRight.RulesEngine.RulesProfile node below into your profile:

    <SubMain.CodeItRight.RulesEngine.RulesProfile Name="My Profile" Description="" Author="">
      <CustomRules.UsePrefixForStaticMember>
        <Scopes>Public, ProtectedInternal, Private, Abstract, Sealed, Readonly, Virtual, Override, Extern, Unsafe, SpecialName, Const, Volatile, WriteOnly, WithEvents, Default</Scopes>
        <Status>Active</Status>
        <Targets>Field</Targets>
        <Severity>Warning</Severity>
        <Title>Use "s_" prefix for static fields</Title>
        <Name>Static field -> Use "s_" prefix</Name>
        <NextCharCapitalizationStyle>Lower</NextCharCapitalizationStyle>
        <PrefixToCheck>s_</PrefixToCheck>
      </CustomRules.UsePrefixForStaticMember>
      <CustomRules.UsePrefixForNonStaticMember>
        <Scopes>Public, ProtectedInternal, Private, Abstract, Sealed, Readonly, Virtual, Override, Extern, Unsafe, SpecialName, Const, Volatile, WriteOnly, WithEvents, Default</Scopes>
        <Status>Active</Status>
        <Targets>Field</Targets>
        <Severity>Warning</Severity>
        <Title>Use "m_" prefix for non-static fields</Title>
        <Name>Non-static fields -> Use "m_" prefix</Name>
        <NextCharCapitalizationStyle>Lower</NextCharCapitalizationStyle>
        <PrefixToCheck>m_</PrefixToCheck>
      </CustomRules.UsePrefixForNonStaticMember>
    </SubMain.CodeItRight.RulesEngine.RulesProfile>

    Please let me know how these working out for you.


    Thank you,
    Serge Baranovsky
    http://submain.com - .NET Developer Tools  |  Microsoft VB MVP  |  http://vbcity.com - VB Developer Community
    » » (Static Code Analysis + Automatic Refactoring) / Painless Coding Guidelines = CodeIt.Right - http://submain.com/codeit.right
    » » C#/VB .NET Coding Guidelines - FREE 100+ page ebook (PDF) http://submain.com/guidelines
    Filed under: , ,
  •  03-10-2008, 3:18 AM 462 in reply to 460

    Re: exclude a scope

    Hi Serge,

     
    This works like a charm. Thanks a lot. You guys are really a refreshing company to work with.

     
    Jurgen

     

  •  03-10-2008, 10:06 AM 463 in reply to 462

    Re: exclude a scope

    Jurgen,

    Thank you!

    This is the best compliment for us!

     


    Thank you,
    Serge Baranovsky
    http://submain.com - .NET Developer Tools  |  Microsoft VB MVP  |  http://vbcity.com - VB Developer Community
    » » (Static Code Analysis + Automatic Refactoring) / Painless Coding Guidelines = CodeIt.Right - http://submain.com/codeit.right
    » » C#/VB .NET Coding Guidelines - FREE 100+ page ebook (PDF) http://submain.com/guidelines
View as RSS news feed in XML