.editorconfig の解析処理を修正 - #2558
Open
beru wants to merge 9 commits into
Open
Conversation
|
Contributor
tab_widthの値をstd::from_charsに渡す際、valueではなくkeyを渡していた。keyは この時点で必ず"tab_width"であり整数として解析できないため、変換は常に失敗して EditorConfigParser::Parseがfalseを返していた。 このためtab_widthが効かないだけでなく、tab_widthを含む.editorconfigは ファイル全体が解析失敗として破棄され、同じファイルに書かれたindent_styleや indent_sizeも無視されていた。root = trueも読まれないため、探索が親ディレクトリへ 続いてしまう。 sakura-editor#2467 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
strieqが短い方の長さで_strnicmpを行っていたため、文字列全体ではなく前方一致で 判定されていた。このため"spacex"が"space"に、逆に"t"が"tab"に一致してしまう。 長さが0の文字列は任意の文字列に一致する。 EditorConfigの仕様では indent_style は tab / space、root は true / false と 決められた語のみが有効で、省略形や部分一致は認められていない。長さの一致を 条件に加えて厳密一致とした。 sakura-editor#2479 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
インデント幅の指定を伴わないindent_style = tabは、style.characterにTabsを設定した のちfalseを返していたため、呼び出し元が設定を受け取れず、内容からの自動検出結果で 上書きされていた。 EditorConfigの仕様ではtab_widthはindent_sizeを既定値とし、indent_sizeは indent_style = tabのときtab_widthに従うため、どちらも書かれていなければ幅の指定は 存在せず、エディタ自身の設定を使うのが正しい。style.tabSpaceを-1のままtrueを返す ことで、CDocEditor::OnAfterLoadの「タブ幅は元のままで変更しない」経路に到達する ようにした。 なおindent_style = spaceのみが指定された場合は、幅が決まらないと呼び出し元が スペース挿入を有効化しないため、今回は対象としない。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
.editorconfigとファイル内容からの検出のどちらを優先するかがコード上の 早期returnからしか読み取れず、ヘルプにも記述がないため、DetectIndentationStyleに 仕様をコメントとして残す。 記述したのは、.editorconfigを優先すること、.editorconfigの探索範囲、指定が 無かったものとして扱う条件、インデント幅を決められなかった場合に呼び出し元が 現在のタブ幅を維持すること、およびファイル内容から幅を検出できるのは半角空白の 場合のみであること。現時点の実装の追認であり、動作は変えていない。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
この関数は.editorconfigを探すだけでなく、パースとセクション照合を行って IndentationStyleを組み立てるところまでを担っている。またindent_style = tabの 単独指定に対応したことで、幅を何も決めていなくてもtrueを返すようになり、 「見つかったか」を表す名前との乖離が大きくなった。 実態に合わせて改名するとともに、戻り値が「インデントスタイルを決定できたか」で あって「.editorconfigを読めたか」ではないことをコメントに明記する。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
indent_style = tabは幅の指定が無くてもtrueを返すのに対し、indent_style = spaceは indent_sizeが無いとfalseを返す。この非対称は、幅が決まらないまま呼び出し元に渡しても スペース挿入が有効にならず、かつファイル内容からの検出まで抑止してしまうためであり、 意図的なものである。 理由が書かれていないと対称化する修正を招きかねないため、コメントとして残す。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
indent_sizeとtab_widthの値をstd::from_charsで解釈できなかった場合にfalseを返して いたため、EditorConfigParser::Parseが失敗し、.editorconfigに書かれた他の指定まで まとめて破棄されていた。 EditorConfigではどのプロパティにもunsetを指定でき、また認識できない値は無視すべき と定められている。indent_styleが認識できない値を無視するのに合わせて、数値として 解釈できない場合はそのプロパティの指定が無かったものとして扱う。 あわせて値全体が数値であることを要求する。std::from_charsは先頭が数値であれば 成功を返すため、これまで4xのような値が4として解釈されていた。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
CEditDocから使っているのはファイルパスとCDocLineMgrの2つだけなのに ドキュメント一式を受け取っており、parse配下のモジュールがdoc/CEditDoc.hに 依存していた。使う2つだけを受け取るようにしてincludeを落とす。 CEditDocは共有メモリとCEditAppシングルトンの初期化を伴うため単体では構築できず、 この形にすることで.editorconfigの解析をユニットテストから直接叩けるようにもなる。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
beru
force-pushed
the
fix/editorconfig_tab_width
branch
from
July 27, 2026 13:51
8abe7c5 to
eb9bb0a
Compare
一時ディレクトリに.editorconfigを置いてDetectIndentationStyleを直接叩く。 本PRで直した不具合を1件ずつ突く形にし、tab_widthの値解析、値比較の厳密一致、 indent_style = tab単独指定、解釈できない数値の無視をそれぞれ検証する。 併せてセクションのグロブ照合、親ディレクトリへの遡上、root = trueによる打ち切り、 ファイル内容からの検出への委譲も回帰防止として押さえる。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
beru
force-pushed
the
fix/editorconfig_tab_width
branch
from
July 27, 2026 14:10
eb9bb0a to
fa41dd7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.





PR対象
カテゴリ
PR の背景
@uzanka さんが報告してくれた不具合 #2467 #2479 に対応しました。
仕様・動作説明
PR の影響範囲
テスト内容
関連 issue, PR
#786 #2467 #2479
参考資料
https://editorconfig.org/