Add SQL parameter validation to lint-scan#7
Merged
Conversation
Validate that SQL parameters (@param) in spanner.Statement match the keys in the Params map literal. Reports errors for both missing and unused parameters, consistent with existing ToStruct bidirectional checking. Also document that type compatibility is not checked. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Instead of silently skipping variable references in Params, report an error requiring a map literal for static analysis. Support //nolint:spantool comment to suppress the error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
@param) とParamsマップキーの整合性チェックを追加//nolint:spantoolで抑制可能)設計の背景
既存の ToStruct チェックと同様に双方向のエラー報告を採用した。ToStruct では struct にあるが SELECT にないフィールドもエラーとして報告しており、Params でも未使用キーを警告ではなくエラーとすることで一貫性を保っている。
Params が変数参照の場合はエラーを報告し、マップリテラルの使用を促す。静的解析不可能なケースでも
//nolint:spantoolコメントで明示的に抑制できる。検討した代替案
extractSQLParamsとextractSelectInfoが同じ SQL を個別にパースしているが、lint ツールの実行速度への影響は軽微なため、関心の分離を優先して現状のまま据え置いたextractMapLiteralKeysとlint.goのextractMapKeysの共通化: 戻り値の型([]stringvs[]mapKey)やエラー処理方針が異なるため、無理に統合せず個別に実装したTest plan
go test ./...全テスト通過//nolint:spantool(抑制)🤖 Generated with Claude Code