erb renders array properly, but RM says syntax error

I'm not sure if this is a RM bug, a Chef Cookbook RM plugin bug or if I'm doing something wrong in terms of erb or HCL syntax and RM is picking up on my mistake. This is a snippet of the erb (ie myfile.hcl.erb) file that generates a configuration file:

server         = false
list_of_things = <%= @my_array.to_s %>
script_checks = true

RM marks the line `script_checks` with a syntax error. The tooltip reads `'(', <boolean>, <identifier>, <null>, <operator>, or <string literal> expected, got '='`

I _think_ this is because the syntax parser doesn't like the previous line. To the parser `<%= ... %>` doesn't look like a proper value type (String, Array, Hash, etc) but just looks like some weird unknown object type hanging out there. If the RH side of `list_of_things` is wrapped in quotes or brackets, RM is happy.

That's an issue because the rendered value needs to be written out as an HCL array. It needs to render literally as `list_of_things = [ "a", "b", "c" ]`. If wrapped in quotes, the HCL parser will assume the whole thing is a single string, and if wrapped in brackets, will treat it as a 3 item array nested in a 1 item array `[ [ "a", "b", "c" ] ]`

I don't think RM's syntax parser is strictly wrong. It has no idea that the rendered result will be correct, only that it looks like the HCL format is bad - an so marks the line and the file as having errors. The runtime ERB generator is fine with this as written, and the file renders properly.

Is this an issue with the RM parser, or is there another way I should be approaching this than `<%= @myarray.to_s %>` to get the rendered result I need, or some way to hint to RM that the final value will be a proper array?

edit: sorry for the inline code mess. there doesn't appear to be a way to do inline code format style, only block-level.

0
7 comments

Hello Richard,

I've tried to reproduce the problem in RubyMine 2021.1.1 but didn't manage to. Would it be possible to provide a project sample for that purpose?

0

Happy to! I don't see a way to attach files to this thread, so I uploaded a tarball to gist.

https://gist.github.com/rjhornsby/ab7a02f958c2b9e98ef4b976f3f1356d

base64 -d < rm_syntax_cookbook.tar.gz.base64 | tar -xvz -

on any mac or linux system should unpack it into a directory `rm_syntax`. Thanks!

Quick note about the attached screenshot - while the error appears on line 3, it's because the parser doesn't like line 2. Re-writing line 2 as

start_join  = ["<%= @node['consul']['config']['start_join'].join('","') %>"]

passes the parser checks, but is messy and more difficult to read. If using `join` in this way is the correct approach, and is less likely to break in the future than `to_s`, I'll go with it.

0

Hello Richard,

thank you for the project, but it works fine for me in RubyMine 2021.1.1 What are your IDE and Ruby versions?

0

I'm running RM 2021.1.1 with Ruby 2.7.3 that ships with cinc-workstation. It doesn't seem to help if I use rbenv ruby 2.7.1 or 2.7.2.

RubyMine 2021.1.1
Build #RM-211.7142.41, built on April 29, 2021
Runtime version: 11.0.10+9-b1341.41 x86_64
VM: Dynamic Code Evolution 64-Bit Server VM by JetBrains s.r.o.
macOS 10.15.7
GC: ParNew, ConcurrentMarkSweep
Memory: 1979M
Cores: 12
Registry: ide.balloon.shadow.size=0
Non-Bundled Plugins: CMD Support (1.0.5), codes.rudolph.idea.cfg (0.3.1), com.intellij.ideolog (203.0.27.0), com.intellij.properties (211.6693.44), com.intellij.plugins.watcher (211.6693.44), com.mallowigi (36.0), com.sburlyaev.terminal.plugin (0.4.4), org.intellij.plugins.hcl (0.7.10), mobi.hsz.idea.gitignore (4.1.0), name.kropp.intellij.makefile (211.6693.108), com.perl5 (2021.1), aws.toolkit (1.26-211), org.jetbrains.plugins.ruby-chef (211.6693.111)

 

0

Could you please try disabling all the 3rd party plugins and also HCL support plugin? How does it go in this case?

0

Disabling 3rd party plugins didn't change the behavior. By disabling the HCL plugin, RM no longer considers the syntax a problem. Not knowing the internals, I'd have to guess by looks of the editor window, this disabled all HCL validation/parsing.

0

Sorry for the delay. That appears to be more a HCL plugin's issue so could you please submit an issue on their tracker: https://github.com/VladRassokhin/intellij-hcl/issues

There's already one related to erb: https://github.com/VladRassokhin/intellij-hcl/issues/314

0

Please sign in to leave a comment.