Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
c113e3f
fix(writer): align first item in empty multiline arrays
DecimalTurn Aug 19, 2026
611eca2
feat: improve indentation handling
DecimalTurn Aug 19, 2026
74f6da7
fix: ensure root key's indentation is taken into considerations
DecimalTurn Aug 19, 2026
9a88efb
test: add more indentation at root tests
DecimalTurn Aug 19, 2026
a3d31f8
test: add (failing) tests about extraneous whitespace in dotted keys
DecimalTurn Aug 19, 2026
d8b53da
fixup! test: add more indentation at root tests
DecimalTurn Aug 19, 2026
379dde5
test: add more indentation issues potentially caused by human edition…
DecimalTurn Aug 19, 2026
e5abc99
test: Move dotted keys with extranous spacing tests
DecimalTurn Aug 20, 2026
00efb53
test: adjust tests to keep note of the comment ownership future plans
DecimalTurn Aug 20, 2026
5c322e2
fix(patch): preserve spacing after comment-only tables
DecimalTurn Aug 20, 2026
eb7eb13
test: move indentation test to seperate file and add "nested multilin…
DecimalTurn Aug 20, 2026
5b836e2
fix: preserve multiline string inside array
DecimalTurn Aug 20, 2026
52396d3
test: adjust to fit string format preservation
DecimalTurn Aug 20, 2026
f0d0f5d
feat: support nested array indentation
DecimalTurn Aug 20, 2026
6f94c30
refactor: use inline layout helper from patch.ts instead of explandin…
DecimalTurn Aug 20, 2026
a2e6a97
feat: support nested multiline inline table layout
DecimalTurn Aug 20, 2026
37094b4
test: additional tests for indentation of inline array/table
DecimalTurn Aug 20, 2026
c6ae6b1
docs: update README
DecimalTurn Aug 20, 2026
effef7f
perf: optimize auto detection of spacing
DecimalTurn Aug 21, 2026
d49c5fb
test: add additional indentation tests
DecimalTurn Aug 21, 2026
b33c831
test: more indentation tests
DecimalTurn Aug 21, 2026
35c0f72
fix: adjust tab detection and document current behavior with mixed in…
DecimalTurn Aug 21, 2026
f9ebb45
Merge branch 'latest' into dev-array-multi
DecimalTurn Aug 23, 2026
65831f9
chore: fix lint errors in tests
DecimalTurn Aug 23, 2026
17d6f84
chore: remove truncated indentation TODO
DecimalTurn Aug 23, 2026
e453416
docs: clarify tab indentation detection
DecimalTurn Aug 23, 2026
2e279aa
test: cover tab detection ties
DecimalTurn Aug 23, 2026
1c03296
fix: allow unset indent width
DecimalTurn Aug 23, 2026
e62271a
test: fix indentation comment typo
DecimalTurn Aug 23, 2026
4e60c64
test: disambiguate indentation test names
DecimalTurn Aug 23, 2026
d232e08
docs: clarify dotted key spacing comment
DecimalTurn Aug 23, 2026
234214d
test: fix dotted key spacing spelling
DecimalTurn Aug 23, 2026
09d0e30
Merge branch 'latest' into dev-array-multi
DecimalTurn Aug 30, 2026
720d96e
fix: imports
DecimalTurn Aug 30, 2026
37b4d6d
fix: preserve tab indentation on the first line during patch output
DecimalTurn Aug 30, 2026
04c714b
Merge branch 'latest' into dev-array-multi
DecimalTurn Aug 30, 2026
8bd868d
Merge branch 'latest' into dev-array-multi
DecimalTurn Aug 30, 2026
f9823a8
Revert "test: remove unneeded test"
DecimalTurn Aug 30, 2026
528bec8
test:: force preservation of inline array and talble multiline style
DecimalTurn Aug 30, 2026
208a2b3
fix: force preservation of inline array and table multiline style
DecimalTurn Aug 30, 2026
6e4c29c
test: add cases to preserve indentation when deleting and re-adding k…
DecimalTurn Aug 30, 2026
369ffa5
test: add cases to preserve indentation when deleting and re-adding v…
DecimalTurn Aug 30, 2026
58aca0a
fix: remove trailing commas inconsistencies
DecimalTurn Aug 30, 2026
64380ed
fix: handle mixed indentation
DecimalTurn Aug 30, 2026
dd80205
test: add format override check
DecimalTurn Aug 30, 2026
16461d2
test: add cases for preserving indentation in mixed indentation scena…
DecimalTurn Aug 30, 2026
7a3189b
docs: clarify plans and future indentation API options
DecimalTurn Aug 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ class TomlFormat {
bracketSpacing: boolean
inlineTableStart?: number
truncateZeroTimeInDates: boolean
useTabsForIndentation?: boolean
indentWidth: number
minimumDecimals?: number
leadingBom: boolean
updateOrder?: boolean
Expand Down Expand Up @@ -160,4 +162,4 @@ const toml = stringify({

```

See the [formatting reference](https://github.com/DecimalTurn/toml-patch/blob/v3.0.4/docs/Formatting.md) for the complete list of options, auto-detection behavior, `updateOrder` and more examples.
See the [formatting reference](https://github.com/DecimalTurn/toml-patch/blob/v3.0.4/docs/Formatting.md) for the complete list of options, auto-detection behavior, `updateOrder` and more examples.
337 changes: 337 additions & 0 deletions docs/PLAN-Indentation.md

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions src/__tests__/patch.dotted-key-spacing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import patch from '../patch';
import { parse } from '../';
import dedent from 'dedent';

/* The TOML spec allows extraneous spacing between the key and the dot
for dotted keys. This is not recommended, but it is allowed.

When adding a new dotted key to an existing TOML document, the spacing and overall
style should be preserved. There might be cases where the appropriate spacing
is not obvious, but the patcher should try to preserve the existing spacing as
much as possible.

//TODO: add more tests with space before and or after the dot. Try with many spaces.
// Also try tests where the table name is a dotted key with spacing, and
// the new table should then have a similar spacing (to be confirmed).

*/
describe('patching dotted keys with extraneous spacing', () => {

test.fails('editing a key with spacing preserves the spacing', () => {
const src = dedent`
fruit. color = "yellow"
`;

const obj = parse(src) as any;
//Edit fruit.color to "green"
obj.fruit.color = "green";
const result = patch(src, obj);
expect(parse(result)).toEqual(obj);
expect(result).toEqual(dedent`
fruit. color = "green"
`);
});

test.fails('adding a new dotted key with spacing to an existing dotted key with spacing', () => {
const src = dedent`
fruit. color = "yellow"
`;

const obj = parse(src) as any;
//Add fruit.flavor to the object
obj.fruit.flavor = "banana";
const result = patch(src, obj);
expect(parse(result)).toEqual(obj);
expect(result).toEqual(dedent`
fruit. color = "yellow"
fruit. flavor = "banana"
`);
});

test.fails('single key added to indented single key with spacing', () => {
// fruit. color = "yellow" # same as fruit.color
//fruit . flavor = "banana" # same as fruit.flavor
const src = [
' fruit. color = "yellow"',
].join('\n')
const obj = parse(src) as any;
//Add fruit.flavor to the object
obj.fruit.flavor = "banana";
expect(patch(src, obj, { indentWidth: 4 })).toEqual([
' fruit. color = "yellow"',
' fruit. flavor = "banana"',
].join('\n'));
});

});
7 changes: 4 additions & 3 deletions src/__tests__/patch.fuzz.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ test('collapsing a multiline-array dotted key into an inline table (seed 30330 a
a5 = [1]

h.z = {
b.x = true,
b.y = "tail"
b.x = true,
b.y = "tail",
}
`);
});
Expand Down Expand Up @@ -2401,7 +2401,8 @@ test('moving a multiline literal past duplicate scalars while removing the head
const result = patch(src, obj);
expect(parse(result)).toEqual(obj);
expect(result).toEqual(dedent`
o4s = [false, 30325, false, "changed", false, "x", 'y']
o4s = [false, 30325, false, '''
changed''', false, "x", 'y']
`);
});

Expand Down
Loading