Disable "optimize import" on specific files

已回答

I have a couple files in my TypeScript project that have imports which IntelliJ thinks are unused, but actually are used. When I tun Optimize Imports it removes these imports and the project doesn't compile or run. However I usually have that option selected on commit. Can I direct IntelliJ to skip optimize imports for a specific file? I looked for something similar to // @formatter:off but couldn't find anything. I would also like it to skip import re-arrangement for a few files where the import order [unfortunately] matters.

5

There is no way to do it at the moment, related requests:

https://youtrack.jetbrains.com/issue/WEB-30221
https://youtrack.jetbrains.com/issue/IDEA-181612

Feel free to submit a new one for the specific issues that you have with TypeScript imports removed.

0
Avatar
Permanently deleted user

Could really use a feature to exclude files from optimize imports. Using XML-files as blueprints for testing generated messages. Optimize imports should not touch this file and the only solution right now is to turn of optimize imports completely when commiting the work related to these tests. 

0
Avatar
Permanently deleted user

I landed here looking for a way to disable an import-optimize in PyCharm and decided to just add an `assert` on the python object that would be removed by the optimizer and that disabled it for just the imports to be kept.

0

I'm running into this.   I want to disable the ts-lint noany rule on test.ts in an Angular project, but when I commit the file with optimize imports enabled, it re-orders the imports, which are order sensitive.

For now I can just disable that option when committing, but I like having a configuration option so that other team members do not accidentally do this.

 

0

there is currently no way to exclude certain imports from optimization, please follow https://youtrack.jetbrains.com/issue/WEB-31187 for updates

But note that you can disable it for specific files by creating a scope with these files included and adding this scope to Do not format, optimize imports, arrange code list in Preferences | Editor | Code StyleFormatter Control tab

2

请先登录再写评论。