Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nullcheck generates poor formatting #222

Open
JohanLarsson opened this issue Jul 13, 2019 · 1 comment
Open

Add nullcheck generates poor formatting #222

JohanLarsson opened this issue Jul 13, 2019 · 1 comment

Comments

@JohanLarsson
Copy link
Member

Before:

        protected override void StopListening(object source)
        {
            ((ICommand)source).CanExecuteChanged -= this.DeliverEvent;
        }

After:

        protected override void StopListening(object source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            } ((ICommand)source).CanExecuteChanged -= this.DeliverEvent;
        }
@JohanLarsson
Copy link
Member Author

JohanLarsson commented Aug 10, 2019

Too weird for today, failing tests:

            [Test]
            public static void WhenCastAndUnsubscribed()
            {
                var before = @"
namespace N
{
    using System;
    using System.ComponentModel;

    public class C
    {
        protected void M(object ↓source)
        {
            ((INotifyPropertyChanged)source).PropertyChanged -= this.M;
        }

        private void M(object sender, PropertyChangedEventArgs e)
        {
        }
    }
}";

                var after = @"
namespace N
{
    using System;
    using System.ComponentModel;

    public class C
    {
        protected void M(object source)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            ((INotifyPropertyChanged)source).PropertyChanged -= this.M;
        }

        private void M(object sender, PropertyChangedEventArgs e)
        {
        }
    }
}";
                RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after);
            }

            [Test]
            public static void WhenCastAndInvoked()
            {
                var before = @"
namespace N
{
    using System;
    using System.ComponentModel;

    public class C
    {
        protected void M(object ↓source)
        {
            ((string)source).ToString();
        }
    }
}";

                var after = @"
namespace N
{
    using System;
    using System.ComponentModel;

    public class C
    {
        protected void M(object source)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            ((string)source).ToString();
        }
    }
}";
                RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after);
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant