'Optimize Imports' and 'Reformat Code' functions do not adhere to my configured settings.

Answered

In our team, we adhere to a specific code formatting style, which I apply to each project. This includes a defined order for imports, configured as follows:

static all other, blank, java., blank, javax., blank, org., blank, com., blank, all other imports

i've also set up the 'do not format' settings for files with extensions {html, htm, jsp, properties, tld, yml, sql}.

Despite these configurations, IntelliJ's 'Optimize Imports' feature is not following this format, and SQL files continue to be reformatted without my knowledge.

To provide more context,
I imported a “formatter” file from Eclipse. I overwrote the default configuration for each project. There are numerous rules, including imports:

I checked the "use single class import" option in the Code Style > Java > Imports tab.

Use fully qualified class names in JavaDoc if not already imported.
Class count to use import with '*': 99
Names count to use static import with '*': 3
Next, I changed the following order in the sub-tab (difficult to resize, making screenshots more challenging):

static package with subpackag… (not checked)
import java.awt.*
import javax.swing.*
import jakarta.*

then,
Layout static imports separately (checked) and all following “with subpackages” is checked)

and i changed the following order: with blank lines to respect code format conventions
import static all other imports
blank line
import java.*
blank line
import javax.*
blank line
import.jakarta.*
blank line
import.org.*
blank line
import.com.*
blank line
import all other imports

However, when using the 'Optimize Imports' feature (shortcut CTRL + SHIFT + L), it does not adhere to these custom import settings. Manually copying and pasting imports is necessary to comply with the format conventions.

I'm currently using Ubuntu 20.04 LTS, and my IntelliJ Ultimate version is 2023.3.3. Despite having reported this issue, there has been no response from customer service, prompting me to seek assistance on this forum.

The problem extends to keyboard shortcuts like Alt+1, Alt+2, etc., which require customization for AZERTY keyboards. This issue has persisted for years.

1
4 comments

Hi,

> i've also set up the 'do not format' settings for files with extensions {html, htm, jsp, properties, tld, yml, sql}.

The format is not right. Please try *.{html,htm,jsp,properties,tld,yml,sql} (no space between , ).

> I imported a “formatter” file from Eclipse. I overwrote the default configuration for each project. There are numerous rules, including imports:

Have you installed any formater related plugin like `Adapter for Eclipse Code Formatter`? In this case, the IDE will use these formater plugins to format which doesn't use any IDE code style rules. You can check the plugin list in `Settings | Plugins | Installed tab`.

0

I tried the suggested tips without success. The spaces in {{html,htm,jsp,properties,tld,yml,sql} were well written (it is just my message in this forum wich was wrong).

0
Can you share a screenshot of `Settings | Editor | Code Style | Formatter tab`?
Please also reproduce this issue and share the IDE log file (idea.log) from IDE main menu `Help | Show Log in`.
You can upload the log file here https://uploads.jetbrains.com/ and share us the upload id. Thanks.
0

I would like to apologize. I finally found the cause. It's a "."  in the imports definition in the settings that caused the issue. So you can close the incident. Many thanks for your help. The incorrect definition and consideration of the regex was causing the issue. A thousand apologies

0

Please sign in to leave a comment.