Giter VIP home page Giter VIP logo

purityanalyzer's Introduction

Hello.

My name is Yacoub Massad. I am a Software Architect/Developer working at Zeva International. I develop software using C# and .NET.

I am very interested in learning and teaching others about coding principles and practices that aim at creating maintainable software.

You can see my blog here: criticalsoftwareblog.com.

I recently started a youtube channel about Roslyn, the C# compiler. Click here to see the channel: Learn Roslyn by example.

I am also the creator of DIVEX, a dependency injection tool that allows you to compose objects and functions in C# in a way that makes your code more maintainable.

purityanalyzer's People

Contributors

ymassad avatar

Stargazers

 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

Forkers

seerek dererafi

purityanalyzer's Issues

VS2019 Compatability

@ymassad hey Yacoub, I recently read your articles on dotnetcurry and wanted to try your extension in VS2019. I downloaded the .vsix file and was met with this curious error.

In any event, thanks!
image

Support the [Pure] attribute from System.Diagnostics.Contracts

Can the analyzer also work with the [Pure] attribute from System.Diagnostics.Contracts?

I don't want to introduce an extra [IsPure] attribute. There is one already in the framework. I would prefer to use that one. A lot of OSS projects have annotated there code with the [Pure] attribute. I want to use this analyzer to check their implementation.

Thanks,

Fons

Handle FormattableString.Invariant(const interpolated string)

I think that PurityAnalyer should not allow this:

public static void M()
{
    FormattableString fs = $"{1}";

    Do(fs);
}
public static void Do(FormattableString fs)
{
    var result = FormattableString.Invariant(fs);
}

As far as Do is concerned, the arguments in fs might have impure ToString methods, and we cannot know that at compile time.

So we cannot consider FormattableString.Invariant to be pure. What we can do however, is give special handling to this:

FormattableString.Invariant( $"{1}");

That is, when the parameter given to Invariant is a constant.

By default, as far as PurityAnalyzer is concerned, a method is either pure or not.

However, this might be used often enough to justify special handling.

Visual Studio 2022 Support

Hi @ymassad,

I am setting this issue as a placeholder for Visual Studio 2022 support.

Thank you in advance for your extension and work! ๐Ÿฅ‡

Publish a NuGet package

The PurityAnalyzer is now only a Visual Studio Extension. Can you also publish a NuGet package for it? I want to use it without the need to install the extension. The NuGet (analyzer) package would allow me to analyze only certain projects in my solution.

Regards,

Fons

Casting to object impure?

While working on #5 I've tested latest (github) version of PurityAnalyzer and found strange behavior related to casting.

Given following code:

 [IsPure] private static string AliasWithNo(int number) => "test_" + number;

PurityAnalyzer underlined number and said:

Cast is impure.
Error casting.
From: System.Int32
To: System.Object
Relevant methods: System.Object.ToString()

This make me notice that int.ToString() is impure but I don't understand why cast to object is impure?
Strangely enough changing "test_" + number to $"test_{number}" removes the error.

But, knowing that int.ToString() is impure I've changed it to FormattableString.Invariant($"test_{number}") and added

System.FormattableString, Invariant(System.FormattableString)
System.FormattableString, ToString()

to PureMethods.txt
but then I've again received error

Cast is impure.
Error casting.
From: System.String
To: System.FormattableString
Relevant methods:
System.FormattableString.get_Format
System.FormattableString.GetArguments
System.FormattableString.get_ArgumentCount
System.FormattableString.ToString
System.FormattableString.ToString
System.Object.GetHashCode

  • Why is casting to object impure? (I guess because of impure ToString())
  • How to resolve cases like above?
  • is GetHashCode really impure?
  • Or maybe it's just unfinished feature

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.