@yuu1111/biome-config 1.3.8 → 1.3.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 (3) hide show
  1. package/README.ja.md +150 -0
  2. package/README.md +2 -0
  3. package/package.json +2 -1
package/README.ja.md ADDED
@@ -0,0 +1,150 @@
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を1つ足す
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/network"
51
+ ]
52
+ }
53
+ ```
54
+
55
+ Projectに必要な最も具体的なpresetを選ぶ
56
+
57
+ - `plugins/core` はforwarding export、未完成実装、型安全の迂回、安全でないerrno assertion、無意味なtest、pass-through wrapper、副作用目的のternaryを検査する
58
+ - `plugins/network` は `core` を含み、`fetch` に `AbortSignal` を要求し、手動で予約したabort timeoutの後始末を検査する
59
+ - `plugins/discord` は `network` を含み、動的なDiscord messageに明示的なmention処理があるかを検査する
60
+
61
+ 親presetを別に並べない 子presetは親のruleを含む
62
+
63
+ #### Core rules
64
+
65
+ - `no-reexports` は既存bindingを転送するだけのexport(`export type Alias = Imported`、`export default imported`、`export const wrapped = imported` など)をwarningにする `export ... from` の形はbaseのbarrel file ruleが担当する
66
+ - `no-incomplete-implementation` はplaceholderのthrowをerror、logだけのcatch、`null`・`[]`・`{}` へ置き換えたrejected promiseとcatchしたerrorをwarningにする
67
+ - `no-type-safety-bypass` は `as unknown as T` をerror、`Record<string, unknown>` のassertion、未検証のJSON assertion、静的な `Reflect.get`、receiver無しの `Reflect.apply` をwarningにする
68
+ - `no-unsafe-errno-assertion` はcatchした値を検証せず `NodeJS.ErrnoException` のassertion経由で `code` を直接読むコードをwarningにする
69
+ - `no-meaningless-test` はidentifierやliteralを自分自身と比較する `toBe`・`toEqual`・`toStrictEqual` をerror、空の `test`・`it` callbackをwarningにする
70
+ - `no-useless-abstraction` は同じ引数を別の関数へ渡すだけの名前付き単一引数arrow functionをwarningにする 同じ形のasync版も含む
71
+ - `no-ternary-statement` は `flag ? enable() : disable()` のような文としてのternaryをwarningにする if/elseの方が明確な箇所が対象
72
+
73
+ ruleは意図的に狭く保つ 検証、変換、log、cache、transaction開始などの処理を行うwrapperはpass-through wrapperとして報告しない 準備やassertionのあるtestは空として扱わない
74
+
75
+ `plugins/core` が報告する例
76
+
77
+ ```ts
78
+ throw new Error("Not implemented")
79
+ request.catch(() => null)
80
+
81
+ const user = value as unknown as User
82
+ const parsed = JSON.parse(text) as User
83
+ const code = (error as NodeJS.ErrnoException).code
84
+
85
+ test("placeholder", () => {})
86
+ expect(result).toEqual(result)
87
+
88
+ const loadUser = (id) => fetchUser(id)
89
+
90
+ flag ? enable() : disable()
91
+ ```
92
+
93
+ 理由を添えて意図的な例外を抑制する
94
+
95
+ ```ts
96
+ // biome-ignore lint/plugin: An optional cache miss is an expected fallback
97
+ cacheRequest.catch(() => null)
98
+ ```
99
+
100
+ #### Network rule
101
+
102
+ - `require-fetch-abort-signal` は `fetch` 呼び出しが `signal` optionを省いているとwarningにする
103
+ - `require-abort-timeout-cleanup` は `setTimeout` callbackで `fetch` をabortしていながらそのtimerをclearしない関数をwarningにする
104
+
105
+ #### Discord rule
106
+
107
+ `no-unsafe-dynamic-discord-message` は明示的な `allowedMentions` policy無しで動的なmessage内容を送るとwarningにする
108
+
109
+ #### Project-scoped rule
110
+
111
+ `no-adapter-import` は `integrations/` か `adapters/` を含むpathをmoduleがimportするとerrorにする 保護する層がProject固有のためpresetを持たない Project自身の設定で宣言し、`includes` で絞る
112
+
113
+ ```json
114
+ {
115
+ "plugins": [
116
+ {
117
+ "path": "./node_modules/@yuu1111/biome-config/plugins/no-adapter-import.grit",
118
+ "includes": ["**/src/modules/authorization/**"]
119
+ }
120
+ ]
121
+ }
122
+ ```
123
+
124
+ pluginは `includes` に一致したfileだけで走るため、同じimportはadapter側と統合層へ到達してよい層では有効なままになる pluginのpatternはfileのfull pathと照合されるため、`src/modules/authorization` のようなpathへ一致させるには `**/` から始める必要がある
125
+
126
+ 統合moduleへ到達してよい層はpatternから外す 自身のadapter実装を `adapters/` に置くmoduleはそのディレクトリを除外しないと、ruleがadapter自身を報告する
127
+
128
+ ```json
129
+ {
130
+ "includes": [
131
+ "**/src/modules/authorization/**",
132
+ "!**/src/modules/authorization/adapters/**"
133
+ ]
134
+ }
135
+ ```
136
+
137
+ `no-direct-response` は対象層での `new Response(...)`、`Response.json(...)`、`Response.redirect(...)` をerrorにする すべてのresponseを共有helper経由で組み立てる層へ絞る
138
+
139
+ ```json
140
+ {
141
+ "plugins": [
142
+ {
143
+ "path": "./node_modules/@yuu1111/biome-config/plugins/no-direct-response.grit",
144
+ "includes": ["**/src/worker/routes/**"]
145
+ }
146
+ ]
147
+ }
148
+ ```
149
+
150
+ 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuu1111/biome-config",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
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",