Sonar.issue.ignore.multicriteria many files in one line? - sonarqube

SonaQube 9.1. Community Edition
sonar.issue.ignore.multicriteria=e1,e2,e3
sonar.issue.ignore.multicriteria.e1.ruleKey=java:S115
sonar.issue.ignore.multicriteria.e1.resourceKey=**/*Type.java
sonar.issue.ignore.multicriteria.e2.ruleKey=java:S115
sonar.issue.ignore.multicriteria.e2.resourceKey=**/*Enum.java
sonar.issue.ignore.multicriteria.e3.ruleKey=java:S115
sonar.issue.ignore.multicriteria.e3.resourceKey=**/NEStatus.java
Nice. This work fine.
But to much lines.
Is it possible smt like this?
sonar.issue.ignore.multicriteria=e1
sonar.issue.ignore.multicriteria.e1.ruleKey=java:S115
sonar.issue.ignore.multicriteria.e1.resourceKey=**/*Type.java,**/*Enum.java,**/NEStatus.java

Enterprise EditionVersion 8.9.6
The comma-separated path names didn't work. I had to proceed with individual ruleKey and resourceKeys for the same rule exclusion.

Related

Is there any way to categorize components generated from heat.exe into features?

AFAIK every component should belong to some feature. So, I wonder if heat.exe has any command to categorize components it generated into features. In my case I have thousands of components. So I need some automated way to categorize the components into features. Thanks.
You can base your categorization on component groups. If you logically split your files into different folders, and run heat.exe once per each folder, you'll end up with a number of ComponentGroup elements. Finally, split then into features.
Probably, not exactly what you're looking for, but kind of similar. And, as #Rob suggested, XSL is always the last resort.
There is nothing built into heat to do that. The only "categorization" supported is to use XSL to transform the output. XSL can do just about anything.

Eliminating code duplication in a single file

Sadly, a project that I have been working on lately has a large amount of copy-and-paste code, even within single files. Are there any tools or techniques that can detect duplication or near-duplication within a single file? I have Beyond Compare 3 and it works well for comparing separate files, but I am at a loss for comparing single files.
Thanks in advance.
Edit:
Thanks for all the great tools! I'll definitely check them out.
This project is an ASP.NET/C# project, but I work with a variety of languages including Java; I'm interested in what tools are best (for any language) to remove duplication.
Check out Atomiq. It finds code that is duplicate that is prime for extracting to one location.
http://www.getatomiq.com/
If you're using Eclipse, you can use the copy paste detector (CPD) https://olex.openlogic.com/packages/cpd.
You don't say what language you are using, which is going to affect what tools you can use.
For Python there is CloneDigger. It also supports Java but I have not tried that. It can find code duplication both with a single file and between files, and gives you the result as a diff-like report in HTML.
See SD CloneDR, a tool for detecting copy-paste-edit code within and across multiple files. It detects exact copyies, copies that have been reformatted, and near-miss copies with different identifiers, literals, and even different seqeunces of statements.
The CloneDR handles many languages, including Java (1.4,1.5,1.6) and C# especially up to C#4.0. You can see sample clone detection reports at the website, also including one for C#.
Resharper does this automagically - it suggests when it thinks code should be extracted into a method, and will do the extraction for you
Check out PMD , once you have configured it (which is tad simple) you can run its copy paste detector to find duplicate code.
One with some Office skills can do following sequence in 1 minute:
use ordinary formatter to unify the code style, preferably without line wrapping
feed the code text into Microsoft Excel as a single column
search and replace all dual spaces with single one and do other replacements
sort column
At this point the keywords for duplicates will be already well detected. But to go further
add comparator formula to 2nd column and counter to 3rd
copy and paste values again, sort and see the most repetitive lines
There is an analysis tool, called Simian, which I haven't yet tried. Supposedly it can be run on any kind of text and point out duplicated items. It can be used via a command line interface.
Another option similar to those above, but with a different tool chain: https://www.npmjs.com/package/jscpd

How can I search in Visual Studio and get it to ignore what is commented out?

I am refactoring a C++ codebase in Visual Studio 2005. I'm about half way through this process now and I've commented out a lot of old code and replaced or moved it. Now I'm searching to see that I have to change next but the search function keeps bringing me the old commented out stuff I no longer care about. I don't really want to delete that old code yet, just in case.
Is there any way I can search all files in the solution and get results ignoring what is commented out? I don't see a way in visual studio itself, is the perhaps a plug-in that would do it?
As the other provided solutions didn't work for me, I finally discovered the following solution:
^~(:b*//).*your_search_term
Short explanation:
^ from beginning of line
~( NOT the following
:b* any number of white spaces, followed by
// the comment start
) end of NOT
.* any character may appear before
your_search_term your search term :-)
Obviouly this will only work for // and ///-style comments.
You must click "Use Regular Expressions " Button (dot and asterisk) on your find window to apply regex search
In newer versions of visual studio .net regex is used which has a slightly different syntax:
^(?![ \t]*//).*your_search_term
My take:
yes you can use regular expressions, those tend to be too slow and thinking about them distracts from focusing on real stuff - your software.
I prefer non-obtrusive semi-inteligent methods:
Poor man's method:
Find references if you happen to use intelisense on
Or even better:
Visual assist and it's colored "Find all References" and "Go To" mapped to handy shortcuts. This speeds up navigation tremendously.
If you comment your old code with // you can use regular expressions while searching for something in your codebase. Something like this for example: ^[^/][^/].*your_function_name.*.
Previous answer gave a false-positive on cases where otherwise matching lines were placed on lines containing other source:
++i; // your_search_term gets found, don't want it found
So replaced the :b* with .* and added the <> so only entire words are found, and then went after some of the older C-style comments where there's a /* on the line:
^~(.*//)~(.*/\*).*<your_search_term>
In my case I was hunting for all instances of new, not amenable to refactor assistance, and boatloads of false-positives. I also haven't figured out how to avoid matches in quoted strings.
Just to add on, as I was doing a "find all" for division operator used in the code, used the below to exclude comments as well as </ and /> from aspx files:
^~(.*//)~(.*/\*)~(.*\<\/)~(.*/\>).*/
In Visual Basic within Visual Studio 2015, I was able to search for text outside of comments by adapting glassiko's comment from the most upvoted answer
^(?![ \t]*[']).*mysearchterm
And in C# you would use glassiko's comment exactly as it was
^(?![ \t]*//).*mysearchterm
Better use \s I think. ^(?![\s]*//).*your_search_term
delete the commented out code, it is in source control right? there is no need to keep it in the file as well.

can I do a regex search/replace in vs.net?

In vs.net, I want to search for all occurances of
[someWord]
in my .sql file, and replace it with
[SomeWord]
Is this possible? (notice the uppercasing of the first character in the result)
Yes you can do Regex searches/Replaces in vs.net, just make sure to check the box in the dialog. The regex syntax is different from the Perl/.Net one though. Pay attention to the differences in syntax.
There's some reference here:
http://www.codinghorror.com/blog/archives/000633.html
If it's just a certain word:-
s/\[someWord\]/[SomeWord]/
But it might just be better to use a replace function
If it's anything in square brackets.
s/\[[a-zA-Z]+\]/[\u\1]/
Not sure but you might open that sql file externally is some editor like notepad++ and replace the stuff accordingly.
Here, this is VS Addin for regex search and replace found on CodeProject. Be warned that the code was for VS 2003, but can be recompiled I'm sure for later versions of VS.NET.
Hope this helps,
Best regards,
Tom.

Logs Utility Applications

I have complex log files, which are full of noise.
Can someone recommand a simple utility program which I can use to define lines which I want to filter out, or highlight using wildcards or any other method?
As well, a utility that can find logs which fulfill a certain condition (e.g., contains a line of a certain template) among a directory full of logs?
Regards
Have a look at LogParser from Microsoft. It has a SQL-like query language to allow you to filter log files based on conditions. Jeff Atwood has a brief overview of it here.
There's always good old "grep".
I have used Bear tail with great success. They have a free as well as a paid version.
If you have a bit of time to play with PERL and regular expressions, this is the kind of thing they do beautifully.

Resources