This is a migrated thread and some comments may be shown as answers.

Can you override code analysis on a per file basis?

7 Answers 71 Views
Code Analysis
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kendall Bennett
Top achievements
Rank 2
Kendall Bennett asked on 11 Feb 2013, 01:40 AM
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.

7 Answers, 1 is accepted

Sort by
0
Kendall Bennett
Top achievements
Rank 2
answered on 11 Feb 2013, 09:48 PM
Beginning to think this is not possible at all, so I guess I will modify my T4 templates to make the code clean ...
0
Stuart Hemming
Top achievements
Rank 2
answered on 13 Feb 2013, 11:38 AM
Kendall,

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

-- 
Stuart
0
Zdravko
Telerik team
answered on 13 Feb 2013, 04:26 PM
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.
0
Kendall Bennett
Top achievements
Rank 2
answered on 13 Feb 2013, 05:23 PM
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?
0
Zdravko
Telerik team
answered on 15 Feb 2013, 01:56 PM
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.
0
Kendall Bennett
Top achievements
Rank 2
answered on 16 Feb 2013, 06:41 PM
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.
0
Zdravko
Telerik team
answered on 18 Feb 2013, 12:18 PM
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.
Tags
Code Analysis
Asked by
Kendall Bennett
Top achievements
Rank 2
Answers by
Kendall Bennett
Top achievements
Rank 2
Stuart Hemming
Top achievements
Rank 2
Zdravko
Telerik team
Share this question
or