Skip to content

fix: properly strip -- comments and convert tabs to spaces in sqlparse.format#26

Open
label-hook[bot] wants to merge 1 commit into
masterfrom
phoenix/issue-23
Open

fix: properly strip -- comments and convert tabs to spaces in sqlparse.format#26
label-hook[bot] wants to merge 1 commit into
masterfrom
phoenix/issue-23

Conversation

@label-hook
Copy link
Copy Markdown

@label-hook label-hook Bot commented Apr 7, 2026

Summary

Fixes two issues in sqlparse.format() when using strip_comments=True and reindent=True:

  1. -- style comments were not being properly stripped
  2. Tab characters were not being converted to spaces during reindentation

Closes #23

Changes

Comment Stripping Fix (sqlparse/filters/others.py)

  • Modified StripCommentsFilter._process() to properly handle single-line comments (--)
  • Added logic to completely remove T.Comment.Single tokens instead of just replacing content
  • Ensures all -- comments are fully stripped when strip_comments=True

Tab Normalization Fix (sqlparse/filters/reindent.py)

  • Enhanced ReindentFilter._process() to convert tab characters to spaces
  • Added tab-to-space conversion logic that respects the configured indent width
  • Ensures consistent space-based indentation when reindent=True

Testing

  • Created comprehensive test cases covering both issues
  • Verified that SQL with -- comments are completely removed when strip_comments=True
  • Confirmed that tab characters are properly converted to spaces during reindentation
  • Tested with the original issue.sql file to ensure both problems are resolved
  • All existing tests continue to pass, ensuring no regressions

Closes #23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:review Phoenix AI: PR ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlparse.format does not strip -- comments and fails to convert tabs to spaces when reindent=True

1 participant