Can you override code analysis on a per file basis?

8 posts, 0 answers
  1. Kendall Bennett
    Kendall Bennett avatar
    80 posts
    Member since:
    Feb 2010

    Posted 10 Feb 2013 Link to this post

    I have some code that is auto generated using T4 templates, and as such does not necessarily follow the normal coding guidelines, as it creates internal private fields from the property name automatically by pre-pending an unscore. I have already enabled support for allowing an underscore at the stare of a private field, but in this case it is PascalCase, ie:

    [Column("address_book_id")] public int AddressBookID { get { return _AddressBookID; } set { _AddressBookID = value; MarkColumnModified("address_book_id"); } } int _AddressBookID;

    Now I could easily add a new rule to allow an underscore and then PascalCase for private fields, but that is not what I really want as I don't want that type of variable naming anywhere else in the code. I will allow it for the T4 generated code, but not in normal code.

    I noticed it is possible to ignore a particular error in a file and the warnings all go away, but as far as I can tell this is not stored anywhere in the project or solution file, so the next developer who loads the project (or myself when I get to work) is going to have to do the same ignore command. So is there a way to tell it to ignore this for that particular file only, and somehow store it in the project (or a pragma or something in the source file) so all the programmers don't have to do the same thing?

    If not I guess my only option is to fix the T4 templates to generate cleaner code, which I suppose I could do but I know I will run into this again somewhere else.
  2. Kendall Bennett
    Kendall Bennett avatar
    80 posts
    Member since:
    Feb 2010

    Posted 11 Feb 2013 Link to this post

    Beginning to think this is not possible at all, so I guess I will modify my T4 templates to make the code clean ...
  3. DevCraft banner
  4. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 13 Feb 2013 Link to this post

    Kendall,

    Sorry, perhaps this is a bit late, but you are correct, the Analysis and styling functions cannot be overridden like that.

    -- 
    Stuart
  5. Zdravko
    Admin
    Zdravko avatar
    657 posts

    Posted 13 Feb 2013 Link to this post

    Hello,

     Thanks for contacting us.
    If you have installed the latest JustCode internal build you will have the QuickFix command like in this demo. This way you could ignore errors / warnings and store them in the .JustCode folder in your solution.
    I hope this will help you.
    Thanks.

    Regards,
    Zdravko
    the Telerik team
    Share what you think about JustCode with us, so we can help you even better! You can use the built-in feedback tool inside JustCode, our forum, or our JustCode feedback portal.
  6. Kendall Bennett
    Kendall Bennett avatar
    80 posts
    Member since:
    Feb 2010

    Posted 13 Feb 2013 Link to this post

    It is worth pointing out that the ignore options get stored in a .JustCode directory for the solution. Given that these settings are probably wanted across developer machines, maybe it would make sense for them to be stored in the project file, so the information can be maintained in source control and every developer sees the same settings? Kind of like you can share the JustCode options in the solution file, but this would be for ignore settings in a single project file.

    Also it would be nice to be able to ignore a single warning in a file, or a single warning class, rather than having to ignore all warnings in a file. The XML in the .JustCode directory clearly indicates each warning is tagged separately, but you have to ignore them in an entire block for the entire file?
  7. Zdravko
    Admin
    Zdravko avatar
    657 posts

    Posted 15 Feb 2013 Link to this post

    Hi,

     Thanks for the reply.
    If you take a look at the QuickFixes pop up Visual aid menu you will find there that you can ignore only a single warning and also the function to "Find all such problems" and then ignore only them.
    I hope this will help you.
    Thanks. 

    All the best,
    Zdravko
    the Telerik team
    Share what you think about JustCode with us, so we can help you even better! You can use the built-in feedback tool inside JustCode, our forum, or our JustCode feedback portal.
  8. Kendall Bennett
    Kendall Bennett avatar
    80 posts
    Member since:
    Feb 2010

    Posted 16 Feb 2013 Link to this post

    Oddly I don't recall seeing that option, but I will investigate it some more now.

    However I still believe the warning ignoring options should be stored in the .csproj file, not in a separate .JustCode XML file as if we have a legit reason to ignore warnings on a particular item it should be the same for ALL developers on our team, not just me. For them to have to also re-ignore the same warnings (or for me to do it once at home on my laptop and once at work on my desktop) just seems wrong.

    For instance there are some warnings that I agree with 100%, for NORMAL code. Such as the class name needing to be the same as the file it is contained within. However in some instances we need to violate that concept, and we do it knowingly. A great example is the API interface file for our WCF services. We store ALL the DTO classes, ALL the DTO enumerations and the public WCF contract interface that defines our WCF contract in one single file, rather than splitting it up across multiple files. The primary reason for doing this is so that we can version the WCF contract file in one place, and we use the current source control revision number (we use Perforce) in our build system to define the API contract version. That way we have completely decoupled our client and server code to the point that we don't need to rebuild and re-deploy client code if it never changed, when we rebuild the server. We only have to do that if the WCF contract has been changed (and we enforce that when the client starts up, by checking the version it was compiled against when connecting to the server).

    So the catch is we have legit reasons to want to ignore warnings in certain files for certain classes for ALL our developers, and not have them need to do the same when they load a project the first time. Yet we don't want to turn off this option across the board because for the rest of our code, we follow the rules.

    Hence I need some way to preserve these warning settings that can be checked into source control, and given that the .JustCode directory is hidden, along with the file in it, it was clearly not intended to be stored in version control.
  9. Zdravko
    Admin
    Zdravko avatar
    657 posts

    Posted 18 Feb 2013 Link to this post

    Hello,

     Thank for the reply.
    We will consider your suggestion within the team.
    However, you can include the .JustCode folder to your version control so all users that use the source will have ignored the same errors.
    You can also add the file name to Exclude File Filters text box and no warning / errors will be shown from it. It is located at JustCode menu > Options > Code Analysis. Beware that every file containing the name will be ignored too.
    Thanks for helping us to improve JustCode.

    All the best,
    Zdravko
    the Telerik team
    Share what you think about JustCode with us, so we can help you even better! You can use the built-in feedback tool inside JustCode, our forum, or our JustCode feedback portal.
Back to Top
DevCraft banner