Search code examples
intellij-ideacoding-styleintellij-15

In IntelliJ Ultimate, how can I set the code style to set absolute import before relative import?


In IntelliJ Ultimate, we are working on a react application and this is our code styles:

<code_scheme name="Default" version="173">
  <HTMLCodeStyleSettings>
    <option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
  </HTMLCodeStyleSettings>
  <JSCodeStyleSettings version="0">
    <option name="USE_DOUBLE_QUOTES" value="false" />
    <option name="FORCE_QUOTE_STYlE" value="true" />
    <option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
    <option name="SPACES_WITHIN_IMPORTS" value="true" />
  </JSCodeStyleSettings>
  <XML>
    <option name="XML_SPACE_INSIDE_EMPTY_TAG" value="true" />
  </XML>
  <codeStyleSettings language="JavaScript">
    <option name="IF_BRACE_FORCE" value="3" />
    <indentOptions>
      <option name="INDENT_SIZE" value="2" />
      <option name="TAB_SIZE" value="2" />
    </indentOptions>
  </codeStyleSettings>
</code_scheme>

Is there a way to set the code style to set absolute import before relative import?

import _ from 'lodash';
import User from './User';

bad

import User from './User';
import _ from 'lodash';

Solution

  • You can enable sorting the imports by the module name – that way all the application imports that start with ./ will go after the imports from node_modules. This option is available in Preferences | Editor | Code Style | JavaScript or TypeScript | Imports, Sort imports by modules.

    For advanced imports sorting/grouping support, please vote for WEB-21182