dotnet/roslyn

Extract method over-indents second line of expression

Open

#21,453 opened on Aug 11, 2017

View on GitHub
 (2 comments) (0 reactions) (0 assignees)C# (20,414 stars) (4,257 forks)batch import
Area-IDEBugFeature - Extract MethodIDE-Formatterhelp wanted

Description

Version Used: 15.3 Preview 7

:link: Originally revealed by ExtractMethodTests.TestUseExpressionWhenOnSingleLine_AndNotIsOnSingleLine in #21439.

Steps to Reproduce:

  1. Use the following code

    using System;
    
    namespace ConsoleApp5
    {
        class Program
        {
            static void Main(string[] args)
            {
                bool b = true;
                Console.WriteLine(b !=
                    true ? b = true : b = false);
            }
        }
    }
    
  2. Select b != true

  3. Apply the Extract Method refactoring

Expected Behavior:

using System;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            bool b = true;
            Console.WriteLine(NewMethod(b) ? b = true : b = false);
        }

        private static bool NewMethod(bool b)
        {
            return b !=
                true;
        }
    }
}

Actual Behavior:

using System;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            bool b = true;
            Console.WriteLine(NewMethod(b) ? b = true : b = false);
        }

        private static bool NewMethod(bool b)
        {
            return b !=
                            true;
        }
    }
}

Contributor guide

Extract method over-indents second line of expression · dotnet/roslyn#21453 | Good First Issue