Kotlin / Kotlin/ktfmt

ktfmt rearranges comments on top of imports statements

Open
#300 13 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
1.3k
Forks
116
Avg merge
4d 10h
Merged PRs (30d)
15

Description

Let's say I have

import x
import y
//noinspection BannedImport
import z

ktfmt reformats it as

//noinspection BannedImport
import x
import y
import z

This is problematic because some linting tools use a comment to opt out of errors on an import statement. (for example android lint allows you to opt out of a import error with a comment, but then you run ktfmt and it rearranges the comments therefore causing lint to break again.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the Kotlin import and suppression-comment example from the report, then trace the import-sorting logic that associates comments with imports. Add a regression test showing that the suppression comment remains attached to import z and verify the formatter output against that test.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.