Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to handle false unused imports in intellij

Intellij falsely marked some import of Scala implicits as not being use. Is there a way to prevent it from deleting those import when optimized them explicitly for a specific import and not prevent optimized import for the entire project ?

like image 696
NetanelRabinowitz Avatar asked Apr 03 '17 07:04

NetanelRabinowitz


1 Answers

IntelliJ's Scala plugin now allows you to suppress this false warning on a project-wide level. That may not be appropriate for all cases, but it can help. Click the lightbulb then select "Mark import as always used in this project"

enter image description here

Alternatively you can add this directly to your code style xml:

<component name="ProjectCodeStyleConfiguration">
  <code_scheme name="Project" version="173">
    <ScalaCodeStyleSettings>
      <option name="alwaysUsedImports">
        <array>
          <option value="models.slickless.synchronized" />
          <option value="another.import.path" />
        </array>
      </option>
    </ScalaCodeStyleSettings>
  </code_scheme>
</component>

IntelliJ usually stores that file at .idea/codeStyles/Project.xml. It may be a good idea to commit this to your repository so it can be shared.

like image 134
Cory Klein Avatar answered Sep 28 '22 03:09

Cory Klein