Skip to content

Add --range-start and --range-end CLI options for range formatting - #676

Open
samccone wants to merge 1 commit into
Kotlin:mainfrom
samccone:range-formatting
Open

Add --range-start and --range-end CLI options for range formatting#676
samccone wants to merge 1 commit into
Kotlin:mainfrom
samccone:range-formatting

Conversation

@samccone

Copy link
Copy Markdown

Implement character offset-based range formatting inspired by Prettier's range options (--range-start and --range-end).

Features:

  • --range-start <int>: start offset (inclusive, defaults to 0)
  • --range-end <int>: end offset (exclusive, defaults to EOF)
  • Support independent or paired usage with robust bounds validation
  • Safe range clamping in Formatter and KotlinInput to prevent out-of-bounds errors
  • Shebang offset adjustment and line-ending preservation
  • Expanded unit and integration test coverage across CLI, Tokenizer, and Formatter

Fixes: #573, #388

Implement character offset-based range formatting inspired by Prettier's
range options (--range-start and --range-end).

Features:
- `--range-start <int>`: start offset (inclusive, defaults to 0)
- `--range-end <int>`: end offset (exclusive, defaults to EOF)
- Support independent or paired usage with robust bounds validation
- Safe range clamping in Formatter and KotlinInput to prevent out-of-bounds errors
- Shebang offset adjustment and line-ending preservation
- Expanded unit and integration test coverage across CLI, Tokenizer, and Formatter

Fixes: Kotlin#573, Kotlin#388

@AbdullinAM AbdullinAM left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thank you for the contribution! I have some comments on the PR, but before doing a full review, can you please explain your motivation/use case for adding new CLI options for functionality that is already supported by ktfmt via --offset and --length?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reformat before commit and partial reformat is not supported from IntelliJ plugin

2 participants