ktlint icon indicating copy to clipboard operation
ktlint copied to clipboard

New rule: RedundantQualifierName

Open HarisHoulis opened this issue 3 years ago • 1 comments

Expected Behavior of the rule

It should recognise and (ideally) fix the RedundantQualifierName violation.

Context

Went through some package + classes movement and Android Studio added the full qualifier for some classes, even though it wasn't necessary.

Such a rule would be especially helpful when dealing with lots of files.

Example

package com.package.my

class Foo(val a: A) {

    companion object {
        fun from(bar: Bar) : com.package.my.Foo {
            /* factory code  */
        }
    }
}

If you run the Redundant qualifier name inspection in IntelliJ / Android Studio, you will see the warning.

Thanks!

HarisHoulis avatar Aug 18 '22 15:08 HarisHoulis

Strictly, this is not a violation of the Kotlin coding conventions or Android Kotlin Style Guide. So it does not fit the within the standard ktlint rulesets. Technically, it would not be that hard to write a rule for it and provide it via a custom ruleset.

paul-dingemans avatar Aug 18 '22 19:08 paul-dingemans

Ktlint should not try to implement all inspections which are already provided by IntelliJ IDEA and Android Studio.

I become to believe that Ktlint should be restricted

  • adding and removing whitespaces and newlines
  • adding and removing trailing comma's
  • adding and removing braces when needed to improve code readability.

Rules that causes the most problems are typically rules that are violating the principle above. A good example of this is the no-unused-imports rule.

paul-dingemans avatar Apr 09 '23 09:04 paul-dingemans