Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rangeUntil extension function import marked as unused #2373

Closed
dalewking opened this issue Nov 22, 2023 · 3 comments · Fixed by #2376
Closed

rangeUntil extension function import marked as unused #2373

dalewking opened this issue Nov 22, 2023 · 3 comments · Fixed by #2376

Comments

@dalewking
Copy link

dalewking commented Nov 22, 2023

I have an extension function like this to allow you to say something like now..<5.minutes to get an open ended range of instants:

/**
 * Convenience method to convert an instant and a duration into an open-ended range of instants. For
 * example: `now..<5.minutes` produces an open-ended range from now until 5 minutes from now
 *
 * @receiver The starting instant of the range
 * @param duration The amount of time to add to the starting time to get the end of the range
 * @return An open-ended range that starts at `this` and ends before `this + duration`
 */
operator fun Instant.rangeUntil(duration: Duration): OpenEndRange<Instant> = this..<this + duration

Expected Behavior

When I add an import in another file to use this operator, ktlint should know that ..< corresponds to the rangeUntil function name and should not report the import of the rangeUntil name as unused

Observed Behavior

Ktlint reports an unused import on the rangeUntil operator

Steps to Reproduce

Define a rangeUntil extension operator function in one file and import it and use it in another file

@dalewking
Copy link
Author

Ktlint is smart enough to do this for rangeTo function and the .. operator.

@dalewking
Copy link
Author

paul-dingemans added a commit that referenced this issue Nov 24, 2023
Removing this import results in compilation error when shorthand "..<" is used instead of function `rangeUntil(..)`.

Closes #2373
@paul-dingemans paul-dingemans added this to the 1.1 milestone Nov 24, 2023
@paul-dingemans
Copy link
Collaborator

Tnx for suggestion. It was an easy fix.

paul-dingemans added a commit that referenced this issue Nov 26, 2023
Removing this import results in compilation error when shorthand "..<" is used instead of function `rangeUntil(..)`.

Closes #2373
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants