soutaro / rbs-inline

Inline RBS type declaration
MIT License
165 stars 6 forks source link

Comment style does not allow common linter-enforced style #73

Open myronmarston opened 6 days ago

myronmarston commented 6 days ago

I'm quite interested in using this once it becomes stable and is merged into RBS/steep proper. I haven't tried it yet, but one concern I had was about the end-of-line comment syntax:

some_expression #: [RBS type]

My concern is that this syntax does not appear to pass the comment style enforced by common Ruby linters like standardrb. Standard enables Layout/LeadingCommentSpace which would consider that a lint violation, requiring it to instead be written as:

some_expression # : [RBS type]

Can rbs-inline support both? I was curious if it already does and it looks like it doesn't. I applied this patch locally:

diff --git a/test/rbs/inline/writer_test.rb b/test/rbs/inline/writer_test.rb
index ae12f5a..cdcc3cd 100644
--- a/test/rbs/inline/writer_test.rb
+++ b/test/rbs/inline/writer_test.rb
@@ -130,7 +130,7 @@ class RBS::Inline::WriterTest < Minitest::Test
         end

         def hoge x,
-          y #: Integer
+          y # : Integer
         end
       end
     RUBY
@@ -465,7 +465,7 @@ class RBS::Inline::WriterTest < Minitest::Test
     output = translate(<<~RUBY)
       VERSION = "hogehoge"

-      SIZE = [123] #: Array[Integer]
+      SIZE = [123] # : Array[Integer]

       NAMES = __dir__

@@ -511,7 +511,7 @@ class RBS::Inline::WriterTest < Minitest::Test
       module Foo
         # @rbs @foo: String -- This is something

-        def foo #: void
+        def foo # : void
         end

         # @rbs self.@foo: Integer -- Something another
@@ -731,7 +731,7 @@ class RBS::Inline::WriterTest < Minitest::Test
       module M
         # @rbs module ClassMethods[A] : BasicObject
         class_methods do
-          def foo #: Integer
+          def foo # : Integer
             123
           end
         end

When I ran the tests I got failures:

Run options: --seed 64264

# Running:

..........................................................F.............F.....F....F.........

Finished in 0.065510s, 1419.6306 runs/s, 5190.0473 assertions/s.

  1) Failure:
RBS::Inline::WriterTest#test_constant_decl [test/rbs/inline/writer_test.rb:476]:
--- expected
+++ actual
@@ -1,6 +1,6 @@
 "VERSION: ::String

-SIZE: Array[Integer]
+SIZE: ::Array

 NAMES: untyped
 "

  2) Failure:
RBS::Inline::WriterTest#test_ivar [test/rbs/inline/writer_test.rb:521]:
--- expected
+++ actual
@@ -2,7 +2,7 @@
   # This is something
   @foo: String

-  def foo: () -> void
+  def foo: () -> untyped

   # Something another
   self.@foo: Integer

  3) Failure:
RBS::Inline::WriterTest#test_block__module_decl [test/rbs/inline/writer_test.rb:741]:
--- expected
+++ actual
@@ -1,7 +1,7 @@
 "module M
   # @rbs module ClassMethods[A] : BasicObject
   module ClassMethods[A] : BasicObject
-    def foo: () -> Integer
+    def foo: () -> untyped
   end
 end
 "

  4) Failure:
RBS::Inline::WriterTest#test_method_type__return_assertion [test/rbs/inline/writer_test.rb:138]:
--- expected
+++ actual
@@ -3,6 +3,6 @@

   def foo: (untyped x, untyped y) -> void

-  def hoge: (untyped x, untyped y) -> Integer
+  def hoge: (untyped x, untyped y) -> untyped
 end
 "

93 runs, 340 assertions, 4 failures, 0 errors, 0 skips