VladRassokhin / intellij-hcl

HCL language support for IntelliJ platform based IDEs
Apache License 2.0
244 stars 47 forks source link

Values within for blocks are are not indented correctly #378

Open G-Rath opened 2 years ago

G-Rath commented 2 years ago

Prerequisites

Installation details

Version information ``` IntelliJ IDEA 2021.3.2 (Ultimate Edition) Build #IU-213.6777.52, built on January 28, 2022 Licensed to Gareth Jones Subscription is active until June 21, 2022. Runtime version: 11.0.13+7-b1751.25 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Windows 10 10.0 GC: G1 Young Generation, G1 Old Generation Memory: 3072M Cores: 12 Registry: ide.remote.interpreters.rsync.enabled.on.windows=true show.affected.tests.in.changelists=true Non-Bundled Plugins: org.toml.lang (213.5744.224) org.sylfra.idea.plugins.linessorter (1.0.1) org.jetbrains.plugins.go-template (213.6777.8) org.jetbrains.plugins.go (213.6777.52) net.vektah.codeglance (1.5.4) net.seesharpsoft.intellij.plugins.csv (2.18.2) name.kropp.intellij.makefile (213.5744.224) lermitage.intellij.battery.status (1.23.201) fr.gabrielcolson.prisma.prisma-intellij-plugin (1.2.4) com.sburlyaev.terminal.plugin (0.4.5) com.perl5 (2021.3.1) org.jetbrains.plugins.vagrant (213.5744.121) com.jetbrains.plugins.ini4idea (213.5744.190) com.intellij.plugins.watcher (213.6461.19) org.intellij.plugins.hcl (0.7.15) com.intellij.javafx (1.0.3) com.intellij.ideolog (203.0.27.0) org.jetbrains.plugins.ruby (213.6777.38) org.jetbrains.kotlin (213-1.6.10-release-944-IJ6461.79) org.jetbrains.plugins.slim (213.5744.224) org.intellij.plugins.postcss (213.5744.190) com.intellij.apacheConfig (213.5744.190) com.alayouni.ansiHighlight (1.2.4) com.intellij.plugin.adernov.powershell (2.0.9) String Manipulation (8.25.203.5981.1) Statistic (4.1.7) PsiViewer (213-SNAPSHOT) Key Promoter X (2021.3) uk.co.ben-gibson.remote.repository.mapper (3.3.6) mobi.hsz.idea.gitignore (4.3.0) Dummy Text Generator (1.2.0) com.intellij.kubernetes (213.6777.8) CMD Support (1.0.5) org.jetbrains.plugins.vue (213.6777.8) Dart (213.5744.122) io.flutter (63.2.4) mdx.js (1.0.213) jones.restarteslintaction.restart-eslint-action (0.0.1) intellij.prettierJS (213.6461.6) cucumber-javascript (213.6461.6) com.jetbrains.lang.ejs (213.5744.190) com.intellij.plugins.webcomponents (213.6461.6) com.intellij.lang.jsgraphql (3.1.2) jones.foldcallblocks.fold-call-blocks (0.0.7-beta) com.intellij.plugins.html.instantEditing (213.5744.122) com.jetbrains.plugins.jade (213.5744.223) com.jetbrains.php (213.6777.52) org.jetbrains.plugins.phpstorm-remote-interpreter (213.5744.125) org.jetbrains.plugins.phpstorm-wsl (213.5744.125) org.jetbrains.plugins.phpstorm-docker (213.5744.125) net.king2500.plugins.PhpAdvancedAutoComplete (1.1.0) com.raket.silverstripe (0.9.2.0) com.kalessil.phpStorm.phpInspectionsEA (4.0.7.1) com.jetbrains.twig (213.5744.224) com.jetbrains.php.wordPress (213.5744.125) com.jetbrains.php.drupal (213.5744.125) com.jetbrains.php.blade (213.6461.21) de.espend.idea.laravel (0.15.4) com.jetbrains.php.behat (213.5744.125) com.dmarcotte.handlebars (213.5744.190) com.deadlock.scsyntax (213.5744.190) Pythonid (213.6777.52) ru.meanmail.plugin.requirements (2022.2-2021.3) ru.adelf.idea.dotenv (2021.3.0.213) aws.toolkit (1.37-213) org.jetbrains.plugins.node-remote-interpreter (213.6777.8) AWSCloudFormation (213.5744.122) Kotlin: 213-1.6.10-release-944-IJ6461.79 ```

Terraform Configuration Files

locals {
  allowed_load_balancer_ip_ranges = [
    for ip in csvdecode(var.allowed_load_balancer_ip_ranges_csv) : ip["IP Address"]
  ]

  external_acl_rules = flatten([
    for ip in local.allowed_load_balancer_ip_ranges : [
      {
        protocol   = "tcp"
        rule_no    = 101 + (5 * index(local.allowed_load_balancer_ip_ranges, ip))
        action     = "allow"
        cidr_block = ip
        from_port  = 443
        to_port    = 443
      }
    ]
  ])

  load_balancer_acl_rules = coalescelist(
    local.external_acl_rules,
    // fallback to allowing everything if no external nacl rules have been provided
    [
      {
        protocol   = -1
        rule_no    = 100
        action     = "allow"
        cidr_block = "0.0.0.0/0"
        from_port  = 0
        to_port    = 0
      }
    ]
  )
}

Expected Behavior

This should be unchanged.

Actual Behavior

It gets formatted like this:

locals {
  allowed_load_balancer_ip_ranges = [
  for ip in csvdecode(var.allowed_load_balancer_ip_ranges_csv) : ip["IP Address"]
  ]

  external_acl_rules = flatten([
  for ip in local.allowed_load_balancer_ip_ranges : [
    {
      protocol   = "tcp"
      rule_no    = 101 + (5 * index(local.allowed_load_balancer_ip_ranges, ip))
      action     = "allow"
      cidr_block = ip
      from_port  = 443
      to_port    = 443
    }
  ]
  ])

  load_balancer_acl_rules = coalescelist(
    local.external_acl_rules,
    // fallback to allowing everything if no external nacl rules have been provided
    [
      {
        protocol   = -1
        rule_no    = 100
        action     = "allow"
        cidr_block = "0.0.0.0/0"
        from_port  = 0
        to_port    = 0
      }
    ]
  )
}

Steps to Reproduce

  1. Have above code
  2. Apply formatting
nirvana-msu commented 2 years ago

I can confirm the issue (for me it's within .hcl files for Packer, but it's exactly the same). Rather annoying as the auto-formatting is clearly off.