aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qmlformat
diff options
context:
space:
mode:
authorOvidiu Tepescu <[email protected]>2024-12-18 15:15:50 +0100
committerOvidiu Tepescu <[email protected]>2025-01-13 11:13:58 +0100
commit57b681eb5179f9b2bdedd793a366a0e3f4148eed (patch)
tree59f9d255c08f4a41842f4a2ea24df68bf2008ce8 /tools/qmlformat
parentc0c1f96ad3e2a241fcaff327bea7bd38df9de378 (diff)
qmlformat: Reorder imports alphabetically
Reorder imports alphabetically. [ChangeLog][qmlformat] qmlformat now supports sorting of imports, there is a new commandline option -S that is used to sort imports. Fixes: QTBUG-132061 Change-Id: Ic163456d2beed84833f7aadef0688d37292ef0f2 Reviewed-by: Semih Yavuz <[email protected]>
Diffstat (limited to 'tools/qmlformat')
-rw-r--r--tools/qmlformat/qmlformat.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/tools/qmlformat/qmlformat.cpp b/tools/qmlformat/qmlformat.cpp
index d4fb5b9e53..6941f074d9 100644
--- a/tools/qmlformat/qmlformat.cpp
+++ b/tools/qmlformat/qmlformat.cpp
@@ -93,7 +93,7 @@ static bool parseFile(const QString &filename, const QQmlFormatOptions &options)
auto lwOptions = options.optionsForCode(code);
WriteOutChecks checks = WriteOutCheck::Default;
//Disable writeOutChecks for some usecases
- if (options.forceEnabled() || options.isMaxColumnWidthSet() || code.size() > 32000
+ if (options.sortImports() || options.forceEnabled() || options.isMaxColumnWidthSet() || code.size() > 32000
|| fileItem.internalKind() == DomType::JsFile) {
checks = WriteOutCheck::None;
}
@@ -179,6 +179,11 @@ QQmlFormatOptions buildCommandLineOptions(const QCoreApplication &app)
parser.addOption(QCommandLineOption(QStringList() << "functions-spacing", QStringLiteral("Ensure spaces between functions (only works with normalize option).")));
+ parser.addOption(
+ QCommandLineOption({ "S", "sort-imports" },
+ QStringLiteral("Sort imports alphabetically "
+ "(Warning: this might change semantics if a given name identifies types in multiple modules!).")));
+
parser.addPositionalArgument("filenames", "files to be processed by qmlformat");
parser.process(app);
@@ -222,6 +227,7 @@ QQmlFormatOptions buildCommandLineOptions(const QCoreApplication &app)
options.setNormalizeEnabled(parser.isSet("normalize"));
options.setObjectsSpacing(parser.isSet("objects-spacing"));
options.setFunctionsSpacing(parser.isSet("functions-spacing"));
+ options.setSortImports(parser.isSet("sort-imports"));
options.setIndentWidth(indentWidth);
options.setIndentWidthSet(parser.isSet("indent-width"));