Skip to content

Commit e679712

Browse files
committed
docs(prettier-plugin-toml): clarify the precedence order and lock the review nits
Reorder the precedence list in ascending priority, assert the synthetic filepath and the override config in the unit test, and run the no-filepath fixture test from a temporary cwd.
1 parent 0f7b945 commit e679712

3 files changed

Lines changed: 44 additions & 12 deletions

File tree

‎packages/toml/README.md‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,21 @@ the search in Rust:
6363
`%APPDATA%\tombi\config.toml` (Windows).
6464
3. **System** — `/etc/tombi/config.toml`.
6565

66-
The rules are resolved in order, each step overriding the previous one:
67-
68-
1. Prettier's core options (`printWidth`, `tabWidth`, `useTabs`, `singleQuote`,
69-
`bracketSpacing`) and any plugin option the user explicitly sets.
70-
2. The discovered configuration's rules, including the plugin options the user
71-
did not set.
66+
The rules are resolved in ascending priority, each step overriding the previous
67+
one:
68+
69+
1. The discovered configuration's base rules, including the plugin options the
70+
user did not set.
71+
2. Prettier's core options (`printWidth`, `tabWidth`, `useTabs`, `singleQuote`,
72+
`bracketSpacing`) and any plugin option the user explicitly sets, passed as
73+
`overrideConfig`.
7274
3. The discovered configuration's per-file `[[overrides]]`, applied by Tombi
7375
last.
7476

75-
Prettier's core options are always resolved, so they win over `tombi.toml`: a
76-
`tombi.toml` `line-width` that differs from Prettier's `printWidth` does not
77-
change this plugin's output. If you also use the tombi CLI or the VS Code
77+
Prettier's core options are always resolved, so they win over the discovered
78+
base rules (a matching `[[overrides]]` can still override them, because Tombi
79+
applies overrides last): a `tombi.toml` `line-width` that differs from
80+
Prettier's `printWidth` does not change this plugin's output. If you also use the tombi CLI or the VS Code
7881
extension, set `line-width` in `tombi.toml` to the same value as `printWidth`
7982
so both produce the same output — with no configuration at all, Prettier
8083
defaults to `80` while tombi has no line width limit.

‎packages/toml/test/fixtures.spec.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'node:fs'
2+
import os from 'node:os'
23
import path from 'node:path'
34

45
import { format } from 'prettier'
@@ -8,9 +9,17 @@ import TomlPlugin from 'prettier-plugin-toml'
89
describe('parser and printer', () => {
910
const fixtures = path.resolve(import.meta.dirname, 'fixtures')
1011
it('should format without a filepath', async () => {
11-
await expect(
12-
format('a=1\n', { parser: 'toml', plugins: [TomlPlugin] }),
13-
).resolves.toBe('a = 1\n')
12+
const cwd = process.cwd()
13+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'tombit-'))
14+
process.chdir(dir)
15+
16+
try {
17+
await expect(
18+
format('a=1\n', { parser: 'toml', plugins: [TomlPlugin] }),
19+
).resolves.toBe('a = 1\n')
20+
} finally {
21+
process.chdir(cwd)
22+
}
1423
})
1524

1625
for (const relativeFilepath of fs.readdirSync(fixtures)) {

‎packages/toml/test/index.spec.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ParserOptions } from 'prettier'
2+
import { format as formatToml } from 'tombit'
23
import { describe, expect, it, vi } from 'vitest'
34

45
import TomlPlugin from '../src/index.js'
@@ -29,6 +30,25 @@ describe('toml plugin', () => {
2930
)
3031
})
3132

33+
it('should pass the synthetic filepath and the override config', async () => {
34+
vi.mocked(formatToml).mockClear()
35+
36+
await expect(
37+
parser.parse('a=1', {
38+
...options,
39+
filepath: undefined,
40+
} as unknown as ParserOptions),
41+
).rejects.toThrow('Tombi failed to format the TOML document.')
42+
43+
const [call] = vi.mocked(formatToml).mock.calls
44+
expect(call[0]).toBe('a=1')
45+
expect(call[1]).toBe('stdin.toml')
46+
expect(call[2]).toHaveProperty(
47+
'overrideConfig.format.rules.line-width',
48+
options.printWidth,
49+
)
50+
})
51+
3252
it('should not expose source locations', () => {
3353
expect(parser.locStart()).toBe(-1)
3454
expect(parser.locEnd()).toBe(-1)

0 commit comments

Comments
 (0)