Skip to content

Commit 95b529b

Browse files
committed
コーディング規約の検査ツールを追加し、禁止記法と doc コメント漏れを直す
spec/tools/check_comments.py を追加した。コメントと禁止記法の規約適合を 機械で確かめる。人手のレビューでは5言語ぶんの書きぶりを揃え続けられない。 検査するもの: - 公開型・公開メソッドの doc コメント(言語ごとの形式) - 条件分岐とループの説明コメント - 禁止記法(三項演算子・オプショナルチェーン・null 合体演算子) 引数検証などのガード節は条件分岐の対象から外す。書いても 「不正なら弾く」としか書けず、かえって読みにくいため。 ブロック内の先頭に置いたコメントも、意図の説明として認める。 直したもの: - C# のオプショナルチェーン 9 箇所を if で明示する形へ(規約で全面禁止) - TypeScript のクラス 7 件に doc コメントを追加。 ファイル冒頭のモジュール説明はあったが、IDE の補完はクラス直前しか拾わない - TypeScript の setter 6 件と内部メソッド 3 件に doc コメントを追加 - Python の docstring 漏れ 9 件を追加 残りは条件分岐とループのコメント 329 件。件数が多く、機械的に埋めると 意味のないコメントを量産するので、別途進める。
1 parent 40e165c commit 95b529b

17 files changed

Lines changed: 577 additions & 9 deletions

File tree

‎csharp/src/SpringNBTLibrary/World/Chunk.cs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ private void CheckDataVersion(ChunkReadOptions options)
176176

177177
if (options.OnVersionMismatch == VersionMismatchAction.Warn)
178178
{
179-
options.OnWarning?.Invoke(message);
179+
// 通知先が設定されているときだけ知らせる
180+
if (options.OnWarning is not null)
181+
{
182+
options.OnWarning.Invoke(message);
183+
}
180184
}
181185
}
182186

‎csharp/src/SpringNBTLibrary/World/ChunkSection.cs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,15 @@ public NbtCompound ToNbt()
8585
/// <summary>使われていないパレット要素を取り除く。</summary>
8686
public void Compact()
8787
{
88-
BlockStates?.Compact();
89-
Biomes?.Compact();
88+
// 持っているコンテナだけを掃除する
89+
if (BlockStates is not null)
90+
{
91+
BlockStates.Compact();
92+
}
93+
94+
if (Biomes is not null)
95+
{
96+
Biomes.Compact();
97+
}
9098
}
9199
}

‎csharp/src/SpringNBTLibrary/World/Dimension.cs‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,14 @@ public void Flush()
224224
}
225225

226226
modifiedChunks.Clear();
227-
regions?.Flush();
228-
entities?.Flush();
229-
poi?.Flush();
227+
// 開いているフォルダだけを書き出す
228+
foreach (RegionFolder? folder in new[] { regions, entities, poi })
229+
{
230+
if (folder is not null)
231+
{
232+
folder.Flush();
233+
}
234+
}
230235
}
231236

232237
/// <summary>変更を書き戻してから閉じる。</summary>
@@ -242,9 +247,14 @@ public void Close()
242247
Flush();
243248
}
244249

245-
regions?.Close();
246-
entities?.Close();
247-
poi?.Close();
250+
// 開いているフォルダだけを閉じる
251+
foreach (RegionFolder? folder in new[] { regions, entities, poi })
252+
{
253+
if (folder is not null)
254+
{
255+
folder.Close();
256+
}
257+
}
248258
chunkCache.Clear();
249259
closed = true;
250260
}

‎python/src/spring_nbt_library/nbt/io.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def _remaining(self) -> int:
135135
return len(self._data) - self._position
136136

137137
def read_root(self, fmt: NbtFormat) -> NamedTag:
138+
"""ルートタグを 1 つ読む。形式によって名前の有無が変わる。"""
138139
tag_type = TagType.from_id(self._read_byte())
139140

140141
# Java版のファイル形式でもネットワーク形式でも、ルートは必ず TAG_Compound
@@ -352,6 +353,7 @@ def __init__(self) -> None:
352353
self._buffer = bytearray()
353354

354355
def write_root(self, named: NamedTag, fmt: NbtFormat) -> bytes:
356+
"""ルートタグを 1 つ書き出す。形式によって名前の有無が変わる。"""
355357
self._buffer.append(TagType.COMPOUND.value)
356358

357359
if fmt == NbtFormat.JAVA:

‎python/src/spring_nbt_library/nbt/snbt.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def __init__(self, text: str) -> None:
7676
self._position = 0
7777

7878
def parse_whole(self) -> NbtTag:
79+
"""入力全体を 1 つのタグとして読む。末尾に余りがあればエラーにする。"""
7980
value = self._parse_value()
8081
self._skip_whitespace()
8182

‎python/src/spring_nbt_library/nbt/tag.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,14 @@ def value(self):
119119

120120
@value.setter
121121
def value(self, new_value) -> None:
122+
"""値を差し替える。範囲外なら INVALID_ARGUMENT。"""
122123
self._value = self._validate(new_value)
123124

124125
def _validate(self, value):
125126
raise NotImplementedError
126127

127128
def clone(self) -> "NbtTag":
129+
"""同じ値を持つ新しいタグを作る。"""
128130
return type(self)(self._value)
129131

130132
def __eq__(self, other) -> bool:
@@ -260,6 +262,7 @@ def value(self) -> List[int]:
260262

261263
@value.setter
262264
def value(self, new_value) -> None:
265+
"""値を差し替える。範囲外なら INVALID_ARGUMENT。"""
263266
self._value = self._validate(new_value)
264267

265268
def _validate(self, value) -> List[int]:
@@ -272,6 +275,7 @@ def _validate(self, value) -> List[int]:
272275
return result
273276

274277
def clone(self) -> "NbtTag":
278+
"""同じ値を持つ新しいタグを作る。"""
275279
return type(self)(list(self._value))
276280

277281
def __eq__(self, other) -> bool:
@@ -355,6 +359,7 @@ def clear(self) -> None:
355359
self._items.clear()
356360

357361
def clone(self) -> "NbtTag":
362+
"""同じ値を持つ新しいタグを作る。"""
358363
copy = NbtList(self._element_type)
359364

360365
# 要素も深くコピーする
@@ -471,6 +476,7 @@ def items(self) -> Iterator[Tuple[str, NbtTag]]:
471476
return iter(self._entries.items())
472477

473478
def clone(self) -> "NbtTag":
479+
"""同じ値を持つ新しいタグを作る。"""
474480
copy = NbtCompound()
475481

476482
# 挿入順のまま深くコピーする

0 commit comments

Comments
 (0)