Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Reformat" breaks the pkl file validity #26

Open
asm0dey opened this issue Apr 19, 2024 · 7 comments
Open

"Reformat" breaks the pkl file validity #26

asm0dey opened this issue Apr 19, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@asm0dey
Copy link

asm0dey commented Apr 19, 2024

Let's say I have a poorly-formatted, but working file:

x = new Dynamic {
  modno = 33
  version = 1
  host = "blog"
  repos {
    new Dynamic {
      id = "ban-bot"
      uri = "url:/restic/ban-bot"
      password = "redacted"prunePolicy {
        maxFrequencyDays = 7
        maxUnusedPercent = 25
      }
    }
 };
 plans { new Dynamic { id = "ban-bot";
 repo = "ban-bot";
 paths { "xxx" };
 cron = "50 0 * * *";
 retention { policyTimeBucketed { hourly = 24;
 daily = 7;
 weekly = 4;
 monthly = 6;
 yearly = 2 } };
 hooks { new Dynamic { conditions { "CONDITION_ANY_ERROR" };
 actionGotify { baseUrl = "gotify";
 token = "redacted";
 template = "{{ .Summary }}";
 titleTemplate = "Backrest {{ .EventName .Event }} in plan {{ .Plan.Id }}" } } } };
 };
 auth { users { new Dynamic { name = "asm0dey";
 passwordBcrypt = "redacted" } } } }

When I run the command

pkl eval -f json test.pkl

It successfully compiles an expected json.
However, when I execute a "Reformat" action (and I do it all the time), I get the following:

x = new Dynamic {
  modno = 33
  version = 1
  host = "blog"
  repos {
    new Dynamic {
      id = "ban-bot"
      uri = "url:/restic/ban-bot"
      password = "redacted"prunePolicy {
        maxFrequencyDays = 7
        maxUnusedPercent = 25
      }
    }
  }plans { new Dynamic { id = "ban-bot"repo = "ban-bot"paths { "xxx" }cron = "50 0 * * *"retention { policyTimeBucketed { hourly = 24daily = 7weekly = 4monthly = 6yearly = 2 } }hooks { new Dynamic { conditions { "CONDITION_ANY_ERROR" }actionGotify { baseUrl = "gotify"token = "redacted"template = "{{ .Summary }}"titleTemplate = "Backrest {{ .EventName .Event }} in plan {{ .Plan.Id }}" } } } } }auth { users { new Dynamic { name = "asm0dey"passwordBcrypt = "redacted" } } } }

This file cannot be compiled to JSON anymore.

I would expect the "Reformat" to not break my code and, if possible, align it.

My environment:

IntelliJ IDEA 2024.1 (Ultimate Edition)
Build #IU-241.14494.240, built on March 28, 2024
...
Runtime version: 17.0.10+8-b1207.12 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 6.6.27-1-lts
...
Memory: 4040M
Cores: 16
Registry:
  debugger.auto.attach.from.console=true
  ide.experimental.ui=true
  llm.generate.commit.summary=true
  terminal.new.ui=true
  markdown.open.vcs.log.link=true
  search.everywhere.preview=true
  ide.smart.update=true
  editor.minimap.enabled=true
  jetbrains.tbe.show.error.popup=true
  shared.indexes.download.auto.consent=true
  jetbrains.tbe.branding.icon.show=false
Non-Bundled Plugins:
  com.intellij.grazie.pro (0.3.298)
  DevKit (241.14494.247)
  org.jetbrains.plugins.hocon (2024.1.0)
  org.pkl (0.26.0)
  woaini.liquibase.plugin (1.3-SNAPSHOT)
  com.intellij.ml.llm (241.14494.320)
  kotest-plugin-intellij (1.3.74-241.9959-EAP-CANDIDATE-SNAPSHOT)
  org.jetbrains.toolbox-enterprise-client (2024.3.0.2860-ij241)
  com.intellij.git.instant (1.3.8)
Kotlin: 241.14494.240-IJ
Current Desktop: KDE
@asm0dey asm0dey changed the title "Reformat" breaks the pkl fil evalidity "Reformat" breaks the pkl file validity Apr 19, 2024
@bioball bioball added the bug Something isn't working label Apr 19, 2024
@bioball
Copy link
Contributor

bioball commented Apr 19, 2024

Whew, that's a pretty ugly result from formatting. Thanks for the report.

@thefallentree
Copy link

the problem here is semicollon.

If you remove all the semicollons it should format correctly

@asm0dey
Copy link
Author

asm0dey commented Jun 5, 2024

Thanks for the answer! According to the docs, semicolon is an allowed delimiter. If it's not supported, I would expect it to be highlighted by the IDE. Also, IIRC, I got this ill-formatted pkl from the json module during import.

@asm0dey
Copy link
Author

asm0dey commented Jun 5, 2024

Just checked, when I use the following command:

pkl eval -p input="$(cat my.json)" -x 'new Parser {}.parse(read("prop:input"))' pkl:json

I've got an output that cannot be formatted by IDEA

@bioball
Copy link
Contributor

bioball commented Jun 5, 2024

Semicolons are treated as whitespace in Pkl. FYI; our style guide is to use them to separate inline object members--if object members are on their own line, semicolons should be omitted.

@asm0dey
Copy link
Author

asm0dey commented Jun 5, 2024

Got you, thanks! I think they should be underlined as incorrect then

@thefallentree
Copy link

Don’t get me wrong: I am just pointing out the problem that case formattter to act up is semicolon, it can be worked around by just removing every thing, but it’s better to be fixed .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants