saveourtool / diktat

Strict coding standard for Kotlin and a custom set of rules for detecting code smells, code style issues and bugs
https://diktat.saveourtool.com
MIT License
544 stars 39 forks source link

`FILE_UNORDERED_IMPORTS` error message doesn't match the style guide #1933

Open polarene opened 5 months ago

polarene commented 5 months ago

Describe the bug

When there is a violation on imports, the error message doesn't match Diktat style guide. The message says:

[FILE_UNORDERED_IMPORTS] imports should be ordered alphabetically and shouldn't be separated by newlines: import [...] (diktat-ruleset:file-structure)

while the corresponding style rule says:

From top to bottom, the order is the following:

  1. Android
  2. Imports of packages used internally in your organization
  3. Imports from other non-core dependencies
  4. Java core packages
  5. kotlin stdlib

Each category should be alphabetically arranged. Each group should be separated by a blank line.

In fact, running gradle diktatFix formats the code according to the convention above.

Expected behavior

The error message should match the style guide

Steps to Reproduce

  1. shuffle import declarations or remove blank lines between groups
  2. run gradle diktatCheck

Environment information

polarene commented 5 months ago

There's also an additional weird behavior: if I format the imports (manually or by Intellij) to match the desired order, diktatCheck passes even if there are no blank lines between the groups; then diktatFix doesn't make any change, I assume because it depends on the check task passing to avoid running.

But if the check task fails and you run the fix task it will format your imports adding the blank lines between groups, in addition to sorting them.