Optimize Imports¶
Native
Goal¶
Clean up redundant and duplicate open statements in your ReScript files to keep imports tidy and reduce noise.
Steps¶
1. Run Optimize Imports¶
With a .res file open, press Ctrl+Alt+O (Cmd+Alt+O on macOS), or use Code > Optimize Imports from the menu.
The plugin scans the file and automatically removes:
Duplicate opens — When the same module is opened more than once
open Belt
open Belt.Array
open Belt // duplicate
let arr = [1, 2, 3]
let doubled = arr->Array.map(x => x * 2)
open Belt
open Belt.Array
let arr = [1, 2, 3]
let doubled = arr->Array.map(x => x * 2)
2. Review inspection warnings¶
The Duplicate Open Detection inspection highlights redundant opens in real time as you edit. Look for yellow warning underlines on open statements.
Hover over the warning to see the details, or press Alt+Enter for a quick fix to remove the duplicate.
3. Configure auto-optimization (optional)¶
To run import optimization automatically on save or reformat:
Open Settings > Editor > Auto Import
Under the ReScript section, configure the auto-import behavior
Click Apply
You can also run import optimization as part of Code > Reformat Code (Ctrl+Alt+L / Cmd+Alt+L) by checking the Optimize imports option in the reformat dialog.
4. Project-wide optimization¶
To optimize imports across the entire project:
Select the project root (or a directory) in the Project panel
Use Code > Optimize Imports (Ctrl+Alt+O / Cmd+Alt+O)
Review the preview of changes and click Run
Expected Result¶
All .res files in the selected scope have clean, non-redundant open statements.
Tips¶
Combine import optimization with Reformat Code for a one-step cleanup workflow
The inspection can be configured in Settings > Editor > Inspections > ReScript > Duplicate open statement
Use
// noinspection RescriptDuplicateOpento suppress the warning for intentional duplicates