forked from qt-creator/qt-creator
Cppcheck: Reduce uses of auto
Conform to coding rules. Change-Id: I57600bd450665d5db87710bb2444e39e7ecbf3e3 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
9644745b3d
commit
7f2bbe9cfb
@@ -67,7 +67,7 @@ public:
|
||||
m_binary->setExpectedKind(Utils::PathChooser::ExistingCommand);
|
||||
m_binary->setCommandVersionArguments({"--version"});
|
||||
|
||||
const auto variableChooser = new Core::VariableChooser (this);
|
||||
auto variableChooser = new Core::VariableChooser(this);
|
||||
variableChooser->addSupportedWidget (m_customArguments);
|
||||
|
||||
m_unusedFunction->setToolTip(tr("Disables multithreaded check."));
|
||||
@@ -77,10 +77,10 @@ public:
|
||||
"checking slower. Use only when needed."));
|
||||
m_guessArguments->setToolTip(tr("Like C++ standard and language."));
|
||||
|
||||
const auto layout = new QFormLayout(this);
|
||||
auto layout = new QFormLayout(this);
|
||||
layout->addRow(tr("Binary:"), m_binary);
|
||||
|
||||
const auto checks = new Utils::FlowLayout;
|
||||
auto checks = new Utils::FlowLayout;
|
||||
layout->addRow(tr("Checks:"), checks);
|
||||
checks->addWidget(m_warning);
|
||||
checks->addWidget(m_style);
|
||||
@@ -92,7 +92,7 @@ public:
|
||||
|
||||
layout->addRow(tr("Custom arguments:"), m_customArguments);
|
||||
layout->addRow(tr("Ignored file patterns:"), m_ignorePatterns);
|
||||
const auto flags = new Utils::FlowLayout;
|
||||
auto flags = new Utils::FlowLayout;
|
||||
layout->addRow(flags);
|
||||
flags->addWidget(m_inconclusive);
|
||||
flags->addWidget(m_forceDefines);
|
||||
@@ -169,7 +169,7 @@ CppcheckOptionsPage::CppcheckOptionsPage(CppcheckTool &tool, CppcheckTrigger &tr
|
||||
if (Utils::HostOsInfo::isAnyUnixHost()) {
|
||||
options.binary = "cppcheck";
|
||||
} else {
|
||||
auto programFiles = QDir::fromNativeSeparators(
|
||||
QString programFiles = QDir::fromNativeSeparators(
|
||||
QString::fromLocal8Bit(qgetenv("PROGRAMFILES")));
|
||||
if (programFiles.isEmpty())
|
||||
programFiles = "C:/Program Files";
|
||||
@@ -204,7 +204,7 @@ void CppcheckOptionsPage::finish()
|
||||
|
||||
void CppcheckOptionsPage::save(const CppcheckOptions &options) const
|
||||
{
|
||||
const auto s = Core::ICore::settings();
|
||||
QSettings *s = Core::ICore::settings();
|
||||
QTC_ASSERT(s, return);
|
||||
s->beginGroup(Constants::SETTINGS_ID);
|
||||
s->setValue(Constants::SETTINGS_BINARY, options.binary);
|
||||
@@ -227,7 +227,7 @@ void CppcheckOptionsPage::save(const CppcheckOptions &options) const
|
||||
|
||||
void CppcheckOptionsPage::load(CppcheckOptions &options) const
|
||||
{
|
||||
const auto s = Core::ICore::settings();
|
||||
QSettings *s = Core::ICore::settings();
|
||||
QTC_ASSERT(s, return);
|
||||
s->beginGroup(Constants::SETTINGS_ID);
|
||||
options.binary = s->value(Constants::SETTINGS_BINARY,
|
||||
|
||||
@@ -43,7 +43,7 @@ CppcheckRunner::CppcheckRunner(CppcheckTool &tool) :
|
||||
QProcess getConf;
|
||||
getConf.start("getconf ARG_MAX");
|
||||
getConf.waitForFinished(2000);
|
||||
const auto argMax = getConf.readAllStandardOutput().replace("\n", "");
|
||||
const QByteArray argMax = getConf.readAllStandardOutput().replace("\n", "");
|
||||
m_maxArgumentsLength = std::max(argMax.toInt(), m_maxArgumentsLength);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ CppcheckRunner::CppcheckRunner(CppcheckTool &tool) :
|
||||
this, &CppcheckRunner::handleFinished);
|
||||
|
||||
m_queueTimer.setSingleShot(true);
|
||||
const auto checkDelayInMs = 200;
|
||||
const int checkDelayInMs = 200;
|
||||
m_queueTimer.setInterval(checkDelayInMs);
|
||||
connect(&m_queueTimer, &QTimer::timeout,
|
||||
this, &CppcheckRunner::checkQueued);
|
||||
@@ -78,7 +78,7 @@ void CppcheckRunner::reconfigure(const QString &binary, const QString &arguments
|
||||
void CppcheckRunner::addToQueue(const Utils::FileNameList &files,
|
||||
const QString &additionalArguments)
|
||||
{
|
||||
auto &existing = m_queue[additionalArguments];
|
||||
Utils::FileNameList &existing = m_queue[additionalArguments];
|
||||
if (existing.isEmpty()) {
|
||||
existing = files;
|
||||
} else {
|
||||
@@ -110,7 +110,7 @@ void CppcheckRunner::removeFromQueue(const Utils::FileNameList &files)
|
||||
m_queue.clear();
|
||||
} else {
|
||||
for (auto it = m_queue.begin(), end = m_queue.end(); it != end;) {
|
||||
for (const auto &file : files)
|
||||
for (const Utils::FileName &file : files)
|
||||
it.value().removeOne(file);
|
||||
it = !it.value().isEmpty() ? ++it : m_queue.erase(it);
|
||||
}
|
||||
@@ -133,7 +133,7 @@ void CppcheckRunner::checkQueued()
|
||||
if (m_queue.isEmpty() || m_binary.isEmpty())
|
||||
return;
|
||||
|
||||
auto files = m_queue.begin().value();
|
||||
Utils::FileNameList files = m_queue.begin().value();
|
||||
QString arguments = m_arguments + ' ' + m_queue.begin().key();
|
||||
m_currentFiles.clear();
|
||||
int argumentsLength = arguments.length();
|
||||
@@ -163,7 +163,7 @@ void CppcheckRunner::readOutput()
|
||||
m_process->setReadChannel(QProcess::StandardOutput);
|
||||
|
||||
while (!m_process->atEnd() && m_process->canReadLine()) {
|
||||
auto line = QString::fromUtf8(m_process->readLine());
|
||||
QString line = QString::fromUtf8(m_process->readLine());
|
||||
if (line.endsWith('\n'))
|
||||
line.chop(1);
|
||||
m_tool.parseOutputLine(line);
|
||||
@@ -178,7 +178,7 @@ void CppcheckRunner::readError()
|
||||
m_process->setReadChannel(QProcess::StandardError);
|
||||
|
||||
while (!m_process->atEnd() && m_process->canReadLine()) {
|
||||
auto line = QString::fromUtf8(m_process->readLine());
|
||||
QString line = QString::fromUtf8(m_process->readLine());
|
||||
if (line.endsWith('\n'))
|
||||
line.chop(1);
|
||||
m_tool.parseErrorLine(line);
|
||||
|
||||
@@ -70,7 +70,7 @@ CppcheckTextMark::CppcheckTextMark (const Diagnostic &diagnostic)
|
||||
m_checkId(diagnostic.checkId),
|
||||
m_message(diagnostic.message)
|
||||
{
|
||||
const auto visual = getVisual(diagnostic.severity);
|
||||
const Visual visual = getVisual(diagnostic.severity);
|
||||
setPriority(visual.priority);
|
||||
setColor(visual.color);
|
||||
setIcon(visual.icon);
|
||||
|
||||
@@ -38,9 +38,8 @@ CppcheckTextMarkManager::~CppcheckTextMarkManager() = default;
|
||||
|
||||
void CppcheckTextMarkManager::add(const Diagnostic &diagnostic)
|
||||
{
|
||||
auto &fileMarks = m_marks[diagnostic.fileName];
|
||||
const auto finder = [diagnostic] (const MarkPtr &mark) {return *mark == diagnostic;};
|
||||
if (Utils::contains(fileMarks, finder))
|
||||
std::vector<MarkPtr> &fileMarks = m_marks[diagnostic.fileName];
|
||||
if (Utils::contains(fileMarks, [diagnostic](const MarkPtr &mark) {return *mark == diagnostic;}))
|
||||
return;
|
||||
|
||||
fileMarks.push_back(std::make_unique<CppcheckTextMark>(diagnostic));
|
||||
@@ -52,7 +51,7 @@ void CppcheckTextMarkManager::clearFiles(const Utils::FileNameList &files)
|
||||
return;
|
||||
|
||||
if (!files.empty()) {
|
||||
for (const auto &file: files)
|
||||
for (const Utils::FileName &file : files)
|
||||
m_marks.erase(file);
|
||||
} else {
|
||||
m_marks.clear();
|
||||
|
||||
@@ -61,9 +61,8 @@ void CppcheckTool::updateOptions(const CppcheckOptions &options)
|
||||
{
|
||||
m_options = options;
|
||||
m_filters.clear();
|
||||
const auto patterns = m_options.ignoredPatterns.split(',');
|
||||
for (const auto &pattern : patterns) {
|
||||
const auto trimmedPattern = pattern.trimmed();
|
||||
for (const QString &pattern : m_options.ignoredPatterns.split(',')) {
|
||||
const QString trimmedPattern = pattern.trimmed();
|
||||
if (trimmedPattern.isEmpty())
|
||||
continue;
|
||||
|
||||
@@ -90,8 +89,8 @@ void CppcheckTool::updateArguments()
|
||||
|
||||
QStringList arguments;
|
||||
if (!m_options.customArguments.isEmpty()) {
|
||||
auto expander = Utils::globalMacroExpander();
|
||||
const auto expanded = expander->expand(m_options.customArguments);
|
||||
Utils::MacroExpander *expander = Utils::globalMacroExpander();
|
||||
const QString expanded = expander->expand(m_options.customArguments);
|
||||
arguments.push_back(expanded);
|
||||
}
|
||||
|
||||
@@ -127,8 +126,8 @@ QStringList CppcheckTool::additionalArguments(const CppTools::ProjectPart &part)
|
||||
QStringList result;
|
||||
|
||||
if (m_options.addIncludePaths) {
|
||||
for (const auto &path : qAsConst(part.headerPaths)) {
|
||||
const auto projectDir = m_project->projectDirectory().toString();
|
||||
for (const ProjectExplorer::HeaderPath &path : part.headerPaths) {
|
||||
const QString projectDir = m_project->projectDirectory().toString();
|
||||
if (path.type == ProjectExplorer::HeaderPathType::User
|
||||
&& path.path.startsWith(projectDir))
|
||||
result.push_back("-I " + path.path);
|
||||
@@ -186,7 +185,7 @@ void CppcheckTool::check(const Utils::FileNameList &files)
|
||||
} else {
|
||||
std::copy_if(files.cbegin(), files.cend(), std::back_inserter(filtered),
|
||||
[this](const Utils::FileName &file) {
|
||||
const auto stringed = file.toString();
|
||||
const QString stringed = file.toString();
|
||||
const auto filter = [stringed](const QRegExp &re) {return re.exactMatch(stringed);};
|
||||
return !Utils::contains(m_filters, filter);
|
||||
});
|
||||
@@ -195,8 +194,8 @@ void CppcheckTool::check(const Utils::FileNameList &files)
|
||||
if (filtered.isEmpty())
|
||||
return;
|
||||
|
||||
const auto info = CppTools::CppModelManager::instance()->projectInfo(m_project);
|
||||
const auto parts = info.projectParts();
|
||||
const CppTools::ProjectInfo info = CppTools::CppModelManager::instance()->projectInfo(m_project);
|
||||
const QVector<CppTools::ProjectPart::Ptr> parts = info.projectParts();
|
||||
if (parts.size() == 1) {
|
||||
QTC_ASSERT(parts.first(), return);
|
||||
addToQueue(filtered, *parts.first());
|
||||
@@ -204,14 +203,13 @@ void CppcheckTool::check(const Utils::FileNameList &files)
|
||||
}
|
||||
|
||||
std::map<CppTools::ProjectPart::Ptr, Utils::FileNameList> groups;
|
||||
for (const auto &file : qAsConst(filtered)) {
|
||||
const auto stringed = file.toString();
|
||||
for (const auto &part : parts) {
|
||||
for (const Utils::FileName &file : qAsConst(filtered)) {
|
||||
const QString stringed = file.toString();
|
||||
for (const CppTools::ProjectPart::Ptr &part : parts) {
|
||||
using CppTools::ProjectFile;
|
||||
QTC_ASSERT(part, continue);
|
||||
const auto &partFiles = part->files;
|
||||
using File = CppTools::ProjectFile;
|
||||
const auto match = [stringed](const File &file){return file.path == stringed;};
|
||||
if (Utils::contains(partFiles, match))
|
||||
const auto match = [stringed](const ProjectFile &pFile){return pFile.path == stringed;};
|
||||
if (Utils::contains(part->files, match))
|
||||
groups[part].push_back(file);
|
||||
}
|
||||
}
|
||||
@@ -222,7 +220,7 @@ void CppcheckTool::check(const Utils::FileNameList &files)
|
||||
|
||||
void CppcheckTool::addToQueue(const Utils::FileNameList &files, CppTools::ProjectPart &part)
|
||||
{
|
||||
const auto key = part.id();
|
||||
const QString key = part.id();
|
||||
if (!m_cachedAdditionalArguments.contains(key))
|
||||
m_cachedAdditionalArguments.insert(key, additionalArguments(part).join(' '));
|
||||
m_runner->addToQueue(files, m_cachedAdditionalArguments[key]);
|
||||
@@ -237,12 +235,12 @@ void CppcheckTool::stop(const Utils::FileNameList &files)
|
||||
void CppcheckTool::startParsing()
|
||||
{
|
||||
if (m_options.showOutput) {
|
||||
const auto message = tr("Cppcheck started: \"%1\".").arg(m_runner->currentCommand());
|
||||
const QString message = tr("Cppcheck started: \"%1\".").arg(m_runner->currentCommand());
|
||||
Core::MessageManager::write(message, Core::MessageManager::Silent);
|
||||
}
|
||||
|
||||
m_progress = std::make_unique<QFutureInterface<void>>();
|
||||
const auto progress = Core::ProgressManager::addTask(
|
||||
const Core::FutureProgress *progress = Core::ProgressManager::addTask(
|
||||
m_progress->future(), QObject::tr("Cppcheck"),
|
||||
Constants::CHECK_PROGRESS_ID);
|
||||
QObject::connect(progress, &Core::FutureProgress::canceled,
|
||||
@@ -260,12 +258,12 @@ void CppcheckTool::parseOutputLine(const QString &line)
|
||||
Core::MessageManager::write(line, Core::MessageManager::Silent);
|
||||
|
||||
enum Matches { Percentage = 1 };
|
||||
const auto match = m_progressRegexp.match(line);
|
||||
const QRegularExpressionMatch match = m_progressRegexp.match(line);
|
||||
if (!match.hasMatch())
|
||||
return;
|
||||
|
||||
const auto done = match.captured(Percentage).toInt();
|
||||
QTC_ASSERT(m_progress, return);
|
||||
const int done = match.captured(Percentage).toInt();
|
||||
m_progress->setProgressValue(done);
|
||||
}
|
||||
|
||||
@@ -291,12 +289,11 @@ void CppcheckTool::parseErrorLine(const QString &line)
|
||||
Core::MessageManager::write(line, Core::MessageManager::Silent);
|
||||
|
||||
enum Matches { File = 1, Line, Severity, Id, Message };
|
||||
const auto match = m_messageRegexp.match(line);
|
||||
const QRegularExpressionMatch match = m_messageRegexp.match(line);
|
||||
if (!match.hasMatch())
|
||||
return;
|
||||
|
||||
const auto fileName = Utils::FileName::fromString(
|
||||
QDir::fromNativeSeparators(match.captured(File)));
|
||||
const Utils::FileName fileName = Utils::FileName::fromUserInput(match.captured(File));
|
||||
if (!m_runner->currentFiles().contains(fileName))
|
||||
return;
|
||||
|
||||
|
||||
@@ -76,19 +76,19 @@ void CppcheckTrigger::checkEditors(const QList<Core::IEditor *> &editors)
|
||||
return;
|
||||
|
||||
using CppModelManager = CppTools::CppModelManager;
|
||||
const auto info = CppModelManager::instance()->projectInfo(m_currentProject);
|
||||
const CppTools::ProjectInfo info = CppModelManager::instance()->projectInfo(m_currentProject);
|
||||
if (!info.isValid())
|
||||
return;
|
||||
|
||||
const auto editorList = !editors.isEmpty()
|
||||
const QList<Core::IEditor *> editorList = !editors.isEmpty()
|
||||
? editors : Core::DocumentModel::editorsForOpenedDocuments();
|
||||
|
||||
Utils::FileNameList toCheck;
|
||||
for (const auto editor: editorList) {
|
||||
for (const Core::IEditor *editor : editorList) {
|
||||
QTC_ASSERT(editor, continue);
|
||||
const auto document = editor->document();
|
||||
Core::IDocument *document = editor->document();
|
||||
QTC_ASSERT(document, continue);
|
||||
const auto &path = document->filePath();
|
||||
const Utils::FileName &path = document->filePath();
|
||||
if (path.isEmpty())
|
||||
continue;
|
||||
|
||||
@@ -98,7 +98,7 @@ void CppcheckTrigger::checkEditors(const QList<Core::IEditor *> &editors)
|
||||
if (!m_currentProject->isKnownFile(path))
|
||||
continue;
|
||||
|
||||
const auto &pathString = path.toString();
|
||||
const QString &pathString = path.toString();
|
||||
if (!info.sourceFiles().contains(pathString))
|
||||
continue;
|
||||
|
||||
@@ -125,15 +125,15 @@ void CppcheckTrigger::removeEditors(const QList<Core::IEditor *> &editors)
|
||||
if (!m_currentProject)
|
||||
return;
|
||||
|
||||
const auto editorList = !editors.isEmpty()
|
||||
const QList<Core::IEditor *> editorList = !editors.isEmpty()
|
||||
? editors : Core::DocumentModel::editorsForOpenedDocuments();
|
||||
|
||||
Utils::FileNameList toRemove;
|
||||
for (const auto editor: editorList) {
|
||||
for (const Core::IEditor *editor : editorList) {
|
||||
QTC_ASSERT(editor, return);
|
||||
const auto document = editor->document();
|
||||
const Core::IDocument *document = editor->document();
|
||||
QTC_ASSERT(document, return);
|
||||
const auto &path = document->filePath();
|
||||
const Utils::FileName &path = document->filePath();
|
||||
if (path.isEmpty())
|
||||
return;
|
||||
|
||||
@@ -156,7 +156,7 @@ void CppcheckTrigger::checkChangedDocument(Core::IDocument *document)
|
||||
if (!m_currentProject)
|
||||
return;
|
||||
|
||||
const auto &path = document->filePath();
|
||||
const Utils::FileName &path = document->filePath();
|
||||
QTC_ASSERT(!path.isEmpty(), return);
|
||||
if (!m_checkedFiles.contains(path))
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user