Commit b3ca7459 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Fix clazy warnings

Most of the warning fixes are about range-for usage.
parent 9f185afc
Pipeline #87586 passed with stage
in 4 minutes and 44 seconds
......@@ -55,7 +55,7 @@ KateColorPickerConfigPage::KateColorPickerConfigPage(QWidget *parent, KateColorP
chkHexLengths.insert(6, new QCheckBox(i18n("6 digits (#RRGGBB)"), this));
chkHexLengths.insert(3, new QCheckBox(i18n("3 digits (#RGB)"), this));
for (QCheckBox *chk : chkHexLengths.values()) {
for (QCheckBox *chk : qAsConst(chkHexLengths)) {
hexLayout->addWidget(chk);
connect(chk, &QCheckBox::stateChanged, this, &KateColorPickerConfigPage::changed);
}
......@@ -117,8 +117,9 @@ void KateColorPickerConfigPage::reset()
chkNamedColors->setChecked(config.readEntry("NamedColors", false));
chkPreviewAfterColor->setChecked(config.readEntry("PreviewAfterColor", true));
QList<int> enabledHexLengths = config.readEntry("HexLengths", QList<int>{12, 9, 6, 3});
for (const int hexLength : chkHexLengths.keys()) {
const QList<int> enabledHexLengths = config.readEntry("HexLengths", QList<int>{12, 9, 6, 3});
const auto hexLengths = chkHexLengths.keys();
for (const int hexLength : hexLengths) {
chkHexLengths[hexLength]->setChecked(enabledHexLengths.contains(hexLength));
}
}
......@@ -37,7 +37,8 @@ ColorPickerInlineNoteProvider::ColorPickerInlineNoteProvider(KTextEditor::Docume
m_colorRegex.setPatternOptions(QRegularExpression::DontCaptureOption | QRegularExpression::CaseInsensitiveOption);
updateColorMatchingCriteria();
for (auto view : m_doc->views()) {
const auto views = m_doc->views();
for (auto view : views) {
qobject_cast<KTextEditor::InlineNoteInterface *>(view)->registerInlineNoteProvider(this);
}
......@@ -96,7 +97,8 @@ ColorPickerInlineNoteProvider::~ColorPickerInlineNoteProvider()
{
QPointer<KTextEditor::Document> doc = m_doc;
if (doc) {
for (auto view : m_doc->views()) {
const auto views = m_doc->views();
for (auto view : views) {
if (auto ini = qobject_cast<KTextEditor::InlineNoteInterface *>(view)) {
ini->unregisterInlineNoteProvider(this);
}
......@@ -267,7 +269,8 @@ KateColorPickerPlugin::~KateColorPickerPlugin() = default;
QObject *KateColorPickerPlugin::createView(KTextEditor::MainWindow *mainWindow)
{
m_mainWindow = mainWindow;
for (auto view : m_mainWindow->views()) {
const auto views = m_mainWindow->views();
for (auto view : views) {
addDocument(view->document());
}
......
......@@ -107,8 +107,6 @@ public:
QString text = option.text;
option.text = QString();
QColor textColor = normalColor;
option.widget->style()->drawControl(QStyle::CE_ItemViewItem, &option, painter, option.widget);
const AsmViewModel *m = static_cast<const AsmViewModel *>(index.model());
......
......@@ -51,7 +51,7 @@ void CEPluginView::openANewTab()
m_mainWidget = new CEWidget(this, m_mainWindow);
QWidget *mw = m_mainWindow->window();
QMetaObject::invokeMethod(mw, "addWidgetAsTab", Q_ARG(QWidget *, m_mainWidget));
QMetaObject::invokeMethod(mw, "addWidgetAsTab", Q_ARG(QWidget*, m_mainWidget));
}
// required for TextFilterPluginFactory vtable
......
......@@ -400,7 +400,7 @@ bool CEWidget::compilationFailed(const QJsonObject &obj)
lines << text.mid(i, maxChars);
}
for (const auto &line : lines) {
for (const auto &line : qAsConst(lines)) {
AsmRow r;
r.text = line;
rows.push_back(r);
......
......@@ -107,7 +107,7 @@ QString CompileDBReader::argsForFile(const QString &compile_commandsPath, const
QFileInfo fi(cmpCmdFile);
if (fi.isRelative()) {
QString dir = QDir::cleanPath(compileCommand.value(QStringLiteral("directory")).toString());
QString file = QDir::cleanPath(dir + QStringLiteral("/") + cmpCmdFile);
// QString file = QDir::cleanPath(dir + QStringLiteral("/") + cmpCmdFile);
} else {
if (fi.canonicalFilePath() == file) {
return compileCommand.value(QStringLiteral("command")).toString();
......@@ -155,7 +155,7 @@ static void removeIncludeArgument(QStringList &commands)
}
}
for (const auto &rem : toRemove) {
for (const auto &rem : qAsConst(toRemove)) {
commands.removeAll(rem);
}
}
......
......@@ -188,13 +188,13 @@ void KateExternalToolsPlugin::reload()
}
} else {
// first start -> use system config
for (const auto &tool : m_defaultTools) {
for (const auto &tool : qAsConst(m_defaultTools)) {
m_tools.push_back(new KateExternalTool(tool));
}
}
// FIXME test for a command name first!
for (auto *tool : m_tools) {
for (auto *tool : qAsConst(m_tools)) {
if (tool->hasexec && (!tool->cmdname.isEmpty())) {
m_commands.push_back(tool->cmdname);
}
......
......@@ -189,8 +189,8 @@ KateFileTreePluginView::KateFileTreePluginView(KTextEditor::MainWindow *mainWind
m_documentsCreatedTimer.setInterval(0);
connect(&m_documentsCreatedTimer, &QTimer::timeout, this, &KateFileTreePluginView::slotDocumentsCreated);
connect(m_documentModel, &KateFileTreeModel::triggerViewChangeAfterNameChange, [=] {
KateFileTreePluginView::viewChanged();
connect(m_documentModel, &KateFileTreeModel::triggerViewChangeAfterNameChange, this, [this] {
viewChanged();
});
m_fileTree->setModel(m_proxyModel);
......
......@@ -274,7 +274,7 @@ void KateGitBlamePluginView::showCommitInfo(const QString &hash, KTextEditor::Vi
void KateGitBlamePluginView::blameFinished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/)
{
QString stdErr = QString::fromUtf8(m_blameInfoProc.readAllStandardError());
// QString stdErr = QString::fromUtf8(m_blameInfoProc.readAllStandardError());
const QStringList stdOut = QString::fromUtf8(m_blameInfoProc.readAllStandardOutput()).split(QLatin1Char('\n'));
// check if the git process was running for a previous document when the view changed.
......@@ -301,7 +301,7 @@ void KateGitBlamePluginView::blameFinished(int /*exitCode*/, QProcess::ExitStatu
void KateGitBlamePluginView::showFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
QString stdErr = QString::fromUtf8(m_showProc.readAllStandardError());
// QString stdErr = QString::fromUtf8(m_showProc.readAllStandardError());
QString stdOut = QString::fromUtf8(m_showProc.readAllStandardOutput());
// Try to avoid crashes caused by QTextBrowser running out of memory
......
......@@ -24,7 +24,8 @@ public:
QObject *createView(KTextEditor::MainWindow *mainWindow) override
{
for (auto view : mainWindow->views())
const auto views = mainWindow->views();
for (auto view : views)
viewCreated(view);
connect(mainWindow, &KTextEditor::MainWindow::viewCreated, this, &LatexCompletionPlugin::viewCreated);
return nullptr;
......
......@@ -69,7 +69,7 @@ public:
private:
Q_SIGNALS:
// signal settings update
void update() const;
void update();
};
#endif
......@@ -369,7 +369,8 @@ public:
void readSessionConfig(const KConfigGroup &cg)
{
qCInfo(LSPCLIENT) << "reading session config";
for (const auto &fkey : cg.keyList()) {
const auto groups = cg.keyList();
for (const auto &fkey : groups) {
if (fkey.startsWith(ENTRY_PREFIX)) {
QString fname = fkey.mid(ENTRY_PREFIX.size());
QStringList entries = cg.readEntry(fkey, QStringList());
......@@ -423,7 +424,8 @@ public:
for (const auto &entry : {QString(), file}) {
auto it = m_suppressions.find(entry);
if (it != m_suppressions.end()) {
for (const auto &d : it.value()) {
const auto ds = it.value();
for (const auto &d : ds) {
result.push_back(d);
}
}
......@@ -1376,7 +1378,8 @@ public:
}
}
// also consider session suppressions
for (const auto &entry : self->m_sessionDiagnosticSuppressions.getSuppressions(localPath)) {
const auto suppressions = self->m_sessionDiagnosticSuppressions.getSuppressions(localPath);
for (const auto &entry : suppressions) {
auto pattern = QRegularExpression::escape(entry);
m_suppressions.push_back({QRegularExpression(pattern), {}});
}
......@@ -2562,7 +2565,8 @@ public:
KTextEditor::View *viewForUrl(const QUrl &url) const
{
for (auto *view : m_mainWindow->views()) {
const auto views = m_mainWindow->views();
for (auto *view : views) {
if (view->document()->url() == url) {
return view;
}
......@@ -2689,7 +2693,8 @@ public:
// but in either case (url change or close); remove lingering diagnostics
// collect active urls
QSet<QString> fpaths;
for (const auto &view : m_mainWindow->views()) {
const auto views = m_mainWindow->views();
for (const auto &view : views) {
if (auto doc = view->document()) {
fpaths.insert(doc->url().toLocalFile());
}
......
......@@ -247,7 +247,8 @@ static QJsonObject changeWorkspaceFoldersParams(const QList<LSPWorkspaceFolder>
static void from_json(QVector<QChar> &trigger, const QJsonValue &json)
{
for (const auto &t : json.toArray()) {
const auto triggersArray = json.toArray();
for (const auto &t : triggersArray) {
auto st = t.toString();
if (st.length()) {
trigger.push_back(st.at(0));
......@@ -467,7 +468,8 @@ static QList<LSPDocumentHighlight> parseDocumentHighlightList(const QJsonValue &
QList<LSPDocumentHighlight> ret;
// could be array
if (result.isArray()) {
for (const auto &def : result.toArray()) {
const auto defs = result.toArray();
for (const auto &def : defs) {
ret.push_back(parseDocumentHighlight(def));
}
} else if (result.isObject()) {
......@@ -509,7 +511,8 @@ static LSPHover parseHover(const QJsonValue &result)
// support the deprecated MarkedString[] variant, used by e.g. Rust rls
if (contents.isArray()) {
for (const auto &c : contents.toArray()) {
const auto elements = contents.toArray();
for (const auto &c : elements) {
ret.contents.push_back(parseHoverContentElement(c));
}
} else {
......@@ -562,13 +565,15 @@ static QList<LSPSymbolInformation> parseDocumentSymbols(const QJsonValue &result
list->push_back({name, kind, range, detail});
index.insert(name, &list->back());
// proceed recursively
for (const auto &child : symbol.value(QStringLiteral("children")).toArray()) {
const auto children = symbol.value(QStringLiteral("children")).toArray();
for (const auto &child : children) {
parseSymbol(child.toObject(), &list->back());
}
}
};
for (const auto &info : result.toArray()) {
const auto symInfos = result.toArray();
for (const auto &info : symInfos) {
parseSymbol(info.toObject(), nullptr);
}
return ret;
......@@ -579,7 +584,8 @@ static QList<LSPLocation> parseDocumentLocation(const QJsonValue &result)
QList<LSPLocation> ret;
// could be array
if (result.isArray()) {
for (const auto &def : result.toArray()) {
const auto locs = result.toArray();
for (const auto &def : locs) {
const auto &ob = def.toObject();
ret.push_back(parseLocation(ob));
// bogus server might have sent LocationLink[] instead
......@@ -610,7 +616,7 @@ static QList<LSPCompletionItem> parseDocumentCompletion(const QJsonValue &result
// return LSPTextEdit{range, newText};
// };
for (const auto &vitem : items) {
for (const auto &vitem : qAsConst(items)) {
const auto &item = vitem.toObject();
auto label = item.value(MEMBER_LABEL).toString();
auto detail = item.value(MEMBER_DETAIL).toString();
......@@ -636,7 +642,8 @@ static LSPSignatureInformation parseSignatureInformation(const QJsonObject &json
info.label = json.value(MEMBER_LABEL).toString();
info.documentation = parseMarkupContent(json.value(MEMBER_DOCUMENTATION));
for (const auto &rpar : json.value(QStringLiteral("parameters")).toArray()) {
const auto params = json.value(QStringLiteral("parameters")).toArray();
for (const auto &rpar : params) {
auto par = rpar.toObject();
auto label = par.value(MEMBER_LABEL);
int begin = -1, end = -1;
......@@ -669,9 +676,9 @@ static LSPSignatureInformation parseSignatureInformation(const QJsonObject &json
static LSPSignatureHelp parseSignatureHelp(const QJsonValue &result)
{
LSPSignatureHelp ret;
QJsonObject sig = result.toObject();
for (const auto &info : sig.value(QStringLiteral("signatures")).toArray()) {
const QJsonObject sig = result.toObject();
const auto sigInfos = sig.value(QStringLiteral("signatures")).toArray();
for (const auto &info : sigInfos) {
ret.signatures.push_back(parseSignatureInformation(info.toObject()));
}
ret.activeSignature = sig.value(QStringLiteral("activeSignature")).toInt(0);
......@@ -692,7 +699,8 @@ static QString parseClangdSwitchSourceHeader(const QJsonValue &result)
static QList<LSPTextEdit> parseTextEdit(const QJsonValue &result)
{
QList<LSPTextEdit> ret;
for (const auto &redit : result.toArray()) {
const auto textEdits = result.toArray();
for (const auto &redit : textEdits) {
auto edit = redit.toObject();
auto text = edit.value(QStringLiteral("newText")).toString();
auto range = parseRange(edit.value(MEMBER_RANGE).toObject());
......@@ -729,7 +737,7 @@ static QList<LSPDiagnostic> parseDiagnostics(const QJsonArray &result)
auto code = diag.value(QStringLiteral("code")).toString();
auto source = diag.value(QStringLiteral("source")).toString();
auto message = diag.value(MEMBER_MESSAGE).toString();
auto relatedInfo = diag.value(QStringLiteral("relatedInformation")).toArray();
const auto relatedInfo = diag.value(QStringLiteral("relatedInformation")).toArray();
QList<LSPDiagnosticRelatedInformation> relatedInfoList;
for (const auto &vrelated : relatedInfo) {
auto related = vrelated.toObject();
......@@ -745,7 +753,8 @@ static QList<LSPDiagnostic> parseDiagnostics(const QJsonArray &result)
static QList<LSPCodeAction> parseCodeAction(const QJsonValue &result)
{
QList<LSPCodeAction> ret;
for (const auto &vaction : result.toArray()) {
const auto codeActions = result.toArray();
for (const auto &vaction : codeActions) {
auto action = vaction.toObject();
// entry could be Command or CodeAction
if (!action.value(MEMBER_COMMAND).isString()) {
......
......@@ -259,7 +259,7 @@ public:
*/
int count = 0;
for (const auto &el : m_servers) {
for (const auto &el : qAsConst(m_servers)) {
for (const auto &si : el) {
auto &s = si.server;
if (!s) {
......@@ -282,7 +282,7 @@ public:
count = 0;
for (count = 0; count < 2; ++count) {
bool wait = false;
for (const auto &el : m_servers) {
for (const auto &el : qAsConst(m_servers)) {
for (const auto &si : el) {
auto &s = si.server;
if (!s) {
......@@ -308,7 +308,7 @@ public:
}
// match via regexes + cache result
for (auto it : m_highlightingModeRegexToLanguageId) {
for (const auto &it : m_highlightingModeRegexToLanguageId) {
if (it.first.match(mode).hasMatch()) {
m_highlightingModeToLanguageIdCache[mode] = it.second;
return it.second;
......@@ -621,7 +621,8 @@ private:
if (fileNamesForDetection.isArray()) {
// we try each file name alternative in the listed order
// this allows to have preferences
for (auto name : fileNamesForDetection.toArray()) {
const auto fileNames = fileNamesForDetection.toArray();
for (auto name : fileNames) {
if (name.isString()) {
auto root = rootForDocumentAndRootIndicationFileName(document, name.toString());
if (!root.isEmpty()) {
......@@ -664,7 +665,7 @@ private:
// maybe there is a server with other root that is workspace capable
if (!server && useWorkspace) {
for (const auto &l : m_servers) {
for (const auto &l : qAsConst(m_servers)) {
// for (auto it = l.begin(); it != l.end(); ++it) {
auto it = l.find(langId);
if (it != l.end()) {
......@@ -693,7 +694,8 @@ private:
if (!scmdline.isEmpty()) {
cmdline = scmdline.split(QLatin1Char(' '));
} else {
for (const auto &c : vcmdline.toArray()) {
const auto cmdOpts = vcmdline.toArray();
for (const auto &c : cmdOpts) {
cmdline.push_back(c.toString());
}
}
......@@ -978,7 +980,6 @@ private:
{
// determine server description
auto server = dynamic_cast<LSPClientServer *>(sender());
auto message = params.message;
if (isLog) {
Q_EMIT serverLogMessage(server, params);
} else {
......@@ -1014,7 +1015,7 @@ private:
void updateWorkspace(bool added, const QString &baseDir, const QString &name)
{
qCInfo(LSPCLIENT) << "update workspace" << added << baseDir << name;
for (const auto &u : m_servers) {
for (const auto &u : qAsConst(m_servers)) {
for (const auto &si : u) {
if (auto server = si.server) {
const auto &caps = server->capabilities();
......
......@@ -66,11 +66,11 @@ void SemanticHighlighter::doSemanticHighlighting_impl(KTextEditor::View *view)
auto doc = view->document();
if (m_docResultId.count(doc) == 0) {
connect(doc,
SIGNAL(aboutToInvalidateMovingInterfaceContent(KTextEditor::Document *)),
SIGNAL(aboutToInvalidateMovingInterfaceContent(KTextEditor::Document*)),
this,
SLOT(remove(KTextEditor::Document *)),
SLOT(remove(KTextEditor::Document*)),
Qt::UniqueConnection);
connect(doc, SIGNAL(aboutToDeleteMovingInterfaceContent(KTextEditor::Document *)), this, SLOT(remove(KTextEditor::Document *)), Qt::UniqueConnection);
connect(doc, SIGNAL(aboutToDeleteMovingInterfaceContent(KTextEditor::Document*)), this, SLOT(remove(KTextEditor::Document*)), Qt::UniqueConnection);
}
if (caps.semanticTokenProvider.range) {
......
......@@ -465,8 +465,6 @@ void GitWidget::showDiff(const QString &file, bool staged)
if (es != QProcess::NormalExit || exitCode != 0) {
sendMessage(i18n("Failed to get Diff of file: %1", QString::fromUtf8(git->readAllStandardError())), true);
} else {
const QString filename = file.isEmpty() ? QString() : QFileInfo(file).fileName();
auto addContextMenuActions = [this, file, staged](KTextEditor::View *v) {
auto m = v->contextMenu();
if (!staged) {
......@@ -567,7 +565,6 @@ QString GitWidget::getDiff(KTextEditor::View *v, bool hunk, bool alreadyStaged)
VcsDiff full;
full.setDiff(v->document()->text());
auto p = QUrl::fromUserInput(m_gitPath);
full.setBaseDiff(QUrl::fromUserInput(m_gitPath));
const auto dir = alreadyStaged ? VcsDiff::Reverse : VcsDiff::Forward;
......
......@@ -183,7 +183,7 @@ void KateProjectCompletion::allMatches(QStandardItemModel &model, KTextEditor::V
/**
* let project index fill the completion for this document
*/
for (const auto &project : projects) {
for (const auto &project : qAsConst(projects)) {
if (project->projectIndex()) {
project->projectIndex()->findMatches(model, view->document()->text(range), KateProjectIndex::CompletionMatches);
}
......
......@@ -81,7 +81,8 @@ void KateProjectIndex::loadCtags(const QStringList &files, const QVariantMap &ct
QStringList args;
args << QStringLiteral("-L") << QStringLiteral("-") << QStringLiteral("-f") << m_ctagsIndexFile->fileName() << QStringLiteral("--fields=+K+n");
const QString keyOptions = QStringLiteral("options");
for (const QVariant &optVariant : ctagsMap[keyOptions].toList()) {
const auto opts = ctagsMap[keyOptions].toList();
for (const QVariant &optVariant : opts) {
args << optVariant.toString();
}
ctags.start(QStringLiteral("ctags"), args);
......
......@@ -102,7 +102,8 @@ void KateProjectInfoViewIndex::slotTextChanged(const QString &text)
if (m_project && m_project->projectIndex() && !text.isEmpty()) {
m_project->projectIndex()->findMatches(*m_model, text, KateProjectIndex::FindMatches);
} else if (!text.isEmpty()) {
for (const auto &project : m_pluginView->plugin()->projects()) {
const auto projects = m_pluginView->plugin()->projects();
for (const auto &project : projects) {
if (project->projectIndex()) {
project->projectIndex()->findMatches(*m_model, text, KateProjectIndex::FindMatches, TAG_FULLMATCH | TAG_OBSERVECASE);
}
......
......@@ -71,7 +71,8 @@ KateProjectPlugin::KateProjectPlugin(QObject *parent, const QList<QVariant> &)
readConfig();
// register all already open documents, later we keep track of all newly created ones
for (auto document : KTextEditor::Editor::instance()->application()->documents()) {
const auto docs = KTextEditor::Editor::instance()->application()->documents();
for (auto document : docs) {
slotDocumentCreated(document);
}
......@@ -117,7 +118,7 @@ KateProjectPlugin::~KateProjectPlugin()
{
unregisterVariables();
for (KateProject *project : m_projects) {
for (KateProject *project : qAsConst(m_projects)) {
m_fileWatcher.removePath(QFileInfo(project->fileName()).canonicalPath());
delete project;
}
......@@ -181,7 +182,7 @@ KateProject *KateProjectPlugin::projectForDir(QDir dir, bool userSpecified)
// check for project and load it if found
const QString canonicalPath = dir.canonicalPath();
const QString canonicalFileName = dir.filePath(ProjectFileName);
for (KateProject *project : m_projects) {
for (KateProject *project : qAsConst(m_projects)) {
if (project->baseDir() == canonicalPath || project->fileName() == canonicalFileName) {
return project;
}
......@@ -226,7 +227,8 @@ KateProject *KateProjectPlugin::projectForDir(QDir dir, bool userSpecified)
bool KateProjectPlugin::closeProject(KateProject *project)
{
QVector<KTextEditor::Document *> projectDocuments;
for (auto doc : KTextEditor::Editor::instance()->application()->documents())
const auto docs = KTextEditor::Editor::instance()->application()->documents();
for (auto doc : docs)
if (QUrl(project->baseDir()).isParentOf(doc->url().adjusted(QUrl::RemoveScheme)))
projectDocuments.push_back(doc);
......@@ -305,7 +307,7 @@ void KateProjectPlugin::slotDocumentUrlChanged(KTextEditor::Document *document)
void KateProjectPlugin::slotDirectoryChanged(const QString &path)
{
QString fileName = QDir(path).filePath(ProjectFileName);
for (KateProject *project : m_projects) {
for (KateProject *project : qAsConst(m_projects)) {
if (project->fileName() == fileName) {
QDateTime lastModified = QFileInfo(fileName).lastModified();
if (project->fileLastModified().isNull() || (lastModified > project->fileLastModified())) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment