GithubHelp home page GithubHelp logo

jetbrains / resharper-cyclomatic-complexity Goto Github PK

View Code? Open in Web Editor NEW
120.0 25.0 17.0 7 MB

ReSharper plugin to measure cyclomatic complexity as you type

License: Apache License 2.0

C# 83.92% C++ 2.19% JavaScript 4.05% TypeScript 3.05% PowerShell 5.21% Kotlin 1.57%
resharper resharper-plugin plugin cyclomatic-complexity jetbrains

resharper-cyclomatic-complexity's Introduction

official JetBrains project

Rider ReSharper

Cyclomatic complexity plugin for ReSharper

This is a ReSharper plugin that measures cyclomatic complexity as you type. If the complexity of a method, function or property exceeds a configurable threshold, the method, function or property is marked with a warning highlight ("squiggly"). Supported languages are C#, VB, JavaScript, TypeScript and C++.

It can be installed by going to ReSharper → Extensions Manager and searching for "Cyclomatic Complexity".

Cyclomatic complexity is a metric intended to show the complexity of your code. It measures the number of paths through a code block - the more branches and conditional statements, the higher the metric. As the code gets more complex, the metric gets higher. A higher value is a good indicator that a method is getting too complex, and is becoming a maintainability risk, and should be refactored. You can read more about cyclomatic complexity at wikipedia.

The complexity of a method, function or other code member is always available as a tooltip on the method name:

Complexity displayed as an info tooltip

When the complexity reaches a configurable threshold, the tooltip is shown as a warning:

Complexity exceeds the configurable threshold

And the complexity threshold can be configured in the options, per language:

Options

resharper-cyclomatic-complexity's People

Contributors

citizenmatt avatar ebrucucen avatar matkoch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

resharper-cyclomatic-complexity's Issues

Support for PhpStorm/WebStorm

Any chance of getting this plugin to work with WebStorm/PhpStorm (asked here too)?

Obviously not the C#, VB, and C++ bits. But the JavaScript and TypeScript support would be very useful in WebStorm / PhpStorm.

Cannot build from clone

When cloning the project, the build will fail due to problems with the ThemedIconConverter task. It looks like this task requires msbuild 4.0, but the SDK based .csproj requires msbuild 15.0+

It's probably time to retire the XAML based icons and use SVGs instead.

Update description for Rider

The Rider plugin uses the same description as the ReSharper plugin, which says it supports JavaScript and TypeScript. Rider uses WebStorm's web tooling, so does not support JS + TS.

Cyclomatic Complexity value from resharper is different compare to other evaluator

private static IEnumerable<Result> Update(IEnumerable<Config> configs, Req req)
{
    foreach(Config config in configs) {
        config.Setting1 = req.Setting1 ?? config.Setting1;
        config.Setting2 = config.Setting1 || (req.Setting2 ?? config.Setting2);
        config.Setting3 = req.Setting3 ?? config.Setting3;
        config.Setting4 = req.Setting4 ?? config.Setting4;
        config.Setting5 = req.Setting5 ?? config.Setting5;
        config.Setting6 = req.Setting6 ?? config.Setting6;

        if(req.performAction != true) {
         continue;
        }

        PerformAction(config);
        yield return new Result {
            Id = config.Id,
            Text = config.Text
        };
    }
}

Above method result as 24 cyclomatic complexity from this resharper plugin, while visual studio's analysis only shows complexity of 1. CodeMaid shows complexity of 1 as well.

I'm not sure which one did wrong, but its hard to manage project when every tools given different result while point out to article says it should keep at certain level.

Tooltip does not display

In previous versions mousing over the method showed the CC in a tooltip (as shown in your screenshots). But for me, this no longer works. Instead, it only shows in the status bar on the lower left-hand side and only when I click on the method vs. hover. Is this something new from you or something wrong with my installation.

Rider configuration

Hi,

I haven't been able to find the configuration for the Rider version of the plugin. Is there any? I've tried to look for Cyclomatic or Complexity words in the preferences pane of Rider.

Thanks for the help,
Cheers,
Attila

ReSharper 2016.3 Support

Hi,

Is there any plan to release 2016.3 installer for this package?
If not, could you provide a quick start on how to compile the project for that version?

Thanks,
Regards,
Attila

Optionally ignore C++ macros, etc.

From RSPL-6620:

It would be nice to add ability to exclude macro during complexity evaluation.

My case: i have function and it has assert macro. Windows assert macro has non-trivial definition and i get 8 points of complexity more with it in some expressions.

It would be nice to tell the plugin that i don't want to include some macro (or event function/method) for complexity calculation.

Not sure how this would work - ignore certain node types on the control flow graph?

Plugin seems to be ignored by ReSharper Command Line Tools

Hi,

I'm trying to use the plugin with the help of ReSharper Command Line Tools, but the output seems to be missing the Cyclomatic Complexity issues.

This is the command that I'm executing:
C:\ReSharperCLT\inspectcode.exe -x=PowerToys.CyclomaticComplexity -o="report.xml" CodeDuplicates.sln

The codebase, that I use to execute the command on, can be found at https://github.com/atzimler/CodeDuplicates.git .

I know for a fact that the VS R# with the plugin actually sees the issue, as I was using it during development of the example code.

Is there anything else that I'm missing or is this an issue?

Regards,
Attila

Wrong calculation in C# hint

In this screenshot

strange

I get a hint that makes no sense to me. All settings are left at the default threshold of 20 and the message states that a threshold of 1 is 5% of 20 which is incorrect. What's the reson for this?

R# 2017.1

Hi,

Is 2017.1 supported? The plugin does not seem to come up in the list of plugins able to install.

If I recall correctly, there was a similar issue with 2016.3, is there any way that I can help to solve this problem, so that I don't have to report it everytime Resharper is upgraded in version number?

Thanks,
Attila

Conflicting reports of complexity

image

If the image uploaded correctly, you can see that it's showing both a complexity rating of 11 and a message saying it's too complex to analyze. Is this an error or is it talking about two different types of complexity. I started getting both of these after installing the plugin (2019.1.0) today.

Thanks,

Morgan

Specific keywords like try and finally are adding to the Cyclomatic Complexity that should not

The CC does not appear to be calculating correctly. Below are two pairs of arbitrary methods to simplify the issue In pair 1 they should both be CC = 2 and in Pair 2 they should be CC = 1.

It appears that the Try and Finally are adding to the CC when they should be ignored. These pair of methods are identical within the pair and should have the same CC.

My understanding in CC is that at the least the following keywords are ignored:

else, do, switch, try, using, throw, finally, return

I didn't check all of them but found two and stopped as it should be easy enough for you guys to work out the rest.

// PAIR 1
// R# Ext CC = 2
private static string DoSomething1(string value)
{
    if (string.IsNullOrEmpty(value))
        value.ToString();

    return value;
}
// R# Ext CC = 6
private static string DoSomething2(string value)
{
    try
    {
        return value;
    }
    finally
    {
        if (string.IsNullOrEmpty(value))
            value.ToString();
    }
}
// PAIR 2
// R# Ext CC = 1
private static void DoSomething3()
{
            
}
// R# Ext CC = 3
private static void DoSomething4()
{
    try
    {
                
    }
    finally
    {
                
    }
}

Installation error

Hi,

I get this error when I install the plugin or any other in R# 2016.1
Loading an assembly “JetBrains.ReSharper.Resources, Version=105.0.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325” which is not listed in assembly references of assembly “JetBrains.ReSharper.Plugins.CyclomaticComplexity, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null” when trying to resolve the type JetBrains.ReSharper.Resources.Settings.CodeInspectionSettings. A type reference points into an assembly not listed among assembly references

Any idea?

Show methods that exceed the cyclomatic-complexity in code issue inspection results

Currently, for methods that exceed the cyclomatic-complexity threshold:

  1. They are underlined with "squiggles",
  2. They are indicated in the right-hand gutter within the editor (by default as a warning)
  3. If the warning is changed to an error, they show up in the error list.

However, if not set as an error, they are hard to discover as they do not show up when eg, Resharper->Inspect->Code issues in Solution is selected. It would be a useful addition to this extension for them to do so, if possible.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.