GithubHelp home page GithubHelp logo

bkoelman / resharpercodecontractnullabilityfxcop Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 250 KB

Reports diagnostics, helping you to annotate your source tree with (Item)NotNull / (Item)CanBeNull attributes.

Home Page: https://www.jetbrains.com/resharper/help/Code_Analysis__Code_Annotations.html

C# 96.97% PowerShell 2.96% Batchfile 0.07%

resharpercodecontractnullabilityfxcop's Introduction

Resharper Code Contract Nullability FxCop Rules

Build status

This Visual Studio analyzer supports you in consequently annotating your codebase with Resharpers nullability attributes. Doing so improves the nullability analysis engine in Resharper, so NullReferenceExceptions at runtime will become something from the past.

Get started

  • You need Visual Studio 2013 (or lower) and Resharper v8 or higher to use this analyzer. See here if you use Visual Studio 2015 or 2017.

  • Activate the solution configuration in which you want to install (Debug/Release)

  • From the NuGet package manager console:

    Install-Package ResharperCodeContractNullabilityFxCop

    Install-Package JetBrains.Annotations

  • Rebuild your solution

Instead of adding the JetBrains package, you can put the annotation definitions directly in your source code. In that case, it's recommended to set both the conditional and internal options checked.

Analyzer in action

Building, Testing, and Debugging

To build, open ResharperCodeContractNullabilityFxCop.sln in Visual Studio 2013. Press Ctrl + R, A to run all unit tests. See How-to-debug.md for debugging instructions.

Trying out the latest build

After each commit, a new prerelease NuGet package is automatically published to AppVeyor at https://ci.appveyor.com/project/bkoelman/resharpercodecontractnullabilityfxcop/build/artifacts. To try it out, follow the next steps:

  • In Visual Studio: Tools, Options, NuGet Package Manager, Package Sources
  • Open the NuGet package manager console (Tools, NuGet Package Manager, Package Manager Console)
    • Select AppVeyor ResharperCodeContractNullabilityFxCop as package source
    • Run command: Install-Package ResharperCodeContractNullabilityFxCop -pre

Running on your build server

This assumes your project uses ResharperCodeContractNullabilityFxCop, but Resharper is not installed on your build server. To make the analyzer run there, make sure to install External Annotations on the server as a pre-build step:

  • nuget install JetBrains.ExternalAnnotations -Version 10.2.29
  • xcopy JetBrains.ExternalAnnotations.10.2.29\*.xml "%LOCALAPPDATA%\JetBrains\Installations\ReSharperPlatformVs15\ExternalAnnotations" /s /i /r /y /q

resharpercodecontractnullabilityfxcop's People

Contributors

bkoelman avatar

Watchers

 avatar  avatar

Forkers

feodorfitsner

resharpercodecontractnullabilityfxcop's Issues

Parameter name of indexer property is reported as Item; only one parameter is reported

Repro:

class C
{
    public int this[string a, string b, string c]
    {
        get { throw new NotImplementedException();}
        set { throw new NotImplementedException();}
    }
}

Expected:
Annotate 'a' with [NotNull] or [CanBeNull].
Annotate 'b' with [NotNull] or [CanBeNull].
Annotate 'c' with [NotNull] or [CanBeNull].

Actual:
Annotate 'Item' with [NotNull] or [CanBeNull].

Unexpected report on an array of value type

Repro:

class C
{
    byte[] f;
}

Reports:

Annotate 'f' with [ItemNotNull] or [ItemCanBeNull].

This is incorrect, because the underlying item type, byte in this case, cannot contain null.

Constructed array parameter from open generic interface with external annotation should not be reported

Example:

public class C : ICollection<string>
{
    // ...
    public void CopyTo(string[] array, int arrayIndex) { ... }
}

Reports:

Annotate 'array' with [NotNull] or [CanBeNull].

Which is incorrect, because an external annotation exists for ICollection.CopyTo:

<member name="M:System.Collections.Generic.ICollection`1.CopyTo(`0[],System.Int32)">
    <parameter name="array">
      <attribute ctor="M:JetBrains.Annotations.NotNullAttribute.#ctor" />
    </parameter>
  </member>

Because of this, Resharper grays out the annotation after manually adding it.

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.