Commit 3311fdde authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Add 'Clazy' code analysis tool


Signed-off-by: Waqar Ahmed's avatarWaqar Ahmed <waqar.17a@gmail.com>
parent 7dd8812f
......@@ -74,6 +74,8 @@ target_sources(
tools/kateprojectcodeanalysistoolflake8.cpp
tools/kateprojectcodeanalysistoolshellcheck.cpp
tools/kateprojectcodeanalysisselector.cpp
tools/kateprojectcodeanalysistoolclazy.cpp
tools/kateprojectcodeanalysistoolclazycurrent.cpp
git/gitdiff.cpp
git/gitutils.cpp
......
......@@ -35,3 +35,8 @@ void KateProjectCodeAnalysisTool::setActualFilesCount(int count)
{
m_filesCount = count;
}
void KateProjectCodeAnalysisTool::setMainWindow(KTextEditor::MainWindow *mainWin)
{
m_mainWindow = mainWin;
}
......@@ -13,6 +13,11 @@
#include "kateproject.h"
namespace KTextEditor
{
class MainWindow;
}
/**
* Information provider for a code analysis tool
*/
......@@ -27,6 +32,8 @@ protected:
*/
KateProject *m_project = nullptr;
KTextEditor::MainWindow *m_mainWindow;
public:
~KateProjectCodeAnalysisTool() override;
......@@ -116,6 +123,8 @@ public:
*/
void setActualFilesCount(int count);
void setMainWindow(KTextEditor::MainWindow *mainWin);
private:
int m_filesCount = 0;
};
......
......@@ -108,6 +108,7 @@ void KateProjectInfoViewCodeAnalysis::slotStartStopClicked()
*/
m_analysisTool = m_toolSelector->currentData(Qt::UserRole + 1).value<KateProjectCodeAnalysisTool *>();
m_analysisTool->setProject(m_project);
m_analysisTool->setMainWindow(m_pluginView->mainWindow());
/**
* clear existing entries
......@@ -240,6 +241,7 @@ void KateProjectInfoViewCodeAnalysis::finished(int exitCode, QProcess::ExitStatu
m_analysisTool->getActualFilesCount(),
exitCode));
}
static_cast<QVBoxLayout *>(layout())->addWidget(m_messageWidget);
m_messageWidget->animatedShow();
}
......@@ -7,6 +7,8 @@
#include "kateprojectcodeanalysisselector.h"
#include "kateprojectcodeanalysistoolclazy.h"
#include "kateprojectcodeanalysistoolclazycurrent.h"
#include "kateprojectcodeanalysistoolcppcheck.h"
#include "kateprojectcodeanalysistoolflake8.h"
#include "kateprojectcodeanalysistoolshellcheck.h"
......@@ -23,7 +25,11 @@ QStandardItemModel *KateProjectCodeAnalysisSelector::model(QObject *parent)
// flake8, for Python
new KateProjectCodeAnalysisToolFlake8(model),
// ShellCheck, for sh/bash scripts
new KateProjectCodeAnalysisToolShellcheck(model)};
new KateProjectCodeAnalysisToolShellcheck(model),
// clazy for Qt C++
new KateProjectCodeAnalysisToolClazy(model),
// clang-tidy
new KateProjectCodeAnalysisToolClazyCurrent(model)};
QList<QStandardItem *> column;
......
#include "kateprojectcodeanalysistoolclazy.h"
#include <KLocalizedString>
#include <QRegularExpression>
KateProjectCodeAnalysisToolClazy::KateProjectCodeAnalysisToolClazy(QObject *parent)
: KateProjectCodeAnalysisTool(parent)
{
}
QString KateProjectCodeAnalysisToolClazy::name() const
{
return i18n("Clazy (Qt/C++)");
}
QString KateProjectCodeAnalysisToolClazy::description() const
{
return i18n("Clazy is a static analysis tool for Qt/C++ code");
}
QString KateProjectCodeAnalysisToolClazy::fileExtensions() const
{
return QStringLiteral("cpp|cxx|cc|c++|tpp|txx");
}
QStringList KateProjectCodeAnalysisToolClazy::filter(const QStringList &files) const
{
// c++ files
return files.filter(
QRegularExpression(QStringLiteral("\\.(") + fileExtensions().replace(QStringLiteral("+"), QStringLiteral("\\+")) + QStringLiteral(")$")));
}
QString KateProjectCodeAnalysisToolClazy::path() const
{
return QStringLiteral("clazy-standalone");
}
QStringList KateProjectCodeAnalysisToolClazy::arguments()
{
if (!m_project) {
return {};
}
// check for compile_commands.json
bool hasCompileComds = QFile::exists(m_project->baseDir() + QStringLiteral("/build/compile_commands.json"));
QStringList args;
if (hasCompileComds) {
args = QStringList{QStringLiteral("-p"), m_project->baseDir() + QStringLiteral("/build")};
}
auto &&fileList = filter(m_project->files());
setActualFilesCount(fileList.size());
QString files = fileList.join(QLatin1Char(' '));
return args << fileList;
}
QString KateProjectCodeAnalysisToolClazy::notInstalledMessage() const
{
return i18n("Please install 'clazy'.");
}
QStringList KateProjectCodeAnalysisToolClazy::parseLine(const QString &line) const
{
//"/path/kate/kate/kateapp.cpp:529:10: warning: Missing reference in range-for with non trivial type (QJsonValue) [-Wclazy-range-loop]"
int idxColon = line.indexOf(QLatin1Char(':'));
if (idxColon < 0) {
return {};
}
QString file = line.mid(0, idxColon);
idxColon++;
int nextColon = line.indexOf(QLatin1Char(':'), idxColon);
QString lineNo = line.mid(idxColon, nextColon - idxColon);
int spaceIdx = line.indexOf(QLatin1Char(' '), nextColon);
if (spaceIdx < 0) {
return {};
}
idxColon = line.indexOf(QLatin1Char(':'), spaceIdx);
if (idxColon < 0) {
return {};
}
QString severity = line.mid(spaceIdx + 1, idxColon - (spaceIdx + 1));
idxColon++;
QString msg = line.mid(idxColon);
return {file, lineNo, severity, msg};
}
QString KateProjectCodeAnalysisToolClazy::stdinMessages()
{
return QString();
}
#ifndef KATEPROJECTCODEANALYSISTOOLCLAZY_H
#define KATEPROJECTCODEANALYSISTOOLCLAZY_H
#include <kateprojectcodeanalysistool.h>
class KateProjectCodeAnalysisToolClazy : public KateProjectCodeAnalysisTool
{
public:
explicit KateProjectCodeAnalysisToolClazy(QObject *parent = nullptr);
~KateProjectCodeAnalysisToolClazy() override = default;
QString name() const override;
QString description() const override;
QString fileExtensions() const override;
QStringList filter(const QStringList &files) const override;
QString path() const override;
QStringList arguments() override;
QString notInstalledMessage() const override;
QStringList parseLine(const QString &line) const override;
QString stdinMessages() override;
};
#endif // KATEPROJECTCODEANALYSISTOOLCLAZY_H
#include "kateprojectcodeanalysistoolclazycurrent.h"
#include <KLocalizedString>
#include <KTextEditor/MainWindow>
KateProjectCodeAnalysisToolClazyCurrent::KateProjectCodeAnalysisToolClazyCurrent(QObject *parent)
: KateProjectCodeAnalysisToolClazy(parent)
{
}
QString KateProjectCodeAnalysisToolClazyCurrent::name() const
{
return i18n("Clazy - Current File");
}
QString KateProjectCodeAnalysisToolClazyCurrent::description() const
{
return i18n("clang-tidy is a clang-based C++ “linter” tool");
}
QStringList KateProjectCodeAnalysisToolClazyCurrent::arguments()
{
if (!m_project || !m_mainWindow || !m_mainWindow->activeView()) {
return {};
}
// check for compile_commands.json
bool hasCompileComds = QFile::exists(m_project->baseDir() + QStringLiteral("/build/compile_commands.json"));
QStringList args;
if (hasCompileComds) {
args << QStringList{QStringLiteral("-p"), m_project->baseDir() + QStringLiteral("/build")};
}
setActualFilesCount(1);
const QString file = m_mainWindow->activeView()->document()->url().toLocalFile();
args.append(file);
return args;
}
#ifndef KATEPROJECTCODEANALYSISTOOLCLANGTIDY_H
#define KATEPROJECTCODEANALYSISTOOLCLANGTIDY_H
#include "kateprojectcodeanalysistoolclazy.h"
class KateProjectCodeAnalysisToolClazyCurrent : public KateProjectCodeAnalysisToolClazy
{
public:
KateProjectCodeAnalysisToolClazyCurrent(QObject *parent);
QString name() const override;
QString description() const override;
QStringList arguments() override;
};
#endif // KATEPROJECTCODEANALYSISTOOLCLANGTIDY_H
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