Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HereDoc constant generation causes syntax errors in generated RBIs #102

Open
AaronC81 opened this issue Aug 14, 2019 · 3 comments
Open

HereDoc constant generation causes syntax errors in generated RBIs #102

AaronC81 opened this issue Aug 14, 2019 · 3 comments
Labels
bug Something isn't working external The issue is caused by a problem in a different project

Comments

@AaronC81
Copy link
Owner

Describe the bug
If a constant's value is a HereDoc, the generated RBI contains syntax errors due to the weird syntax of HereDocs in method calls. (I found this when generating an RBI for Rack.)

To Reproduce
Generate an RBI for this code:

module Foo
  CONST = <<-HERE
    This is a heredoc.
  HERE
end

Expected behavior

# typed: strong
module Foo
  CONST = T.let(<<-HERE, T.untyped)
    This is a heredoc.
  HERE
end

Actual behavior

# typed: strong
module Foo
  CONST = T.let(<<-HERE
  This is a heredoc.
HERE, T.untyped)
end
@AaronC81 AaronC81 added the bug Something isn't working label Aug 14, 2019
@connorshea
Copy link
Contributor

  class IDNumber < Faker::Base
    CHECKS = T.let('TRWAGMYFPDXBNJZSQVHLCKE', T.untyped)
    INVALID_SSN = T.let([
  /0{3}-\d{2}-\d{4}/,
  /\d{3}-0{2}-\d{4}/,
  /\d{3}-\d{2}-0{4}/,
  /666-\d{2}-\d{4}/,
  /9\d{2}-\d{2}-\d{4}/
].freeze, T.untyped)
  end

This also happens in Faker :)

@AaronC81
Copy link
Owner Author

AaronC81 commented Mar 12, 2020

YARD doesn't appear to parse heredocs quite right, which means this can't be implemented perfectly now.

Given this file:

module X
  A = <<-EOF
    bar!
    EOF

  B = <<-EOF
  bar!
  EOF
end

p X::A
p X::B

Ruby preserves the indentation properly:

$ ruby test.rb                   
"    bar!\n"
"  bar!\n"

But YARD strips the indentation from both of them:

irb(main):010:0> YARD::Registry.root.children.first.children.map(&:value)
=> ["<<-EOF\nbar!\nEOF", "<<-EOF\nbar!\nEOF"]

I'll see if there's an existing issue for this on the YARD repo and open one if not.

@AaronC81 AaronC81 added the external The issue is caused by a problem in a different project label Mar 12, 2020
@dduugg
Copy link

dduugg commented May 11, 2023

Is lsegal/yard#1315 the resulting issue? If so, please take a look at lsegal/yard#1495 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working external The issue is caused by a problem in a different project
Projects
None yet
Development

No branches or pull requests

3 participants