aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorSami Shalayel <sami.shalayel@qt.io>2026-01-27 14:19:43 +0100
committerSami Shalayel <sami.shalayel@qt.io>2026-02-03 18:16:41 +0100
commitc4b45ab1b84bed31e32080387329f461a4ce1d07 (patch)
tree0503244ace6a231e48305d4eb02d92bea1a81a29 /tools
parent23776e71edee80821d532fc319c5569c51e66a50 (diff)
qmllint: don't confuse default values with user-set values
Rename settings to defaultSettings and categories to defaultCategories in qmllint.cpp, to discern them from settings and categories (that contains values set by command line or settings files). For each file, re-create new empty settings and create a category from the default category list. Amends 1568923e429b615a74ee7b1b15c6b9b02b6cb639 and removes the workarounds that it made --only-explicit-categories require. Pick-to: 6.11 6.10 Change-Id: Ia9aff347fe0f72210f405476cab4ef5697e7a57c Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qmllint/main.cpp66
1 files changed, 25 insertions, 41 deletions
diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp
index 8378f2be0b..d08e336db4 100644
--- a/tools/qmllint/main.cpp
+++ b/tools/qmllint/main.cpp
@@ -71,14 +71,14 @@ bool argumentsFromCommandLineAndFile(QStringList& allArguments, const QStringLis
int main(int argc, char *argv[])
{
QHashSeed::setDeterministicGlobalSeed();
- QList<QQmlJS::LoggerCategory> categories;
+ QList<QQmlJS::LoggerCategory> defaultCategories;
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationName("qmllint");
QCoreApplication::setApplicationVersion(QT_VERSION_STR);
QCommandLineParser parser;
- QQmlToolingSettings settings(QLatin1String("qmllint"),
- { QLatin1String("General"), QLatin1String("Warnings") });
+ QQmlToolingSettings defaultSettings(QLatin1String("qmllint"),
+ { QLatin1String("General"), QLatin1String("Warnings") });
parser.setApplicationDescription(QLatin1String(R"(QML syntax verifier and analyzer
All warnings can be set to four levels of severity:
@@ -122,7 +122,7 @@ All warnings can be set to four levels of severity:
QStringLiteral("resource"));
parser.addOption(resourceOption);
const QString &resourceSetting = QLatin1String("ResourcePath");
- settings.addOption(resourceSetting);
+ defaultSettings.addOption(resourceSetting);
QCommandLineOption qmlImportPathsOption(
QStringList() << "I"
@@ -131,7 +131,7 @@ All warnings can be set to four levels of severity:
QLatin1String("directory"));
parser.addOption(qmlImportPathsOption);
const QString qmlImportPathsSetting = QLatin1String("AdditionalQmlImportPaths");
- settings.addOption(qmlImportPathsSetting);
+ defaultSettings.addOption(qmlImportPathsSetting);
QCommandLineOption environmentOption(
QStringList() << "E",
@@ -144,7 +144,7 @@ All warnings can be set to four levels of severity:
"This may be used to run qmllint on a project using a different Qt version."));
parser.addOption(qmlImportNoDefault);
const QString qmlImportNoDefaultSetting = QLatin1String("DisableDefaultImports");
- settings.addOption(qmlImportNoDefaultSetting, false);
+ defaultSettings.addOption(qmlImportNoDefaultSetting, false);
QCommandLineOption qmldirFilesOption(
QStringList() << "i"
@@ -158,7 +158,7 @@ All warnings can be set to four levels of severity:
QLatin1String("qmldirs"));
parser.addOption(qmldirFilesOption);
const QString qmldirFilesSetting = QLatin1String("OverwriteImportTypes");
- settings.addOption(qmldirFilesSetting);
+ defaultSettings.addOption(qmldirFilesSetting);
QCommandLineOption absolutePath(
QStringList() << "absolute-path",
@@ -188,7 +188,7 @@ All warnings can be set to four levels of severity:
QLatin1String("plugins"));
parser.addOption(pluginsDisable);
const QString pluginsDisableSetting = QLatin1String("DisablePlugins");
- settings.addOption(pluginsDisableSetting);
+ defaultSettings.addOption(pluginsDisableSetting);
QCommandLineOption pluginPathsOption(
QStringList() << "P"
@@ -208,10 +208,10 @@ All warnings can be set to four levels of severity:
);
parser.addOption(maxWarnings);
const QString maxWarningsSetting = QLatin1String("MaxWarnings");
- settings.addOption(maxWarningsSetting, -1);
+ defaultSettings.addOption(maxWarningsSetting, -1);
// QTBUG-135020: don't break existing user configs and still accept PropertyAliasCycles
- settings.addOption("PropertyAliasCycles"_L1);
+ defaultSettings.addOption("PropertyAliasCycles"_L1);
const auto onlyExplicitCategoriesOptionName = "only-explicit-categories"_L1;
const auto onlyExplicitCategoriesSettingName = "OnlyExplicitCategories"_L1;
@@ -219,17 +219,17 @@ All warnings can be set to four levels of severity:
QStringList() << onlyExplicitCategoriesOptionName,
"Enable only categories explicitly set on the command line or in the settings file."_L1);
parser.addOption(onlyExplicitCategoriesOption);
- settings.addOption(onlyExplicitCategoriesSettingName, false);
+ defaultSettings.addOption(onlyExplicitCategoriesSettingName, false);
auto addCategory = [&](const QQmlJS::LoggerCategory &category) {
- categories.push_back(category);
+ defaultCategories.push_back(category);
const QString severity = QQmlJS::LoggingUtils::severityToString(category.severity());
QCommandLineOption option(category.id().name().toString(),
category.description() + " (default: %1)"_L1.arg(severity),
"severity"_L1, severity);
parser.addOption(option);
- settings.addOption("Warnings/"_L1 + category.settingsName(), severity);
+ defaultSettings.addOption("Warnings/"_L1 + category.settingsName(), severity);
};
for (const auto &category : QQmlJSLogger::builtinCategories()) {
@@ -308,7 +308,7 @@ All warnings can be set to four levels of severity:
}
if (parser.isSet(writeDefaultsOption)) {
- return settings.writeDefaults() ? 0 : 1;
+ return defaultSettings.writeDefaults() ? 0 : 1;
}
if (parser.isSet("help") || parser.isSet("help-all"))
@@ -357,37 +357,15 @@ All warnings can be set to four levels of severity:
}
if (parser.isSet(dryRun))
- settings.reportConfigForFiles(positionalArguments);
+ defaultSettings.reportConfigForFiles(positionalArguments);
- settings.saveValues();
QJsonArray jsonFiles;
- const auto checkOnlyExplicitCategories = [&](const QString &filename) -> bool {
- if (parser.isSet(onlyExplicitCategoriesOption))
- return true;
-
- if (parser.isSet(ignoreSettings))
- return false;
-
- // We need to check for the OnlyExplicitCategories setting separately because checking for
- // it overrides the default values for categories before we can read it.
- QQmlToolingSettings s("qmllint"_L1, { "General"_L1, "Warnings"_L1 });
- QQmlToolingSettings::SearchOptions options;
- options.isQmllintSilent = true;
- s.search(filename, options);
- return s.value(onlyExplicitCategoriesSettingName).toBool();
- };
-
for (const QString &filename : positionalArguments) {
- settings.restoreValues();
+ QQmlToolingSettings settings(QLatin1String("qmllint"),
+ { QLatin1String("General"), QLatin1String("Warnings") });
- const bool onlyExplicitCategories = checkOnlyExplicitCategories(filename);
- if (onlyExplicitCategories) {
- for (const auto &category : categories) {
- if (!category.isEssential())
- settings.setValue("Warnings/"_L1 + category.settingsName(), "disable");
- }
- }
+ QList<QQmlJS::LoggerCategory> categories = defaultCategories;
if (!parser.isSet(ignoreSettings)) {
QQmlToolingSettings::SearchOptions options;
@@ -395,6 +373,10 @@ All warnings can be set to four levels of severity:
settings.search(filename, options);
}
+ const bool onlyExplicitCategories = parser.isSet(onlyExplicitCategoriesOption)
+ || (settings.isSet(onlyExplicitCategoriesSettingName)
+ && settings.value(onlyExplicitCategoriesSettingName).toBool());
+
const auto categorySelection = onlyExplicitCategories
? QQmlJS::LoggingUtils::CategorySelection::Explicit
: QQmlJS::LoggingUtils::CategorySelection::All;
@@ -488,7 +470,9 @@ All warnings can be set to four levels of severity:
if (success) {
const qsizetype value = parser.isSet(maxWarnings)
? parser.value(maxWarnings).toInt()
- : settings.value(maxWarningsSetting).toInt();
+ : (settings.isSet(maxWarningsSetting)
+ ? settings.value(maxWarningsSetting).toInt()
+ : defaultSettings.value(maxWarningsSetting).toInt());
if (value != -1 && value < linter.logger()->numWarnings())
success = false;
}