@contractkit/prettier-plugin 0.8.1 → 0.9.1
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/.turbo/turbo-build$colon$ci.log +19 -35
- package/.turbo/turbo-test$colon$ci.log +26 -105
- package/CHANGELOG.md +32 -0
- package/README.md +58 -0
- package/coverage/clover.xml +159 -155
- package/coverage/coverage-final.json +5 -5
- package/coverage/indent.ts.html +1 -1
- package/coverage/index.html +27 -27
- package/coverage/print-ck.ts.html +111 -57
- package/coverage/print-contract.ts.html +1 -1
- package/coverage/print-operation.ts.html +58 -37
- package/coverage/print-type.ts.html +1 -1
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/print-ck.d.ts +8 -0
- package/dist/print-ck.d.ts.map +1 -1
- package/dist/print-operation.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/print-ck.ts +22 -4
- package/src/print-operation.ts +7 -0
- package/tests/print-ck.test.ts +109 -0
- package/.turbo/turbo-build.log +0 -15
- package/.turbo/turbo-format.log +0 -29
- package/.turbo/turbo-test.log +0 -14
- package/dist/__tests__/print-ck.test.d.ts +0 -2
- package/dist/__tests__/print-ck.test.d.ts.map +0 -1
- package/dist/__tests__/print-op.test.d.ts +0 -2
- package/dist/__tests__/print-op.test.d.ts.map +0 -1
- package/dist/__tests__/print-op.test.js +0 -359
- package/dist/__tests__/print-op.test.js.map +0 -1
- package/dist/print-dto.d.ts +0 -3
- package/dist/print-dto.d.ts.map +0 -1
- package/dist/print-dto.js +0 -100
- package/dist/print-dto.js.map +0 -1
- package/dist/print-op.d.ts +0 -24
- package/dist/print-op.d.ts.map +0 -1
- package/dist/print-op.js +0 -224
- package/dist/print-op.js.map +0 -1
- package/dist/print-type.js +0 -110
- package/dist/print-type.js.map +0 -1
|
@@ -1,35 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
=============
|
|
21
|
-
|
|
22
|
-
> @contractkit/prettier-plugin@0.8.0 build /Users/robert/projects/contractkit/apps/prettier-plugin
|
|
23
|
-
> tsup src/index.ts --format esm --sourcemap --dts && tsc --emitDeclarationOnly --declaration
|
|
24
|
-
|
|
25
|
-
[34mCLI[39m Building entry: src/index.ts
|
|
26
|
-
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
27
|
-
[34mCLI[39m tsup v8.5.1
|
|
28
|
-
[34mCLI[39m Target: esnext
|
|
29
|
-
[34mESM[39m Build start
|
|
30
|
-
[32mESM[39m [1mdist/index.js [22m[32m17.83 KB[39m
|
|
31
|
-
[32mESM[39m [1mdist/index.js.map [22m[32m42.37 KB[39m
|
|
32
|
-
[32mESM[39m ⚡️ Build success in 43ms
|
|
33
|
-
DTS Build start
|
|
34
|
-
DTS ⚡️ Build success in 612ms
|
|
35
|
-
DTS dist/index.d.ts 157.00 B
|
|
1
|
+
|
|
2
|
+
> @contractkit/prettier-plugin@0.9.1 build:ci /home/runner/work/ContractKit/ContractKit/apps/prettier-plugin
|
|
3
|
+
> eslint --max-warnings=0 && pnpm run build
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
> @contractkit/prettier-plugin@0.9.1 build /home/runner/work/ContractKit/ContractKit/apps/prettier-plugin
|
|
7
|
+
> tsup src/index.ts --format esm --sourcemap --dts && tsc --emitDeclarationOnly --declaration
|
|
8
|
+
|
|
9
|
+
[34mCLI[39m Building entry: src/index.ts
|
|
10
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
11
|
+
[34mCLI[39m tsup v8.5.1
|
|
12
|
+
[34mCLI[39m Target: esnext
|
|
13
|
+
[34mESM[39m Build start
|
|
14
|
+
[32mESM[39m [1mdist/index.js [22m[32m18.13 KB[39m
|
|
15
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m43.70 KB[39m
|
|
16
|
+
[32mESM[39m ⚡️ Build success in 123ms
|
|
17
|
+
[34mDTS[39m Build start
|
|
18
|
+
[32mDTS[39m ⚡️ Build success in 3581ms
|
|
19
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m157.00 B[39m
|
|
@@ -1,105 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
[
|
|
7
|
-
[
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
[1m[
|
|
12
|
-
|
|
13
|
-
[2m
|
|
14
|
-
[2m
|
|
15
|
-
|
|
16
|
-
[
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
[2m Test Files [22m[1m[32m0 passed[39m[22m[90m (1)[39m
|
|
28
|
-
[2m Tests [22m[1m[32m1 passed[39m[22m[90m (45)[39m
|
|
29
|
-
[2m Start at [22m08:51:09
|
|
30
|
-
[2m Duration [22m1.12s
|
|
31
|
-
[?2026l[K[1A[K[1A[K[1A[K[1A[K[1A[K[1A[K[1A[K [32m✓[39m tests/print-ck.test.ts [2m([22m[2m45 tests[22m[2m)[22m[32m 99[2mms[22m[39m
|
|
32
|
-
[32m✓[39m printCk — route modifiers [2m(5)[22m
|
|
33
|
-
[32m✓[39m prints route with no modifiers[32m 12[2mms[22m[39m
|
|
34
|
-
[32m✓[39m prints route with internal modifier[32m 0[2mms[22m[39m
|
|
35
|
-
[32m✓[39m prints route with deprecated modifier[32m 0[2mms[22m[39m
|
|
36
|
-
[32m✓[39m treats empty modifiers array same as no modifier[32m 0[2mms[22m[39m
|
|
37
|
-
[32m✓[39m preserves description alongside modifier[32m 0[2mms[22m[39m
|
|
38
|
-
[32m✓[39m printCk — operation modifiers [2m(6)[22m
|
|
39
|
-
[32m✓[39m prints operation with no modifiers[32m 0[2mms[22m[39m
|
|
40
|
-
[32m✓[39m prints operation with internal modifier[32m 0[2mms[22m[39m
|
|
41
|
-
[32m✓[39m prints operation with deprecated modifier[32m 0[2mms[22m[39m
|
|
42
|
-
[32m✓[39m treats empty operation modifiers array as no modifiers[32m 0[2mms[22m[39m
|
|
43
|
-
[32m✓[39m prints multiple operations with mixed modifiers[32m 0[2mms[22m[39m
|
|
44
|
-
[32m✓[39m preserves description alongside modifier on operation[32m 0[2mms[22m[39m
|
|
45
|
-
[32m✓[39m printCk — route and operation modifiers combined [2m(2)[22m
|
|
46
|
-
[32m✓[39m prints both route and operation modifiers independently[32m 0[2mms[22m[39m
|
|
47
|
-
[32m✓[39m modifier placement: operation(modifier) before path, verb(modifier) before colon[32m 0[2mms[22m[39m
|
|
48
|
-
[32m✓[39m printCk — security [2m(8)[22m
|
|
49
|
-
[32m✓[39m prints operation-level security: none[32m 0[2mms[22m[39m
|
|
50
|
-
[32m✓[39m prints security block with roles only[32m 0[2mms[22m[39m
|
|
51
|
-
[32m✓[39m prints security block with multiple roles space-separated[32m 0[2mms[22m[39m
|
|
52
|
-
[32m✓[39m prints operation-level signature as its own keyword[32m 0[2mms[22m[39m
|
|
53
|
-
[32m✓[39m prints unquoted identifier signature without quotes[32m 0[2mms[22m[39m
|
|
54
|
-
[32m✓[39m prints route-level security with shallower indentation[32m 0[2mms[22m[39m
|
|
55
|
-
[32m✓[39m prints route-level security: none[32m 0[2mms[22m[39m
|
|
56
|
-
[32m✓[39m emits no security line when security is undefined[32m 0[2mms[22m[39m
|
|
57
|
-
[32m✓[39m printCk — query and headers descriptions [2m(2)[22m
|
|
58
|
-
[32m✓[39m emits inline comment on query params that have descriptions[32m 0[2mms[22m[39m
|
|
59
|
-
[32m✓[39m emits inline comment on headers params that have descriptions[32m 0[2mms[22m[39m
|
|
60
|
-
[32m✓[39m printCk — query and headers optional, nullable, default [2m(7)[22m
|
|
61
|
-
[32m✓[39m emits ? for optional query params[32m 0[2mms[22m[39m
|
|
62
|
-
[32m✓[39m emits | null for nullable query params[32m 0[2mms[22m[39m
|
|
63
|
-
[32m✓[39m emits = value for numeric defaults[32m 0[2mms[22m[39m
|
|
64
|
-
[32m✓[39m emits = value for boolean defaults[32m 0[2mms[22m[39m
|
|
65
|
-
[32m✓[39m emits = "value" for string defaults that need quoting[32m 0[2mms[22m[39m
|
|
66
|
-
[32m✓[39m combines optional, default, and description on the same param[32m 0[2mms[22m[39m
|
|
67
|
-
[32m✓[39m applies the same rules to headers params[32m 0[2mms[22m[39m
|
|
68
|
-
[32m✓[39m printCk — request blocks [2m(3)[22m
|
|
69
|
-
[32m✓[39m prints a single content-type request[32m 0[2mms[22m[39m
|
|
70
|
-
[32m✓[39m round-trips vendor JSON mime types like application/vnd.api+json[32m 0[2mms[22m[39m
|
|
71
|
-
[32m✓[39m prints multiple content-types preserving source order[32m 0[2mms[22m[39m
|
|
72
|
-
[32m✓[39m printCk — response headers [2m(2)[22m
|
|
73
|
-
[32m✓[39m prints response headers alongside body[32m 0[2mms[22m[39m
|
|
74
|
-
[32m✓[39m prints response headers without a body[32m 0[2mms[22m[39m
|
|
75
|
-
[32m✓[39m printCk — options-level header globals (round-trip) [2m(4)[22m
|
|
76
|
-
[32m✓[39m round-trips options.request.headers[32m 40[2mms[22m[39m
|
|
77
|
-
[32m✓[39m round-trips options.response.headers[32m 23[2mms[22m[39m
|
|
78
|
-
[32m✓[39m round-trips operation-level headers: none[32m 9[2mms[22m[39m
|
|
79
|
-
[32m✓[39m round-trips per-status headers: none[32m 1[2mms[22m[39m
|
|
80
|
-
[32m✓[39m printCk — multi-base inheritance and override (round-trip) [2m(3)[22m
|
|
81
|
-
[32m✓[39m round-trips multi-base inheritance[32m 1[2mms[22m[39m
|
|
82
|
-
[32m✓[39m round-trips override modifier on a field[32m 1[2mms[22m[39m
|
|
83
|
-
[32m✓[39m emits canonical modifier order: override → deprecated → readonly[32m 0[2mms[22m[39m
|
|
84
|
-
[32m✓[39m printCk — typed path params (round-trip) [2m(3)[22m
|
|
85
|
-
[32m✓[39m round-trips path params with constraint arguments[32m 4[2mms[22m[39m
|
|
86
|
-
[32m✓[39m round-trips path params with enum types[32m 1[2mms[22m[39m
|
|
87
|
-
[32m✓[39m round-trips path params with regex constraints and a comment[32m 1[2mms[22m[39m
|
|
88
|
-
|
|
89
|
-
[2m Test Files [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
|
90
|
-
[2m Tests [22m [1m[32m45 passed[39m[22m[90m (45)[39m
|
|
91
|
-
[2m Start at [22m 08:51:09
|
|
92
|
-
[2m Duration [22m 1.20s[2m (transform 258ms, setup 0ms, import 648ms, tests 99ms, environment 0ms)[22m
|
|
93
|
-
|
|
94
|
-
[34m % [39m[2mCoverage report from [22m[33mv8[39m
|
|
95
|
-
--------------------|---------|----------|---------|---------|-----------------------------------------------------------
|
|
96
|
-
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
|
97
|
-
--------------------|---------|----------|---------|---------|-----------------------------------------------------------
|
|
98
|
-
[33;1mAll files [0m | [33;1m 61.01[0m | [33;1m 53.55[0m | [33;1m 68[0m | [33;1m 67.95[0m | [31;1m [0m
|
|
99
|
-
[32;1m indent.ts [0m | [32;1m 100[0m | [32;1m 100[0m | [32;1m 100[0m | [32;1m 100[0m | [33;1m [0m
|
|
100
|
-
[33;1m print-ck.ts [0m | [33;1m 67.14[0m | [33;1m 64.19[0m | [32;1m 100[0m | [33;1m 78.84[0m | [31;1m23-28,32-37,49 [0m
|
|
101
|
-
[31;1m print-contract.ts [0m | [31;1m 41.93[0m | [31;1m 28.57[0m | [33;1m 50[0m | [31;1m 42.85[0m | [31;1m10,37-68 [0m
|
|
102
|
-
[33;1m print-operation.ts[0m | [33;1m 69.64[0m | [33;1m 63.19[0m | [32;1m 90[0m | [33;1m 79.69[0m | [31;1m27-38,47-48,85,102,168,185,193-204,236 [0m
|
|
103
|
-
[31;1m print-type.ts [0m | [31;1m 45.23[0m | [31;1m 42.55[0m | [31;1m 40[0m | [31;1m 47.14[0m | [31;1m12-13,22-30,34-40,44-66,88-93,101-102,108-109,132,135-138[0m
|
|
104
|
-
--------------------|---------|----------|---------|---------|-----------------------------------------------------------
|
|
105
|
-
[?25h
|
|
1
|
+
|
|
2
|
+
> @contractkit/prettier-plugin@0.9.1 test:ci /home/runner/work/ContractKit/ContractKit/apps/prettier-plugin
|
|
3
|
+
> vitest run --coverage
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
[1m[30m[46m RUN [49m[39m[22m [36mv4.1.5 [39m[90m/home/runner/work/ContractKit/ContractKit/apps/prettier-plugin[39m
|
|
7
|
+
[2mCoverage enabled with [22m[33mv8[39m
|
|
8
|
+
|
|
9
|
+
[32m✓[39m tests/print-ck.test.ts [2m([22m[2m55 tests[22m[2m)[22m[32m 215[2mms[22m[39m
|
|
10
|
+
|
|
11
|
+
[2m Test Files [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
|
12
|
+
[2m Tests [22m [1m[32m55 passed[39m[22m[90m (55)[39m
|
|
13
|
+
[2m Start at [22m 18:49:08
|
|
14
|
+
[2m Duration [22m 5.56s[2m (transform 1.50s, setup 0ms, import 4.05s, tests 215ms, environment 0ms)[22m
|
|
15
|
+
|
|
16
|
+
[34m % [39m[2mCoverage report from [22m[33mv8[39m
|
|
17
|
+
-------------------|---------|----------|---------|---------|-------------------
|
|
18
|
+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
|
19
|
+
-------------------|---------|----------|---------|---------|-------------------
|
|
20
|
+
All files | 66.02 | 56.81 | 69.23 | 71.87 |
|
|
21
|
+
indent.ts | 100 | 100 | 100 | 100 |
|
|
22
|
+
print-ck.ts | 89.85 | 80 | 100 | 98.03 | 59
|
|
23
|
+
print-contract.ts | 41.93 | 28.57 | 50 | 42.85 | 10,37-68
|
|
24
|
+
...t-operation.ts | 70.62 | 63.74 | 90 | 80.43 | ...92,200-211,243
|
|
25
|
+
print-type.ts | 45.23 | 42.55 | 40 | 47.14 | ...09,132,135-138
|
|
26
|
+
-------------------|---------|----------|---------|---------|-------------------
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @contractkit/prettier-plugin-contractkit
|
|
2
2
|
|
|
3
|
+
## 0.9.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7555412: Round-trip path-like values in `options.keys` and `options.services` correctly.
|
|
8
|
+
|
|
9
|
+
Values that aren't plain identifiers (paths with slashes, values starting with `.` or `#`, values containing spaces, etc.) are now consistently double-quoted on output. Previously only values starting with `#` or containing spaces were quoted, so a value like `"../../bruno"` lost its quotes on round-trip and re-parsed as a different shape.
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [7555412]
|
|
12
|
+
- @contractkit/core@0.13.0
|
|
13
|
+
|
|
14
|
+
## 0.9.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- 876696f: Add a `plugins` block to operations for attaching external files to individual code-generators.
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
post: {
|
|
22
|
+
plugins: {
|
|
23
|
+
bruno: "request-token.yml"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Each entry maps a plugin name to a path relative to the contract's `.ck` file. The CLI resolves the path before plugins run and exposes the file content on the AST as `op.pluginFiles[name]`; missing files emit a warning. Plugins keyed by their own `name` can read their entry to override or augment generated output. The raw paths remain on `op.plugins` for round-trip use cases (the prettier plugin and VS Code syntax highlighting consume the raw form).
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- Updated dependencies [876696f]
|
|
33
|
+
- @contractkit/core@0.12.0
|
|
34
|
+
|
|
3
35
|
## 0.8.1
|
|
4
36
|
|
|
5
37
|
### Patch Changes
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @contractkit/prettier-plugin
|
|
2
|
+
|
|
3
|
+
A [Prettier](https://prettier.io) plugin that formats ContractKit `.ck` files. Idempotent: re-formatting an already-formatted file is a no-op.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D prettier @contractkit/prettier-plugin
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Configuration
|
|
12
|
+
|
|
13
|
+
Add the plugin to your prettier config:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"plugins": ["@contractkit/prettier-plugin"]
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Prettier registers `.ck` as the `ContractDSL` language and applies the plugin automatically.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# Format all .ck files in your project
|
|
27
|
+
pnpm prettier --write "**/*.ck"
|
|
28
|
+
|
|
29
|
+
# Or via the editor integration of your choice
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Most editors with a Prettier integration (VS Code, JetBrains, Neovim) pick the plugin up from your project's `package.json` automatically.
|
|
33
|
+
|
|
34
|
+
## What it does
|
|
35
|
+
|
|
36
|
+
The printer round-trips the parser's AST back into canonical `.ck` source:
|
|
37
|
+
|
|
38
|
+
- 4-space indentation (matches Prettier's default `tabWidth`)
|
|
39
|
+
- Canonical modifier order on fields: `override → deprecated → readonly|writeonly`
|
|
40
|
+
- Stable ordering of `options` block items, route bodies, and operation blocks
|
|
41
|
+
- Inline `# comment` placement preserved on field/operation/status lines
|
|
42
|
+
- Multi-base inheritance: `contract C: A & B & { ... }` with the inline block always last
|
|
43
|
+
- Multi-line unions: a leading `|` is preserved on type aliases like `contract X: A | B | C`
|
|
44
|
+
- Discriminated unions render as `discriminated(by=field, A | B | C)`
|
|
45
|
+
- Options-level header globals (`options { request/response: { headers } }`) are emitted in their original un-merged form so the AST round-trips cleanly
|
|
46
|
+
|
|
47
|
+
The plugin honours Prettier's `printWidth` for line-wrapping decisions where applicable, but most CK constructs format to a fixed multi-line shape regardless of width.
|
|
48
|
+
|
|
49
|
+
## Source layout
|
|
50
|
+
|
|
51
|
+
| Path | Purpose |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| `src/index.ts` | Prettier plugin entry — parser + printer registration |
|
|
54
|
+
| `src/print-ck.ts` | Top-level dispatcher; renders the `options { ... }` block |
|
|
55
|
+
| `src/print-contract.ts` | Renders `contract` declarations and field blocks |
|
|
56
|
+
| `src/print-operation.ts` | Renders `operation` declarations, params, query, headers, request/response |
|
|
57
|
+
| `src/print-type.ts` | Shared type-expression printer used everywhere a type appears |
|
|
58
|
+
| `src/indent.ts` | Indentation constants and helpers |
|