@daml-tools/daml-fmt 0.2.8 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +19 -11
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -11,15 +11,15 @@ Part of the [daml-tools](https://github.com/stevennevins/daml-tools) workspace.
11
11
  The formatter is **Rust on the [`daml-parser`](https://crates.io/crates/daml-parser) crate** (lexer →
12
12
  offside-rule layout → recursive-descent AST). It is an **AST-driven, own-design** layout —
13
13
  it walks the parse tree, reindents the constructs it models, and passes
14
- everything else through verbatim. Every change is gated on the laid-out token
15
- stream, so it is **desugar-safe by construction**: a formatted file desugars
16
- byte-identically to the original.
14
+ everything else through verbatim. Pure reindentation remains gated on the
15
+ laid-out token stream; layout-organizing rules are checked by the compiler
16
+ desugar oracle.
17
17
 
18
18
  Results over the 924-file corpus (`corpus/SCOREBOARD.md` is the board):
19
19
 
20
20
  | tier | result |
21
21
  |---|---|
22
- | desugar byte-identical (semantics proven unchanged) | 924 / 924 |
22
+ | desugar-equivalent, import-order normalized | 924 / 924 |
23
23
  | parses | 924 / 924 |
24
24
  | semantics silently changed | 0 |
25
25
  | idempotent (`format(format(x)) == format(x)`) | 924 / 924 |
@@ -29,11 +29,15 @@ What it lays out today: module/import continuations, `do`-block indentation,
29
29
  constructor `with` fields, record-update fields, template/interface bodies,
30
30
  choice internals, declaration ladders, class/instance body-column alignment,
31
31
  function guards/where bindings, `try`/`catch` handlers, explicit tuple/list
32
- continuations, trailing-whitespace + blank-line/final-newline normalization,
33
- and type-annotation colon spacing (`x : T` `x: T`). Broader expression
34
- wrapping (long applications, infix chains, lambdas, and inline forms) remains
35
- conservative. It makes its own consistent layout decisions and does not aim to
36
- match any other formatter's output.
32
+ continuations, long applications, infix chains, lambdas, inline `if`/`case`/
33
+ `let`/record construction forms, trailing-whitespace + blank-line/final-newline
34
+ normalization, import organization, and type-annotation colon spacing
35
+ (`x : T` → `x: T`). It makes its own consistent layout decisions and does not
36
+ aim to match any other formatter's output.
37
+
38
+ Import organization is enabled by default. Reordering import declarations can
39
+ change Daml package identity even when the formatted source denotes the same
40
+ imports; use `--preserve-import-order` when package identity stability matters.
37
41
 
38
42
  ## Documentation
39
43
 
@@ -79,6 +83,7 @@ cargo install --path crates/daml-fmt # puts daml-fmt on your PATH
79
83
  daml-fmt Foo.daml # formatted source to stdout
80
84
  find src -name '*.daml' -exec daml-fmt -w {} + # rewrite files in place
81
85
  find src -name '*.daml' -exec daml-fmt --check {} + # list unformatted files
86
+ daml-fmt --preserve-import-order Foo.daml # format without import sorting
82
87
  cat Foo.daml | daml-fmt # stdin -> stdout
83
88
  ```
84
89
 
@@ -98,8 +103,11 @@ cargo test # unit tests for the layout helpers
98
103
  ```
99
104
 
100
105
  The real semantic bar is the desugar oracle: the formatted file must desugar
101
- byte-identically to the original (`daml damlc desugar`). The default verifier
102
- runs that oracle on a curated subset and keeps full-corpus idempotence:
106
+ byte-identically to the original (`daml damlc desugar`), except import
107
+ organization may reorder import declarations and change package identity. For
108
+ that rule, the verifier compares desugar output with import lines sorted, so
109
+ the body and import set must still match. The default verifier runs that oracle
110
+ on a curated subset and keeps full-corpus idempotence:
103
111
 
104
112
  ```sh
105
113
  tools/verify-rust.sh # needs Daml SDK 3.4.11 on PATH for desugar
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daml-tools/daml-fmt",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "A canonical code formatter for the Daml smart-contract language, built on daml-parser",
5
5
  "keywords": [
6
6
  "daml",
@@ -22,10 +22,10 @@
22
22
  "node": ">=18"
23
23
  },
24
24
  "optionalDependencies": {
25
- "@daml-tools/daml-fmt-darwin-arm64": "0.2.8",
26
- "@daml-tools/daml-fmt-linux-arm64": "0.2.8",
27
- "@daml-tools/daml-fmt-linux-x64": "0.2.8",
28
- "@daml-tools/daml-fmt-win32-x64": "0.2.8"
25
+ "@daml-tools/daml-fmt-darwin-arm64": "0.2.9",
26
+ "@daml-tools/daml-fmt-linux-arm64": "0.2.9",
27
+ "@daml-tools/daml-fmt-linux-x64": "0.2.9",
28
+ "@daml-tools/daml-fmt-win32-x64": "0.2.9"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"