SergeyTeplyakov / ErrorProne.NET

Set of roslyn-based analyzers for catching common C# errors (inspired by Google's error-prone)
MIT License
869 stars 43 forks source link

Warn when a task is returned from the method inside 'using' block or using directive #248

Open SergeyTeplyakov opened 2 years ago

SergeyTeplyakov commented 2 years ago

This should be flagged as suspicious code:

public struct MyDisposable : IDisposable
    {
        public void Dispose() { }
    }

    internal class Program
    {
        static Task FooBar() { return Task.FromResult(0); }
        static Task Main(string[] args)
        {
            using var md = new MyDisposable();
            return FooBar();
        }
    }