sord icon indicating copy to clipboard operation
sord copied to clipboard

Sord strips important information from included constants

Open connorshea opened this issue 6 years ago • 4 comments

Describe the bug

In YARD, this file can be found at lib/yard/server/commands/list_command.rb:

# frozen_string_literal: true
module YARD
  module Server
    module Commands
      class ListCommand < LibraryCommand
        include Templates::Helpers::BaseHelper

        def run
          # code
        end
      end
    end
  end
end

To Reproduce Run Sord on YARD and search for include BaseHelper in class ListCommand.

Expected behavior

class ListCommand < LibraryCommand
  include Templates::Helpers::BaseHelper

  # methods
end

Actual behavior Just BaseHelper is generated, which causes an error:

class ListCommand < LibraryCommand
  include BaseHelper

  # methods
end

connorshea avatar Jul 11 '19 01:07 connorshea

You can also see something similar happen in bundler.rbi where class RGProxy < ::Gem::SilentUI becomes class RGProxy < SilentUI, causing an Sorbet error.

connorshea avatar Jul 11 '19 01:07 connorshea

Changing name to path in https://github.com/AaronC81/sord/blob/master/lib/sord/rbi_generator.rb#L68-L73 produces this result instead:

class ListCommand < LibraryCommand
  include YARD::Templates::Helpers::BaseHelper
  # ...
end

This is probably better than the current behaviour, but still not identical to the original include.

AaronC81 avatar Jul 11 '19 08:07 AaronC81

With that change (after #90), it goes from 209 errors to 175 in sord_examples.

connorshea avatar Jul 20 '19 00:07 connorshea

Here's a related test:

it 'returns fully qualified classes' do
  YARD.parse_string(<<-RUBY)
    class Alphabet
    end

    class Letters < Alphabet
    end

    class A < Alphabet::Letters
      # @return [void]
      def x; end
    end
  RUBY

  expect(subject.generate.strip).to eq fix_heredoc(<<-RUBY)
    # typed: strong
    class Alphabet
    end
    
    class Letters < Alphabet
    end
    
    class A < Alphabet::Letters
      sig { void }
      def x; end
    end
  RUBY
end

connorshea avatar Jul 20 '19 02:07 connorshea