@yuu1111/biome-config 1.3.8 → 2.0.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.
package/README.ja.md ADDED
@@ -0,0 +1,149 @@
1
+ [English](README.md)
2
+
3
+ # @yuu1111/biome-config
4
+
5
+ 共有の [Biome](https://biomejs.dev/) 設定
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ bun add -D @yuu1111/biome-config
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Base
16
+
17
+ ```json
18
+ {
19
+ "$schema": "https://biomejs.dev/schemas/2.5.13/schema.json",
20
+ "extends": ["@yuu1111/biome-config/biome"]
21
+ }
22
+ ```
23
+
24
+ base設定はrecommended ruleを有効にし、barrel fileとre-export-allをerror、nested ternary、空block文、過剰なcognitive complexityをwarningにする
25
+
26
+ ```ts
27
+ const size = small ? "s" : medium ? "m" : "l"
28
+ ```
29
+
30
+ ### React
31
+
32
+ CSS/Tailwind対応を含む
33
+
34
+ ```json
35
+ {
36
+ "$schema": "https://biomejs.dev/schemas/2.5.13/schema.json",
37
+ "extends": ["@yuu1111/biome-config/react"]
38
+ }
39
+ ```
40
+
41
+ ### Custom rule presets
42
+
43
+ Custom ruleはopt-in baseまたはReact設定の後ろに、必要な層のpresetを並べる
44
+
45
+ ```json
46
+ {
47
+ "$schema": "https://biomejs.dev/schemas/2.5.13/schema.json",
48
+ "extends": [
49
+ "@yuu1111/biome-config/biome",
50
+ "@yuu1111/biome-config/plugins/core",
51
+ "@yuu1111/biome-config/plugins/network"
52
+ ]
53
+ }
54
+ ```
55
+
56
+ - `plugins/core` はforwarding export、未完成実装、型安全の迂回、安全でないerrno assertion、無意味なtest、pass-through wrapper、副作用目的のternaryを検査する
57
+ - `plugins/network` は `fetch` に `AbortSignal` を要求し、手動で予約したabort timeoutの後始末を検査する
58
+ - `plugins/discord` は動的なDiscord messageに明示的なmention処理があるかを検査する
59
+
60
+ presetは他の層を含まないため、Projectに必要な層をすべて並べる
61
+
62
+ #### Core rules
63
+
64
+ - `no-reexports` は既存bindingを転送するだけのexport(`export type Alias = Imported`、`export default imported`、`export const wrapped = imported` など)をwarningにする `export ... from` の形はbaseのbarrel file ruleが担当する
65
+ - `no-incomplete-implementation` はplaceholderのthrowをerror、logだけのcatch、`null`・`[]`・`{}` へ置き換えたrejected promiseとcatchしたerrorをwarningにする
66
+ - `no-type-safety-bypass` は `as unknown as T` をerror、`Record<string, unknown>` のassertion、未検証のJSON assertion、静的な `Reflect.get`、receiver無しの `Reflect.apply` をwarningにする
67
+ - `no-unsafe-errno-assertion` はcatchした値を検証せず `NodeJS.ErrnoException` のassertion経由で `code` を直接読むコードをwarningにする
68
+ - `no-meaningless-test` はidentifierやliteralを自分自身と比較する `toBe`・`toEqual`・`toStrictEqual` をerror、空の `test`・`it` callbackをwarningにする
69
+ - `no-useless-abstraction` は同じ引数を別の関数へ渡すだけの名前付き単一引数arrow functionをwarningにする 同じ形のasync版も含む
70
+ - `no-ternary-statement` は `flag ? enable() : disable()` のような文としてのternaryをwarningにする if/elseの方が明確な箇所が対象
71
+
72
+ ruleは意図的に狭く保つ 検証、変換、log、cache、transaction開始などの処理を行うwrapperはpass-through wrapperとして報告しない 準備やassertionのあるtestは空として扱わない
73
+
74
+ `plugins/core` が報告する例
75
+
76
+ ```ts
77
+ throw new Error("Not implemented")
78
+ request.catch(() => null)
79
+
80
+ const user = value as unknown as User
81
+ const parsed = JSON.parse(text) as User
82
+ const code = (error as NodeJS.ErrnoException).code
83
+
84
+ test("placeholder", () => {})
85
+ expect(result).toEqual(result)
86
+
87
+ const loadUser = (id) => fetchUser(id)
88
+
89
+ flag ? enable() : disable()
90
+ ```
91
+
92
+ 理由を添えて意図的な例外を抑制する
93
+
94
+ ```ts
95
+ // biome-ignore lint/plugin: An optional cache miss is an expected fallback
96
+ cacheRequest.catch(() => null)
97
+ ```
98
+
99
+ #### Network rule
100
+
101
+ - `require-fetch-abort-signal` は `fetch` 呼び出しが `signal` optionを省いているとwarningにする
102
+ - `require-abort-timeout-cleanup` は `setTimeout` callbackで `fetch` をabortしていながらそのtimerをclearしない関数をwarningにする
103
+
104
+ #### Discord rule
105
+
106
+ `no-unsafe-dynamic-discord-message` は明示的な `allowedMentions` policy無しで動的なmessage内容を送るとwarningにする
107
+
108
+ #### Project-scoped rule
109
+
110
+ `no-adapter-import` は `integrations/` か `adapters/` を含むpathをmoduleがimportするとerrorにする 保護する層がProject固有のためpresetを持たない Project自身の設定で宣言し、`includes` で絞る
111
+
112
+ ```json
113
+ {
114
+ "plugins": [
115
+ {
116
+ "path": "./node_modules/@yuu1111/biome-config/plugins/scoped/no-adapter-import.grit",
117
+ "includes": ["**/src/modules/authorization/**"]
118
+ }
119
+ ]
120
+ }
121
+ ```
122
+
123
+ pluginは `includes` に一致したfileだけで走るため、同じimportはadapter側と統合層へ到達してよい層では有効なままになる pluginのpatternはfileのfull pathと照合されるため、`src/modules/authorization` のようなpathへ一致させるには `**/` から始める必要がある
124
+
125
+ 統合moduleへ到達してよい層はpatternから外す 自身のadapter実装を `adapters/` に置くmoduleはそのディレクトリを除外しないと、ruleがadapter自身を報告する
126
+
127
+ ```json
128
+ {
129
+ "includes": [
130
+ "**/src/modules/authorization/**",
131
+ "!**/src/modules/authorization/adapters/**"
132
+ ]
133
+ }
134
+ ```
135
+
136
+ `no-direct-response` は対象層での `new Response(...)`、`Response.json(...)`、`Response.redirect(...)` をerrorにする すべてのresponseを共有helper経由で組み立てる層へ絞る
137
+
138
+ ```json
139
+ {
140
+ "plugins": [
141
+ {
142
+ "path": "./node_modules/@yuu1111/biome-config/plugins/scoped/no-direct-response.grit",
143
+ "includes": ["**/src/worker/routes/**"]
144
+ }
145
+ ]
146
+ }
147
+ ```
148
+
149
+ helper module自身はpatternの外に置くため、responseを組み立ててよい
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [日本語](README.ja.md)
2
+
1
3
  # @yuu1111/biome-config
2
4
 
3
5
  Shared [Biome](https://biomejs.dev/) configuration.
@@ -38,25 +40,24 @@ CSS/Tailwind support included.
38
40
 
39
41
  ### Custom rule presets
40
42
 
41
- Custom rules are opt-in. Add one preset after the base or React configuration:
43
+ Custom rules are opt-in. Each preset holds one layer of rules; add the layers the project needs after the base or React configuration:
42
44
 
43
45
  ```json
44
46
  {
45
47
  "$schema": "https://biomejs.dev/schemas/2.5.13/schema.json",
46
48
  "extends": [
47
49
  "@yuu1111/biome-config/biome",
50
+ "@yuu1111/biome-config/plugins/core",
48
51
  "@yuu1111/biome-config/plugins/network"
49
52
  ]
50
53
  }
51
54
  ```
52
55
 
53
- Choose the most specific preset needed by the project:
54
-
55
56
  - `plugins/core` checks forwarding exports, incomplete implementations, type-safety bypasses, unsafe errno assertions, meaningless tests, pass-through wrappers, and ternaries used for side effects
56
- - `plugins/network` includes `core`, requires an `AbortSignal` for `fetch`, and checks cleanup for manually scheduled abort timeouts
57
- - `plugins/discord` includes `network` and checks dynamic Discord messages for explicit mention handling
57
+ - `plugins/network` requires an `AbortSignal` for `fetch` and checks cleanup for manually scheduled abort timeouts
58
+ - `plugins/discord` checks dynamic Discord messages for explicit mention handling
58
59
 
59
- Do not list parent presets separately. Each child preset includes its parent rules.
60
+ A preset does not include the other layers, so list every layer the project needs.
60
61
 
61
62
  #### Core rules
62
63
 
@@ -112,7 +113,7 @@ cacheRequest.catch(() => null)
112
113
  {
113
114
  "plugins": [
114
115
  {
115
- "path": "./node_modules/@yuu1111/biome-config/plugins/no-adapter-import.grit",
116
+ "path": "./node_modules/@yuu1111/biome-config/plugins/scoped/no-adapter-import.grit",
116
117
  "includes": ["**/src/modules/authorization/**"]
117
118
  }
118
119
  ]
@@ -138,7 +139,7 @@ Leave the layer that is allowed to reach the integration modules out of the patt
138
139
  {
139
140
  "plugins": [
140
141
  {
141
- "path": "./node_modules/@yuu1111/biome-config/plugins/no-direct-response.grit",
142
+ "path": "./node_modules/@yuu1111/biome-config/plugins/scoped/no-direct-response.grit",
142
143
  "includes": ["**/src/worker/routes/**"]
143
144
  }
144
145
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuu1111/biome-config",
3
- "version": "1.3.8",
3
+ "version": "2.0.0",
4
4
  "description": "Shared Biome configuration",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -16,6 +16,7 @@
16
16
  "./react": "./react.json"
17
17
  },
18
18
  "files": [
19
+ "README.ja.md",
19
20
  "base.json",
20
21
  "plugins",
21
22
  "plugins-core.json",
package/plugins-core.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "$schema": "https://biomejs.dev/schemas/2.5.13/schema.json",
3
3
  "plugins": [
4
- "./node_modules/@yuu1111/biome-config/plugins/no-reexports.grit",
5
- "./node_modules/@yuu1111/biome-config/plugins/no-incomplete-implementation.grit",
6
- "./node_modules/@yuu1111/biome-config/plugins/no-type-safety-bypass.grit",
7
- "./node_modules/@yuu1111/biome-config/plugins/no-unsafe-errno-assertion.grit",
8
- "./node_modules/@yuu1111/biome-config/plugins/no-meaningless-test.grit",
9
- "./node_modules/@yuu1111/biome-config/plugins/no-useless-abstraction.grit",
10
- "./node_modules/@yuu1111/biome-config/plugins/no-ternary-statement.grit"
4
+ "./node_modules/@yuu1111/biome-config/plugins/core/no-reexports.grit",
5
+ "./node_modules/@yuu1111/biome-config/plugins/core/no-incomplete-implementation.grit",
6
+ "./node_modules/@yuu1111/biome-config/plugins/core/no-type-safety-bypass.grit",
7
+ "./node_modules/@yuu1111/biome-config/plugins/core/no-unsafe-errno-assertion.grit",
8
+ "./node_modules/@yuu1111/biome-config/plugins/core/no-meaningless-test.grit",
9
+ "./node_modules/@yuu1111/biome-config/plugins/core/no-useless-abstraction.grit",
10
+ "./node_modules/@yuu1111/biome-config/plugins/core/no-ternary-statement.grit"
11
11
  ]
12
12
  }
@@ -1,15 +1,6 @@
1
1
  {
2
2
  "$schema": "https://biomejs.dev/schemas/2.5.13/schema.json",
3
3
  "plugins": [
4
- "./node_modules/@yuu1111/biome-config/plugins/no-reexports.grit",
5
- "./node_modules/@yuu1111/biome-config/plugins/no-incomplete-implementation.grit",
6
- "./node_modules/@yuu1111/biome-config/plugins/no-type-safety-bypass.grit",
7
- "./node_modules/@yuu1111/biome-config/plugins/no-unsafe-errno-assertion.grit",
8
- "./node_modules/@yuu1111/biome-config/plugins/no-meaningless-test.grit",
9
- "./node_modules/@yuu1111/biome-config/plugins/no-useless-abstraction.grit",
10
- "./node_modules/@yuu1111/biome-config/plugins/no-ternary-statement.grit",
11
- "./node_modules/@yuu1111/biome-config/plugins/require-fetch-abort-signal.grit",
12
- "./node_modules/@yuu1111/biome-config/plugins/require-abort-timeout-cleanup.grit",
13
- "./node_modules/@yuu1111/biome-config/plugins/no-unsafe-dynamic-discord-message.grit"
4
+ "./node_modules/@yuu1111/biome-config/plugins/discord/no-unsafe-dynamic-discord-message.grit"
14
5
  ]
15
6
  }
@@ -1,14 +1,7 @@
1
1
  {
2
2
  "$schema": "https://biomejs.dev/schemas/2.5.13/schema.json",
3
3
  "plugins": [
4
- "./node_modules/@yuu1111/biome-config/plugins/no-reexports.grit",
5
- "./node_modules/@yuu1111/biome-config/plugins/no-incomplete-implementation.grit",
6
- "./node_modules/@yuu1111/biome-config/plugins/no-type-safety-bypass.grit",
7
- "./node_modules/@yuu1111/biome-config/plugins/no-unsafe-errno-assertion.grit",
8
- "./node_modules/@yuu1111/biome-config/plugins/no-meaningless-test.grit",
9
- "./node_modules/@yuu1111/biome-config/plugins/no-useless-abstraction.grit",
10
- "./node_modules/@yuu1111/biome-config/plugins/no-ternary-statement.grit",
11
- "./node_modules/@yuu1111/biome-config/plugins/require-fetch-abort-signal.grit",
12
- "./node_modules/@yuu1111/biome-config/plugins/require-abort-timeout-cleanup.grit"
4
+ "./node_modules/@yuu1111/biome-config/plugins/network/require-fetch-abort-signal.grit",
5
+ "./node_modules/@yuu1111/biome-config/plugins/network/require-abort-timeout-cleanup.grit"
13
6
  ]
14
7
  }