Result of "idea format" in terminal differs from the in editor formatter

已回答

Dear Intellij Team,

as our team grows, the diversity of editors in use is also growing. Intellij has a very specific import order/layout that we want to use in the other editors as well. Unfortunately the basic editorconfig doesn't support all the properties needed, so we came up with the solution to format all the edited files in a pre-commit hook. I was sure formatting via cli respects the editorconfig file and all of ideas special properties but it doesn't seem so. The cli formatter reorganizes the imports differently than the formatter in the editor itself.

Is there a solution for this?

 

Regards,

Afgeoijlejk

0

Could you please provide a code example to reproduce a problem?

0

I think the problem is more of a feature request. The formatter works fine when given a code style file to apply. But the import order stays the same after applying formatting from another formatter. The idea cli formatter doesn't have options like "optimize imports" or anything like this that you can activate on the "Reformat" option within the editor. It would be very helpful if these settings could be integrated to the cli formatter as well.

Example: You have a file like this formatted within intellij (just the imports).

import com.blub.LR;
import com.blub.db.P;
import com.blub.db.PFR;
import com.blub.db.PR;
import com.blub.importer.parser.PPR;
import com.blub.importer.parser.PP;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.InputStream;
import java.util.Collection;
import java.util.stream.Collectors;

When formatted with another editor (respecting editorconfig) you get something like this:

import java.io.InputStream;
import java.util.Collection;
import java.util.stream.Collectors;

import com.blub.LR;
import com.blub.db.P;
import com.blub.db.PFR;
import com.blub.db.PR;
import com.blub.importer.parser.PPR;
import com.blub.importer.parser.PP;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

and if you reformat the file with

idea format -s code_style.xml file.java

the import order stays the same as the one formatted within the editor using editorconfig but one would expect to apply the optimize import operation as well.

 

Regards,

Afgeoijlejk (sorry for this very late reply, totally forgot this thread exists)

0

Seems we have related request on YouTrack: https://youtrack.jetbrains.com/issue/IDEA-180965/Command-line-formatter-to-rearrange-code. Please follow it for updates.

0

请先登录再写评论。