diff options
| author | Semih Yavuz <semih.yavuz@qt.io> | 2025-11-03 11:13:52 +0100 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2025-11-03 15:07:02 +0000 |
| commit | 282446da4cf67a50013cad3a98e5b4a7aaffa710 (patch) | |
| tree | 960a4ac7778749fe3dd14b074b13a1fb8e3f1541 /src/qmlformat/qqmlformatoptions.cpp | |
| parent | de3976722a3f9fec332e256856fb46aef4a51b78 (diff) | |
qmlformat: Fix SemicolonRule option ignored in config file
The SemicolonRule setting from .qmlformat.ini was not being applied,
only the command line option took effect.
Pick-to: 6.10
Fixes: QTBUG-141638
Change-Id: I471fde37c3650e872a893ce46bb5f55e9cc3158e
Initial-Patch-By: Dmitry Makarenko <kryksyh@gmail.com>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlformat/qqmlformatoptions.cpp')
| -rw-r--r-- | src/qmlformat/qqmlformatoptions.cpp | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/src/qmlformat/qqmlformatoptions.cpp b/src/qmlformat/qqmlformatoptions.cpp index 705467d4cf..6fb9dcdab1 100644 --- a/src/qmlformat/qqmlformatoptions.cpp +++ b/src/qmlformat/qqmlformatoptions.cpp @@ -68,6 +68,16 @@ QQmlFormatOptionLineEndings QQmlFormatOptions::parseEndings(const QString &endin #endif } +std::optional<QQmlJS::Dom::LineWriterOptions::SemicolonRule> parseSemicolonRule(const QString &value) { + if (value == "always"_L1) { + return QQmlJS::Dom::LineWriterOptions::SemicolonRule::Always; + } else if (value == "essential"_L1) { + return QQmlJS::Dom::LineWriterOptions::SemicolonRule::Essential; + } else { + return std::nullopt; + } +} + void QQmlFormatOptions::applySettings(const QQmlFormatSettings &settings) { // If the options is already set by commandline, don't override it with the values in the .ini @@ -115,6 +125,18 @@ void QQmlFormatOptions::applySettings(const QQmlFormatSettings &settings) && settings.isSet(QQmlFormatSettings::s_singleLineEmptyObjectsSetting)) { setSingleLineEmptyObjects(settings.value(QQmlFormatSettings::s_singleLineEmptyObjectsSetting).toBool()); } + + if (!isMarked(Settings::SemicolonRule) + && settings.isSet(QQmlFormatSettings::s_semiColonRuleSetting)) { + const auto semicolonRule = parseSemicolonRule( + settings.value(QQmlFormatSettings::s_semiColonRuleSetting).toString()); + if (!semicolonRule.has_value()) { + qWarning().noquote() << "Invalid semicolon rule in settings file, using 'always'"; + setSemicolonRule(QQmlJS::Dom::LineWriterOptions::SemicolonRule::Always); + } else { + setSemicolonRule(semicolonRule.value()); + } + } } QQmlFormatOptions QQmlFormatOptions::buildCommandLineOptions(const QStringList &args) @@ -361,14 +383,12 @@ QQmlFormatOptions QQmlFormatOptions::buildCommandLineOptions(const QStringList & if (parser.isSet(semicolonRuleOption)) { options.mark(Settings::SemicolonRule); const auto value = parser.value(semicolonRuleOption); - if (value == "always"_L1) { - options.setSemicolonRule(QQmlJS::Dom::LineWriterOptions::SemicolonRule::Always); - } else if (value == "essential"_L1) { - options.setSemicolonRule(QQmlJS::Dom::LineWriterOptions::SemicolonRule::Essential); - } else { - options.addError("Error: Invalid value passed to --semicolon-rule."_L1); + auto semicolonRule = parseSemicolonRule(value); + if (!semicolonRule.has_value()) { + options.addError("Error: Invalid value passed to --semicolon-rule. Must be 'always' or 'essential'."_L1); return options; } + options.setSemicolonRule(semicolonRule.value()); } options.setFiles(files); options.setArguments(parser.positionalArguments()); |
