dotnet/roslyn

Extract method over-indents second line of expression

Aperta

#21.453 aperta il 11 ago 2017

 (2 commenti) (0 reazioni) (0 assegnatari)C# (4257 fork)batch import
Area-IDEBugFeature - Extract MethodIDE-Formatterhelp wanted

Metriche repository

Star
 (20.414 stelle)
Metriche merge PR
 (Merge medio 6g 17h) (256 PR mergiate in 30 g)

Descrizione

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;
        }
    }
}

Guida contributor