A tool to automatically organize and sort QML import statements according to best practices.
Caution
This tool is in very early development. Use at your own risk.
Warning
The current version of the tool removes comments between an optional license header and the start of the component.
- Automatically organizes QML imports into logical groups
- Sorts imports alphabetically within each group
- Preserves line endings across platforms (Unix, Windows, macOS)
- Supports stdin/stdout workflow or in-place file modification
- Can process multiple files at once
The tool organizes imports in the following order, with blank lines between groups:
- Pragmas (e.g., pragma Singleton)
- Qt imports (e.g., import QtQuick, import QtQuick.Controls)
- Library imports (e.g., import org.kde.kirigami)
- Module imports (e.g., import MyModule)
- Relative imports (e.g., import "../components")
Within each group, imports are sorted alphabetically.
Before:
// SPDX-FileCopyrightText: Jane Doe
//
// SPDX-License-Identifier: MIT
import "../components"
import MyModule
import QtQuick.Controls
import org.kde.kirigami as Kirigami
import QtQuick
pragma Singleton
QtObject {}After:
// SPDX-FileCopyrightText: Jane Doe
//
// SPDX-License-Identifier: MIT
pragma Singleton
import QtQuick
import QtQuick.Controls
import org.kde.kirigami as Kirigami
import MyModule
import "../components"
QtObject {}Download pre-built binaries from the releases page.
USAGE:
qmlimportsort [flags] [files...]
FLAGS:
--in-place, -i modify files in-place (only valid with files)
--help, -h show help
--version, -v print the version
Process files and output to stdout:
qmlimportsort Main.qml Component.qmlModify files in-place:
qmlimportsort -i Main.qml Component.qmlProcess from stdin:
cat Main.qml | qmlimportsortProcess all QML files in a directory:
find . -name "*.qml" -exec qmlimportsort -i {} +- Go 1.24 or later
just buildjust testContributions are welcome! Please feel free to submit issues or pull requests.