@effect/dprint 0.0.0-stage → 0.1.0

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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +130 -2
  3. package/package.json +39 -3
  4. package/plugin.wasm +0 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Effectful Technologies Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,131 @@
1
- # Temporary Holding Version
1
+ # @effect/dprint
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A [dprint](https://dprint.dev) Wasm plugin that stacks method chains and groups imports before `dprint-plugin-typescript` formats the file.
4
+
5
+ - **Stacks method chains.** When two or more method calls follow the start of a chain, each one goes on its own line, so a pipeline or a view reads top to bottom.
6
+ - **Groups imports.** Imports are split into blank-line-separated groups: packages, `#` subpath aliases, parent imports, then sibling imports.
7
+
8
+ ```ts
9
+ import { Array } from "effect"
10
+
11
+ import { Race } from "#domain"
12
+
13
+ import { titlebar } from "../titlebar.ts"
14
+
15
+ import { TellRoom } from "./commands.ts"
16
+
17
+ const view = h.div
18
+ .class("room")
19
+ .children(titlebar, TellRoom)
20
+ ```
21
+
22
+ The formatting passes run in sandboxed Wasm and do not require Node.js.
23
+
24
+ ## Requirements
25
+
26
+ dprint 0.58.0 or newer, and a plugin that formats the files, such as `dprint-plugin-typescript`. This plugin runs alongside that one instead of claiming the files itself. Older versions of dprint don't support that and would let it take TypeScript files away from the TypeScript plugin.
27
+
28
+ ## Setup
29
+
30
+ List the plugin **before** `dprint-plugin-typescript`. Plugins run in the order of the `plugins` array, so the TypeScript plugin then indents the stacked chains and sorts the imports inside each group.
31
+
32
+ Pin a version from npm:
33
+
34
+ ```json
35
+ {
36
+ "plugins": [
37
+ "npm:@effect/dprint@0.1.0",
38
+ "npm:@dprint/typescript@0.102.0"
39
+ ]
40
+ }
41
+ ```
42
+
43
+ `dprint config update` bumps the pinned version.
44
+
45
+ Or install both plugins as dev dependencies:
46
+
47
+ ```sh
48
+ npm install --save-dev @effect/dprint @dprint/typescript
49
+ ```
50
+
51
+ Then leave the versions out, so dprint loads both from `node_modules`:
52
+
53
+ ```json
54
+ {
55
+ "plugins": [
56
+ "npm:@effect/dprint",
57
+ "npm:@dprint/typescript"
58
+ ]
59
+ }
60
+ ```
61
+
62
+ Or load it from the GitHub release:
63
+
64
+ ```json
65
+ {
66
+ "plugins": [
67
+ "https://github.com/Effect-TS/effect/releases/download/@effect/dprint@0.1.0/plugin.wasm",
68
+ "https://plugins.dprint.dev/typescript-0.102.0.wasm"
69
+ ]
70
+ }
71
+ ```
72
+
73
+ ## Configuration
74
+
75
+ Configure the plugin under the `effect` key.
76
+
77
+ | Key | Type | Default | Meaning |
78
+ | -------------- | ---------------- | ------- | ---------------------------------------------------------------------- |
79
+ | `stackChains` | boolean | `true` | Stack method chains. |
80
+ | `importGroups` | boolean or array | `true` | Group imports. `true` uses the default groups, an array sets your own. |
81
+
82
+ The plugin formats `.ts`, `.tsx`, `.mts`, `.cts`, `.js`, `.jsx`, `.mjs` and `.cjs` files. Use dprint's `associations` to choose which files it formats, and `overrides` to turn a pass off for some of them. For example, to stack chains everywhere except in tests:
83
+
84
+ ```json
85
+ {
86
+ "effect": {
87
+ "overrides": { "files": ["**/*.test.{ts,tsx}"], "stackChains": false }
88
+ }
89
+ }
90
+ ```
91
+
92
+ To run the plugin only on one folder, exclude everything and then include that folder, since the last matching pattern wins:
93
+
94
+ ```json
95
+ {
96
+ "effect": {
97
+ "associations": ["!**/*", "src/ui/**/*.{ts,tsx}"]
98
+ }
99
+ }
100
+ ```
101
+
102
+ ### Import groups
103
+
104
+ `importGroups` is an ordered list of groups, and each group is a pattern or an array of patterns. The default is:
105
+
106
+ ```json
107
+ {
108
+ "effect": {
109
+ "importGroups": ["*", "#*", ["..", "../*"], [".", "./*"]]
110
+ }
111
+ }
112
+ ```
113
+
114
+ - `*` matches any characters, including `/`. Every other character matches itself.
115
+ - An import goes to the group of the matching pattern with the most characters other than `*`. For example, `"#domain"` matches `#*` more specifically than `*`.
116
+ - When matching patterns have the same number of literal characters, the earlier group wins.
117
+ - The list must contain a bare `*`, so every import has a group.
118
+
119
+ To put Effect packages in a group of their own after other packages:
120
+
121
+ ```json
122
+ {
123
+ "effect": {
124
+ "importGroups": ["*", ["effect", "effect/*", "@effect/*"], "#*", ["..", "../*"], [".", "./*"]]
125
+ }
126
+ }
127
+ ```
128
+
129
+ The plugin moves imports between groups but keeps their order inside a group. Sorting is left to `dprint-plugin-typescript`, which sorts each blank-line-separated group on its own.
130
+
131
+ Only imports that bind something are grouped. A side-effect import such as `import "./styles.css"`, or any other statement, ends a run of imports, and no import moves past it. Comments above an import move with it, and so does a comment at the end of its line. Comments above the first import, such as a license header, stay at the top. When a line comment sits directly above the first import, that import stays first too, because comments like `// @ts-expect-error` apply to the line below them.
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@effect/dprint",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "description": "A dprint plugin that stacks fluent method chains and groups imports for Effect code",
6
+ "homepage": "https://effect.website",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/Effect-TS/effect.git",
10
+ "directory": "packages/tools/dprint"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/Effect-TS/effect/issues"
14
+ },
15
+ "tags": [
16
+ "dprint",
17
+ "dprint-plugin",
18
+ "formatting",
19
+ "effect"
20
+ ],
21
+ "keywords": [
22
+ "dprint",
23
+ "dprint-plugin",
24
+ "formatting",
25
+ "effect"
26
+ ],
27
+ "files": [
28
+ "plugin.wasm"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public",
32
+ "provenance": true
33
+ },
34
+ "devDependencies": {
35
+ "dprint": "^0.65.0"
36
+ },
37
+ "scripts": {
38
+ "build": "cargo build --release --locked --target wasm32-unknown-unknown --target-dir target && node -e \"require('node:fs').copyFileSync('target/wasm32-unknown-unknown/release/effect_dprint.wasm', 'plugin.wasm')\"",
39
+ "test": "cargo test --locked",
40
+ "test-cli": "node test/cli.mjs"
41
+ }
6
42
  }
package/plugin.wasm ADDED
Binary file