Skip to content

[feat] Adjust entries order in TOML based on the order in JS Object #174

@DecimalTurn

Description

@DecimalTurn

At the moment, the following test is failling because during patching we won't add the KVP new_root = 42 above the mytable inline table even if it appears before it in the JS Object.

  test.skip('should add new root key-value before inline table if appearing before in the patched object', () => {
    const existing = dedent`
      mytable = {
         key = "value"
      }
      ` + '\n';

    const patched = patch(existing, {
      new_root: 42,
      mytable: { key: 'value' }
    });

    expect(patched).toEqual(dedent`
      new_root = 42
      mytable = {
         key = "value"
      }
    ` + '\n');
  });

It would be nice to have this feature support where new entries are added relative to their position in the JS Object. However that would mean that we also have to re-order all other entries in the TOML file. Otherwise, it could cause issues if existing KVP were moved around and we wouldn't know where to insert the new entry if order of existing entries had flipped for instance.

This means that this would have to be a formatting option. Enabling it would mean that we would re-order all elements in the TOML output based on the order in the JS object even if those haven't changed value between the original TOML and the JS Object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions