pinterest / ktlint

An anti-bikeshedding Kotlin linter with built-in formatter
https://pinterest.github.io/ktlint/
MIT License
6.06k stars 504 forks source link

Restrict import package #2698

Closed greenlaw110 closed 2 weeks ago

greenlaw110 commented 2 weeks ago

Restrict import package, e.g. org.joda, org.junit etc.

Expected Rule behavior

When user specified a package to be restricted, e.g. org.joda, and if any kt source code has import org.joda.<AnyClass> then the rule should fail the check.

Additional information

paul-dingemans commented 2 weeks ago

Tnx for suggestion. It will not be implemented though.

Ktlint focusses primarily on rearranging code to make it more consistent and readible. Restricting which packages may, or may not be used, is not a function that fits in the scope of the project.

You can develop a custom ktlint rule yourself. See https://pinterest.github.io/ktlint/latest/api/custom-rule-set/ for a starting point.