From 60e3364027fdc82754888d0775805c5d16fdd87b Mon Sep 17 00:00:00 2001
From: Franciscello <ftarulla@gmail.com>
Date: Thu, 9 Jun 2022 16:34:44 -0300
Subject: [PATCH] Fix formatter alias-def with no-space before equals (#12073)

---
 spec/compiler/formatter/formatter_spec.cr | 13 ++++++++++++-
 src/compiler/crystal/tools/formatter.cr   |  4 ++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/spec/compiler/formatter/formatter_spec.cr b/spec/compiler/formatter/formatter_spec.cr
index 3d3f77930cc8..7f49eb71f58e 100644
--- a/spec/compiler/formatter/formatter_spec.cr
+++ b/spec/compiler/formatter/formatter_spec.cr
@@ -733,7 +733,18 @@ describe Crystal::Formatter do
   assert_format "alias  Foo::Bar  =   Baz", "alias Foo::Bar = Baz"
   assert_format "alias A = (B)"
   assert_format "alias A = (B) -> C"
-
+  assert_format "alias Foo=Bar", "alias Foo = Bar"
+  assert_format "alias Foo= Bar", "alias Foo = Bar"
+  assert_format "alias Foo =Bar", "alias Foo = Bar"
+  assert_format "alias Foo::Bar=Baz", "alias Foo::Bar = Baz"
+  assert_format "alias Foo::Bar= Baz", "alias Foo::Bar = Baz"
+  assert_format "alias Foo::Bar =Baz", "alias Foo::Bar = Baz"
+  assert_format <<-BEFORE, <<-AFTER
+    alias Foo=
+    Bar
+    BEFORE
+    alias Foo = Bar
+    AFTER
   assert_format "lib Foo\nend"
   assert_format "lib Foo\ntype  Foo  =   Bar\nend", "lib Foo\n  type Foo = Bar\nend"
   assert_format "lib Foo\nfun foo\nend", "lib Foo\n  fun foo\nend"
diff --git a/src/compiler/crystal/tools/formatter.cr b/src/compiler/crystal/tools/formatter.cr
index cb2b0fd0cf69..7c28823a3798 100644
--- a/src/compiler/crystal/tools/formatter.cr
+++ b/src/compiler/crystal/tools/formatter.cr
@@ -4072,10 +4072,10 @@ module Crystal
         accept name
       else
         write name
+        next_token
       end
 
-      next_token_skip_space_or_newline
-
+      skip_space
       write_token " ", :OP_EQ, " "
       skip_space_or_newline