1

In my project there is a YAML file for NewRelic newrelic.yml that has a line with Ruby code for setting app_name. The existing config is working, and I need to edit the file, but when I try to do a yarn commit it fail with the following error, that to me looks like a Prettier error.

I have tried to add #prettier-ignore before the line, but it still causes the commit to fail.

node_modules/prettier/index.js:13588
      throw error;
      ^

SyntaxError: Nested mappings are not allowed in compact mappings (18:13)
  17 |   # Relic.  For more details, see https://docs.newrelic.com/docs/apm/new-relic-apm/maintenance/renaming-applications
> 18 |   app_name: <%= ENV["SERVER_ENV"] == 'staging' ? 'MyApp (Staging)' : 'MyApp' %>
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

My code editor is VSCode incase that is relevant.

So I'd like to either figure out why the # prettier-ignore is not working as the prettier docs indicate it should. Or figure out how to get things formatted to pass, which is the preferred option obviously.

CanuckT
  • 321
  • 1
  • 3
  • 14

1 Answers1

1

Seems like Prettier doesn't handle ERB in YAML files.

I would add all common configurations into one block and would then re-use that block with YAML aliases.

common: &default_settings
  license_key: 1234
  log_lever: info
  # ...

production:
  <<: *default_settings
  app_name: MyApp

staging:
  <<: *default_settings
  app_name: MyApp (Staging)
spickermann
  • 100,941
  • 9
  • 101
  • 131
  • Thanks I will try that out, it seems that most of the tutorials out there show using ERB to set the names for different environments from the CONFIG_VARS and licence key too. So might just be better to have Prettier ignore the whole file. (Which is a bummer as it's nice to ensure the rest of the formatting is right). – CanuckT Nov 29 '20 at 02:46