VladRassokhin / intellij-hcl

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

Plugin formatting forces newlines in undesired places (before comments, after opening [, etc) #310

Closed G-Rath closed 3 years ago

G-Rath commented 4 years ago

Prerequisites

Installation details

IntelliJ IDEA 2020.2 (Ultimate Edition) Build #IU-202.6397.94, built on July 27, 2020 Licensed to Gareth Jones Subscription is active until June 22, 2021 Runtime version: 11.0.7+10-b944.20 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Windows 10 10.0 GC: ParNew, ConcurrentMarkSweep Memory: 3014M Cores: 12 Registry: find.search.in.excluded.dirs=true, analyze.exceptions.on.the.fly=true, windows.jumplist=true, show.affected.tests.in.changelists=true, go.run.processes.with.pty=false, eslint.language.service.full.log=true Non-Bundled Plugins: CMD Support, Key Promoter X, PsiViewer, com.alayouni.ansiHighlight, com.intellij.apacheConfig, com.intellij.ideolog, String Manipulation, com.jetbrains.plugins.ini4idea, com.intellij.plugins.watcher, org.intellij.plugins.postcss, org.jetbrains.plugins.slim, de.thomasrosenau.diffplugin, lermitage.intellij.battery.status, name.kropp.intellij.makefile, net.seesharpsoft.intellij.plugins.csv, net.vektah.codeglance, org.elixir_lang, org.intellij.plugins.hcl, uk.co.ben-gibson.remote.repository.mapper, mobi.hsz.idea.gitignore, org.jetbrains.plugins.vagrant, AWSCloudFormation, com.intellij.kubernetes, org.sylfra.idea.plugins.linessorter, org.toml.lang, com.intellij.plugin.adernov.powershell, com.perl5, com.deadlock.scsyntax, com.intellij.plugins.webcomponents, com.jetbrains.lang.ejs, cucumber-javascript, intellij.prettierJS, jones.restarteslintaction.restart-eslint-action, com.dmarcotte.handlebars, com.emberjs, Dart, io.flutter, org.jetbrains.plugins.node-remote-interpreter, org.jetbrains.plugins.vue, org.jetbrains.kotlin, com.intellij.plugins.html.instantEditing, com.jetbrains.plugins.jade, com.intellij.lang.jsgraphql, com.jetbrains.php, com.jetbrains.php.blade, de.espend.idea.laravel, com.jetbrains.php.drupal, com.jetbrains.php.wordPress, com.raket.silverstripe, net.king2500.plugins.PhpAdvancedAutoComplete, org.jetbrains.plugins.phpstorm-remote-interpreter, org.jetbrains.plugins.phpstorm-docker, org.jetbrains.plugins.phpstorm-wsl, com.jetbrains.twig, org.jetbrains.plugins.ruby, jones.foldcallblocks.fold-call-blocks, org.jetbrains.plugins.ruby-chef, Pythonid, aws.toolkit, ru.meanmail.plugin.requirements, org.jetbrains.plugins.go, ru.adelf.idea.dotenv

Terraform Configuration Files

data "aws_iam_policy_document" "lambda_assume_role" { # comment
  statement {
    effect  = "Allow"
    actions = ["sts:AssumeRole"]

    principals {
      identifiers = ["lambda.amazonaws.com"]
      type        = "Service"
    }
  }
}

Expected Behavior

data "aws_iam_policy_document" "lambda_assume_role" { # comment
  statement {
    effect  = "Allow"
    actions = ["sts:AssumeRole"]

    principals {
      identifiers = ["lambda.amazonaws.com"]
      type        = "Service"
    }
  }
}

Actual Behavior

data "aws_iam_policy_document" "lambda_assume_role" {
  # comment
  statement {
    effect  = "Allow"
    actions = [
      "sts:AssumeRole"]

    principals {
      identifiers = [
        "lambda.amazonaws.com"]
      type        = "Service"
    }
  }
}

Steps to Reproduce

Apply formatting to code provided above.

nmarchini commented 3 years ago

I have this same error and it's intensely frustrating. You can adjust the behaviour like this I'm a MAC user so the Windows UI might be different

Preferences - Editor - Code Style - HashiCorp Configuration Language.

Click on Wrapping and Braces then Arrays - choose the option you want Click on Wrapping and Braces then Objects - choose the option you want Click on Other and then Align Properties set to On Equals

You can cut and paste your sample code into the sample window to see how it will be impacted by the changes.

If that doesn't work see if there is also a Terraform config option in the Code style tree as that might be where you need to set it

e.g Preferences - Editor - Code Style - Terraform config

G-Rath commented 3 years ago

@VladRassokhin any chance of getting this looked at? I'd be happy to take a crack at fixing it myself if I had the source code - if it helps, I have no issue signing docs like NDAs if that'd let me contribute.

VladRassokhin commented 3 years ago

I've updated formatting in 0.7.14, now it's more terraform fmt-like: Other :: Align Properties set to On Equals Wrapping and Braces :: Arrays set to Wrap if long Wrapping and Braces :: Objects set to Wrap if long

G-Rath commented 3 years ago

@VladRassokhin awesome thanks! I can confirm that formatting is working nicely, and that comments are no longer being pushed onto new lines - it does look like #269 is still present however.

As always let me know if I can help in anyway :)