ruby / syntax_suggest

Searching for unexpected `end` syntax errors takes a lot of time. Let this gem do it for you!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`||=` Incorrect code removed to make an invalid block

schneems opened this issue · comments

This code is totally valid:

  def ruby_install_binstub_path(ruby_layer_path = ".")
    @ruby_install_binstub_path ||=
      if ruby_version.build?
        "#{build_ruby_path}/bin"
      elsif ruby_version
        "#{ruby_layer_path}/#{slug_vendor_ruby}/bin"
      else
        ""
      end
  end

But if it exists alongside of another syntax error like:

            def ruby_install_binstub_path(ruby_layer_path = ".")
              @ruby_install_binstub_path ||=
                if ruby_version.build?
                  "#{build_ruby_path}/bin"
                elsif ruby_version
                  "#{ruby_layer_path}/#{slug_vendor_ruby}/bin"
                else
                  ""
                end
            end

            def add_node_js_binary
              return [] if node_js_preinstalled?

              if Pathname(build_path).join("package.json").exist? ||
                  bundler.has_gem?('execjs') ||
                  bundler.has_gem?('webpacker')
                [@node_installer.binary_path]
              else
                []
              end
            end

            def add_yarn_binary
              return [] if yarn_preinstalled?
          | # <== HERE
              if Pathname(build_path).join("yarn.lock").exist? || bundler.has_gem?('webpacker')
                [@yarn_installer.name]
              else
                []
              end
            end

Then dead end will remove the inside of the method first, making it:

def ruby_install_binstub_path(ruby_layer_path = ".")
  @ruby_install_binstub_path ||=

end

Which is not valid. Then when it re-parses that code it thinks that it has a syntax error, so it's never hidden.

One possible solution is to change the valid? check inside of CodeBlock to re-parse all the code lines instead of only what's visible.