feat: add trailing_comment_spacing option to preserve comment alignment#1129
Open
sobh wants to merge 1 commit into
Open
feat: add trailing_comment_spacing option to preserve comment alignment#1129sobh wants to merge 1 commit into
trailing_comment_spacing option to preserve comment alignment#1129sobh wants to merge 1 commit into
Conversation
…ment Add a new configuration option `trailing_comment_spacing` that controls how whitespace before trailing inline comments is handled: - `Compress` (default): always use a single space before comments - `Preserve`: keep the original spacing before comments This allows users to maintain aligned comments without the formatter collapsing the spacing. Configurable via stylua.toml, CLI flag, and EditorConfig. Also document all supported EditorConfig property mappings in the README.
3b7f239 to
57e31a1
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.
Summary
Adds a new
trailing_comment_spacingconfiguration option that controls whether the formatter compresses whitespace before trailing inline comments to a single space, or preserves the original spacing.This is useful for codebases that align trailing comments for readability:
Configuration
Possible values:
Compress: (default) — matches StyLua's original behavior of replacing all whitespace before a trailing comment with a single space.Preserve: keeps the original spacing as written in the source.stylua.toml:
CLI:
EditorConfig:
Changes
TrailingCommentSpacingenum tostylua_libformat_tokenandload_token_triviainsrc/formatters/general.rsto preserve original whitespace before trailing comments when configured--trailing-comment-spacing)stylua_trailing_comment_spacing)Testing