@daml-tools/daml-fmt 0.7.1 → 0.7.3
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.
- package/README.md +42 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -37,7 +37,8 @@ aim to match any other formatter's output.
|
|
|
37
37
|
|
|
38
38
|
Import organization is enabled by default. Reordering import declarations can
|
|
39
39
|
change Daml package identity even when the formatted source denotes the same
|
|
40
|
-
imports; use `--preserve-import-order`
|
|
40
|
+
imports; use `--preserve-import-order` or set `daml-tools.fmt.import-order` to
|
|
41
|
+
`preserve` when package identity stability matters.
|
|
41
42
|
|
|
42
43
|
## Documentation
|
|
43
44
|
|
|
@@ -86,11 +87,43 @@ daml-fmt Foo.daml # formatted source to stdout
|
|
|
86
87
|
find src -name '*.daml' -exec daml-fmt -w {} + # rewrite files in place
|
|
87
88
|
find src -name '*.daml' -exec daml-fmt --check {} + # list unformatted files
|
|
88
89
|
daml-fmt --preserve-import-order Foo.daml # format without import sorting
|
|
90
|
+
find src -name '*.daml' -exec daml-fmt --ignore-path .damlfmtignore --check {} + # skip generated/vendored files
|
|
91
|
+
daml-fmt --rule imports Foo.daml # run only import organization
|
|
92
|
+
daml-fmt --rule spacing Foo.daml # run only whitespace/colon spacing
|
|
89
93
|
cat Foo.daml | daml-fmt # stdin -> stdout
|
|
90
94
|
```
|
|
91
95
|
|
|
92
96
|
Exit codes: 0 ok, 1 `--check` found unformatted files, 2 error.
|
|
93
97
|
|
|
98
|
+
Rule ids are `imports`, `layout`, `spacing`, and `syntax-normalization`.
|
|
99
|
+
`daml-fmt` reads `./daml.yaml` when present:
|
|
100
|
+
|
|
101
|
+
```yaml
|
|
102
|
+
daml-tools:
|
|
103
|
+
fmt:
|
|
104
|
+
import-order: preserve
|
|
105
|
+
ignore:
|
|
106
|
+
- generated/**
|
|
107
|
+
- vendor.daml
|
|
108
|
+
groups: [all]
|
|
109
|
+
rules:
|
|
110
|
+
imports: off
|
|
111
|
+
layout: on
|
|
112
|
+
spacing: on
|
|
113
|
+
syntax-normalization: on
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Default config discovery checks exactly `./daml.yaml` in the current working
|
|
117
|
+
directory; it does not walk parent directories. CLI `--rule`/`--group`
|
|
118
|
+
selection overrides config selection, and `--preserve-import-order` overrides
|
|
119
|
+
`import-order`.
|
|
120
|
+
|
|
121
|
+
`daml-tools.fmt.ignore` entries resolve relative to the config file directory.
|
|
122
|
+
Repeatable `--ignore-path <FILE>` entries resolve patterns relative to each
|
|
123
|
+
ignore file's directory. Ignore files support blank lines, `#` comments, exact
|
|
124
|
+
paths, directory prefixes ending in `/`, leading `/`, `*`, and `**`; this is a
|
|
125
|
+
small gitignore-like subset.
|
|
126
|
+
|
|
94
127
|
## Library API
|
|
95
128
|
|
|
96
129
|
`daml-fmt` is also a Rust library. The primary entry points are
|
|
@@ -101,7 +134,8 @@ Exit codes: 0 ok, 1 `--check` found unformatted files, 2 error.
|
|
|
101
134
|
|
|
102
135
|
```rust
|
|
103
136
|
use daml_fmt::{
|
|
104
|
-
format_source, format_source_with_options, try_format_source, FormatOptions,
|
|
137
|
+
format_source, format_source_with_options, try_format_source, FormatOptions, FormatRule,
|
|
138
|
+
FormatRuleSet, ImportOrder,
|
|
105
139
|
};
|
|
106
140
|
|
|
107
141
|
let formatted = format_source("module M where\nfoo : Int\nfoo = 1\n");
|
|
@@ -111,8 +145,14 @@ let preserved = format_source_with_options(
|
|
|
111
145
|
FormatOptions::new().with_import_order(ImportOrder::Preserve),
|
|
112
146
|
);
|
|
113
147
|
|
|
148
|
+
let imports_only = format_source_with_options(
|
|
149
|
+
"module M where\nimport DA.Optional\nimport DA.List\n\nx : Int\nx = 1\n",
|
|
150
|
+
FormatOptions::new().with_rules(FormatRuleSet::from_rules([FormatRule::Imports])),
|
|
151
|
+
);
|
|
152
|
+
|
|
114
153
|
let checked = try_format_source("module M where\nfoo: Int\nfoo = 1\n").expect("valid source");
|
|
115
154
|
assert_eq!(checked, formatted);
|
|
155
|
+
assert!(imports_only.contains("import DA.List\nimport DA.Optional"));
|
|
116
156
|
```
|
|
117
157
|
|
|
118
158
|
`ImportOrder` implements `Default` (`Organize`) and `Display` (`organize` /
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daml-tools/daml-fmt",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "A canonical code formatter for the Daml smart-contract language, built on daml-parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"daml",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"node": ">=18"
|
|
24
24
|
},
|
|
25
25
|
"optionalDependencies": {
|
|
26
|
-
"@daml-tools/daml-fmt-darwin-arm64": "0.7.
|
|
27
|
-
"@daml-tools/daml-fmt-linux-arm64": "0.7.
|
|
28
|
-
"@daml-tools/daml-fmt-linux-x64": "0.7.
|
|
29
|
-
"@daml-tools/daml-fmt-win32-x64": "0.7.
|
|
26
|
+
"@daml-tools/daml-fmt-darwin-arm64": "0.7.3",
|
|
27
|
+
"@daml-tools/daml-fmt-linux-arm64": "0.7.3",
|
|
28
|
+
"@daml-tools/daml-fmt-linux-x64": "0.7.3",
|
|
29
|
+
"@daml-tools/daml-fmt-win32-x64": "0.7.3"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|