Skip to content

Indentation/whitespace not kept if an element is added at runtime #102

@RivenSkaye

Description

@RivenSkaye

When loading in a TOML file and making sure to have sane defaults in the code for any keys that are missing, Tomlyn will apply the whitespace of the first known element to the current element, and then not apply it to the element it was read from. This subsequently has funky effects on the remainder of the output.

# This is the input file
[db.maria]
    database     = "Foo"
    load_balance = "LeastConnections"
    password     = "ENV:SUPER_SEKRIT"
    port         = 3306
    protocol     = "Socket"
    server       = "db.local.net"
    user         = "Who knows"

    [db.maria.misc]
        cancellation_timeout    = 15
        connection_timeout      = 60

    [db.maria.ssl]
        ssl_mode = "Preferred"

    [db.maria.pooling]
        connection_idle_timeout = 100
        connection_life_time    = 0
        connection_reset        = true
        dns_check_interval      = 0
        maximum_pool_size       = 15
        minimum_pool_size       = 1
        pooling                 = true

Gets mangled into (verbatim copy-pasted from serializing and printing TOML)

[db.maria]
    database     = "Foo"
    load_balance = "LeastConnections"
    password     = "ENV:SUPER_SEKRIT"
    port         = 3306
    protocol     = "Socket"
    server       = "db.local.net"
    user         = "Who knows"

    [db.maria.misc]
        cancellation_timeout    = 15
        connection_timeout      = 60

[db.maria.pooling]

    connection_idle_timeout = 100
        connection_life_time = 0
        connection_reset = true
        dns_check_interval = 0
        maximum_pool_size = 15
        minimum_pool_size = 1
        pooling = true

    [db.maria.ssl]
        ssl_mode = "Preferred"

Metadata

Metadata

Assignees

No one assigned

    Labels

    PR welcomeUser contribution/PR is welcomeenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions