We are now ready to have some practice with dupFinder. If the /show-text option was enabled for analysis, then a Text node with the duplicated code is added to each fragment. Each Fragment element contains file name as well as duplicated piece presented in two alternative ways: as a file offset range and as a line range.Each Duplicate node has a Cost attribute: duplicates with greater cost are the most important ones as they potentially present greater problems.The Duplicates node contains Duplicate nodes, which in turn contain two or more Fragment elements.The Statistics node is an overview of analyzed code, where CodeBaseCost is the relative size of target source code, TotalFragmentsCost is the relative size of the code for analysis after applying filters (‘discard-cost’, ‘discard-literals’, etc.), and TotalDuplicatesCost is the relative size of detected duplicates.The resulting output is a single XML file that presents the following information: /show-text: if this parameter is used, detected duplicate fragments will be embedded into the report.The proper values will differ for different codebases. You’ll need to play a bit with this value to find a balance between avoiding false positives and missing real duplicates. If the ‘discard-cost’ value is less than 10, statements like that will appear as duplicates, which is obviously unhelpful. you can often have the following statements in tests: Assert.AreEqual(gold, result). Using this option, you can filter out equal code fragments that present no semantic duplication. The value for this option is provided in relative units. The fragments with lower complexity are discarded as non-duplicates. /discard-cost allows setting a threshold for code complexity of duplicated fragments.If ‘discard-literals’ is set to ‘false’, these fragments are considered duplicates. There are two code fragments otherwise identical, one contains myStatusBar.SetText("Logging In."), the other contains myStatusBar.SetText("Not Logged In"). To illustrate the way it works, consider the following example. The default value for all of them is ‘false’. /discard-fields, /discard-literals, /discard-local-vars, /discard-types specify whether to filter out similar fragments as non-duplicates if they have different variables, fields, methods, types or literals.‘generated code’ will exclude regions containing ‘Windows Form Designer generated code’). The value is a set of newline-delimited keywords (e.g. /exclude-by-comment and /exclude-code-regions allow excluding files by substrings of opening comments and regions.Note that the paths should be either absolute or relative to the working directory. The value is a set of newline-delimited wildcards (for example, **Generated*.cs). /exclude allows excluding files from duplicate code search.Below are some of the options that you might be interested in: To explore the full list of options, run dupFinder /help. Using optional parameters, you can configure how dupFinder should analyze your source code. Alternatively, you can provide a specific list of source files as a set of newline-delimited wildcards. One way to define the target sources is to specify a solution file: dupFinder understands solution files of Visual Studio 2003, 2005, 2008, 2010, and 2012. Run the following command: dupFinder source.Download and unzip ReSharper Command Line Tools.However, from now on you can get it running with your custom CI, version control, quality control or any other server and here is how: For quite a while, JetBrains TeamCity has included it out of the box, and this is probably the easiest and the most efficient way to make use of dupFinder. Running Duplicate AnalysisĭupFinder is not exactly a new kid on the block. Of course, you can configure allowed similarity level as well as the minimum relative size of duplicated fragments. By default, it considers code fragments as duplicates not only if they are identical, but also if they are structurally similar, even if they contain different variables, fields, methods, types or literals. Being a JetBrains tool, dupFinder does it in a smart way. But the package also includes another tool, dupFinder and we’ll take a closer look at it in this post.Īs its name suggests, dupFinder finds duplicates in C# and Visual Basic. We have already written about one of the tools included in this package - InspectCode, which analyzes your code outside of Visual Studio using hundreds of ReSharper code inspections. Along with ReSharper 8 EAP earlier this year, we have made ReSharper Command Line Tools available for you to download and try.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |