diff --git a/addons/project/CMakeLists.txt b/addons/project/CMakeLists.txt index 593491bb9..678719794 100644 --- a/addons/project/CMakeLists.txt +++ b/addons/project/CMakeLists.txt @@ -1,46 +1,50 @@ project(kateprojectplugin) find_package(KF5NewStuff ${KF5_DEP_VERSION} REQUIRED) # For KMoreTools include_directories( ${CMAKE_CURRENT_BINARY_DIR} ) add_definitions(-DTRANSLATION_DOMAIN=\"kateproject\") set(kateprojectplugin_PART_SRCS fileutil.cpp kateprojectplugin.cpp kateprojectpluginview.cpp kateproject.cpp kateprojectworker.cpp kateprojectitem.cpp kateprojectview.cpp kateprojectviewtree.cpp kateprojecttreeviewcontextmenu.cpp kateprojectinfoview.cpp kateprojectcompletion.cpp kateprojectindex.cpp kateprojectinfoviewindex.cpp kateprojectinfoviewterminal.cpp kateprojectinfoviewcodeanalysis.cpp kateprojectinfoviewnotes.cpp kateprojectconfigpage.cpp + kateprojectcodeanalysistool.cpp + tools/kateprojectcodeanalysistoolcppcheck.cpp + tools/kateprojectcodeanalysistoolflake8.cpp + tools/kateprojectcodeanalysisselector.cpp ) # resource for ui file and stuff qt5_add_resources(kateprojectplugin_PART_SRCS plugin.qrc) add_library(kateprojectplugin MODULE ${kateprojectplugin_PART_SRCS}) kcoreaddons_desktop_to_json (kateprojectplugin kateprojectplugin.desktop) target_link_libraries(kateprojectplugin KF5::TextEditor KF5::Parts KF5::I18n KF5::GuiAddons Qt5::Script KF5::ItemViews KF5::ItemModels KF5::IconThemes KF5::ThreadWeaver KF5::NewStuff # For KMoreTools ) ########### install files ############### install(TARGETS kateprojectplugin DESTINATION ${PLUGIN_INSTALL_DIR}/ktexteditor ) install( FILES kateproject.example DESTINATION ${DATA_INSTALL_DIR}/kateproject ) ############# unit tests ################ ecm_optional_add_subdirectory (autotests) diff --git a/addons/project/kateprojectcodeanalysistool.cpp b/addons/project/kateprojectcodeanalysistool.cpp new file mode 100644 index 000000000..0abbba77d --- /dev/null +++ b/addons/project/kateprojectcodeanalysistool.cpp @@ -0,0 +1,36 @@ +/* This file is part of the Kate project. + * + * Copyright (C) 2017 Héctor Mesa Jiménez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "kateprojectcodeanalysistool.h" + +KateProjectCodeAnalysisTool::KateProjectCodeAnalysisTool(QObject *parent) + : QObject(parent) + , m_project(nullptr) +{ +} + +void KateProjectCodeAnalysisTool::setProject(KateProject *project) +{ + m_project = project; +} + +KateProjectCodeAnalysisTool::~KateProjectCodeAnalysisTool() +{ +} diff --git a/addons/project/kateprojectcodeanalysistool.h b/addons/project/kateprojectcodeanalysistool.h new file mode 100644 index 000000000..bb966da7c --- /dev/null +++ b/addons/project/kateprojectcodeanalysistool.h @@ -0,0 +1,94 @@ +/* This file is part of the Kate project. + * + * Copyright (C) 2017 Héctor Mesa Jiménez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KATE_PROJECT_CODE_ANALYSIS_TOOL_H +#define KATE_PROJECT_CODE_ANALYSIS_TOOL_H + +#include +#include + +#include "kateproject.h" + +/** + * Information provider for a code analysis tool + */ +class KateProjectCodeAnalysisTool: public QObject +{ + Q_OBJECT +protected: + explicit KateProjectCodeAnalysisTool(QObject *parent = nullptr); + + /** + * Current project + */ + KateProject *m_project; + +public: + virtual ~KateProjectCodeAnalysisTool(); + + /** + * bind to this project + * @param project project this tool will analyse + */ + virtual void setProject(KateProject *project); + + /** + * @return tool descriptive name + */ + virtual QString name() = 0; + + /** + * filter relevant files + * @param files set of files in project + * @return relevant files that can be analysed + */ + virtual QStringList filter(const QStringList &files) = 0; + + /** + * @return tool path + */ + virtual QString path() = 0; + + /** + * @return arguments required for the tool + */ + virtual QStringList arguments() = 0; + + /** + * @return warning message when the tool is not installed + */ + virtual QString notInstalledMessage() = 0; + + /** + * parse output line + * @param line + * @return file, line, severity, message + */ + virtual QStringList parseLine(const QString &line) = 0; + + /** + * @return messages passed to the tool through stdin + */ + virtual QString stdinMessages() = 0; +}; + +Q_DECLARE_METATYPE(KateProjectCodeAnalysisTool*) + +#endif // KATE_PROJECT_CODE_ANALYSIS_TOOL_H diff --git a/addons/project/kateprojectinfoviewcodeanalysis.cpp b/addons/project/kateprojectinfoviewcodeanalysis.cpp index f996bb6ff..e9057c8d5 100644 --- a/addons/project/kateprojectinfoviewcodeanalysis.cpp +++ b/addons/project/kateprojectinfoviewcodeanalysis.cpp @@ -1,216 +1,228 @@ /* This file is part of the Kate project. * * Copyright (C) 2012 Christoph Cullmann * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kateprojectinfoviewcodeanalysis.h" #include "kateprojectpluginview.h" +#include "kateprojectcodeanalysistool.h" +#include "tools/kateprojectcodeanalysisselector.h" #include #include #include #include #include KateProjectInfoViewCodeAnalysis::KateProjectInfoViewCodeAnalysis(KateProjectPluginView *pluginView, KateProject *project) : QWidget() , m_pluginView(pluginView) , m_project(project) , m_messageWidget(nullptr) , m_startStopAnalysis(new QPushButton(i18n("Start Analysis..."))) , m_treeView(new QTreeView()) , m_model(new QStandardItemModel(m_treeView)) , m_analyzer(nullptr) + , m_analysisTool(nullptr) + , m_toolSelector(new QComboBox()) { /** * default style */ m_treeView->setEditTriggers(QAbstractItemView::NoEditTriggers); m_treeView->setUniformRowHeights(true); m_treeView->setRootIsDecorated(false); m_model->setHorizontalHeaderLabels(QStringList() << i18n("File") << i18n("Line") << i18n("Severity") << i18n("Message")); /** * attach model * kill selection model */ QItemSelectionModel *m = m_treeView->selectionModel(); m_treeView->setModel(m_model); delete m; m_treeView->setSortingEnabled(true); m_treeView->sortByColumn(1, Qt::AscendingOrder); m_treeView->sortByColumn(2, Qt::AscendingOrder); + /** + * attach model to code analysis selector + */ + m_toolSelector->setModel(KateProjectCodeAnalysisSelector::model(this)); + /** * layout widget */ QVBoxLayout *layout = new QVBoxLayout; layout->setSpacing(0); layout->addWidget(m_treeView); QHBoxLayout *hlayout = new QHBoxLayout; layout->addLayout(hlayout); hlayout->setSpacing(0); hlayout->addStretch(); + hlayout->addWidget(m_toolSelector); hlayout->addWidget(m_startStopAnalysis); setLayout(layout); /** * connect needed signals */ connect(m_startStopAnalysis, &QPushButton::clicked, this, &KateProjectInfoViewCodeAnalysis::slotStartStopClicked); connect(m_treeView, &QTreeView::clicked, this, &KateProjectInfoViewCodeAnalysis::slotClicked); } KateProjectInfoViewCodeAnalysis::~KateProjectInfoViewCodeAnalysis() { } void KateProjectInfoViewCodeAnalysis::slotStartStopClicked() { /** - * get files for cppcheck + * get files for the external tool */ - QStringList files = m_project->files().filter(QRegExp(QStringLiteral("\\.(cpp|cxx|cc|c\\+\\+|c|tpp|txx)$"))); + m_analysisTool = m_toolSelector->currentData(Qt::UserRole + 1).value(); + m_analysisTool->setProject(m_project); /** * clear existing entries */ m_model->removeRows(0, m_model->rowCount(), QModelIndex()); /** * launch cppcheck */ m_analyzer = new QProcess(this); m_analyzer->setProcessChannelMode(QProcess::MergedChannels); connect(m_analyzer, &QProcess::readyRead, this, &KateProjectInfoViewCodeAnalysis::slotReadyRead); connect(m_analyzer, static_cast(&QProcess::finished), this, &KateProjectInfoViewCodeAnalysis::finished); - QStringList args; - args << QStringLiteral("-q") << QStringLiteral("--inline-suppr") << QStringLiteral("--enable=all") << QStringLiteral("--template={file}////{line}////{severity}////{message}") << QStringLiteral("--file-list=-"); - m_analyzer->start(QStringLiteral("cppcheck"), args); + m_analyzer->start(m_analysisTool->path(), m_analysisTool->arguments()); if (m_messageWidget) { delete m_messageWidget; m_messageWidget = nullptr; } if (!m_analyzer->waitForStarted()) { m_messageWidget = new KMessageWidget(); m_messageWidget->setCloseButtonVisible(true); m_messageWidget->setMessageType(KMessageWidget::Warning); m_messageWidget->setWordWrap(false); - m_messageWidget->setText(i18n("Please install 'cppcheck'.")); + m_messageWidget->setText(m_analysisTool->notInstalledMessage()); static_cast(layout())->insertWidget(0, m_messageWidget); m_messageWidget->animatedShow(); return; } /** * write files list and close write channel */ - m_analyzer->write(files.join(QStringLiteral("\n")).toLocal8Bit()); + const QString stdinMessage = m_analysisTool->stdinMessages(); + if (!stdinMessage.isEmpty()) { + m_analyzer->write(stdinMessage.toLocal8Bit()); + } m_analyzer->closeWriteChannel(); } void KateProjectInfoViewCodeAnalysis::slotReadyRead() { /** * get results of analysis */ while (m_analyzer->canReadLine()) { /** * get one line, split it, skip it, if too few elements */ QString line = QString::fromLocal8Bit(m_analyzer->readLine()); - QStringList elements = line.split(QRegExp(QStringLiteral("////")), QString::SkipEmptyParts); + QStringList elements = m_analysisTool->parseLine(line); if (elements.size() < 4) { continue; } /** * feed into model */ QList items; QStandardItem *fileNameItem = new QStandardItem(QFileInfo(elements[0]).fileName()); fileNameItem->setToolTip(elements[0]); items << fileNameItem; items << new QStandardItem(elements[1]); items << new QStandardItem(elements[2]); const auto message = elements[3].simplified(); auto messageItem = new QStandardItem(message); messageItem->setToolTip(message); items << messageItem; m_model->appendRow(items); } /** * tree view polish ;) */ m_treeView->resizeColumnToContents(2); m_treeView->resizeColumnToContents(1); m_treeView->resizeColumnToContents(0); } void KateProjectInfoViewCodeAnalysis::slotClicked(const QModelIndex &index) { /** * get path */ QString filePath = m_model->item(index.row(), 0)->toolTip(); if (filePath.isEmpty()) { return; } /** * create view */ KTextEditor::View *view = m_pluginView->mainWindow()->openUrl(QUrl::fromLocalFile(filePath)); if (!view) { return; } /** * set cursor, if possible */ int line = m_model->item(index.row(), 1)->text().toInt(); if (line >= 1) { view->setCursorPosition(KTextEditor::Cursor(line - 1, 0)); } } void KateProjectInfoViewCodeAnalysis::finished(int exitCode, QProcess::ExitStatus) { m_messageWidget = new KMessageWidget(); m_messageWidget->setCloseButtonVisible(true); m_messageWidget->setWordWrap(false); if (exitCode == 0) { m_messageWidget->setMessageType(KMessageWidget::Information); m_messageWidget->setText(i18n("Analysis finished.")); } else { // unfortunately, output was eaten by slotReadyRead() // TODO: get stderr output, show it here m_messageWidget->setMessageType(KMessageWidget::Warning); m_messageWidget->setText(i18n("Analysis failed!")); } static_cast(layout ())->insertWidget(0, m_messageWidget); m_messageWidget->animatedShow (); } diff --git a/addons/project/kateprojectinfoviewcodeanalysis.h b/addons/project/kateprojectinfoviewcodeanalysis.h index e8356caa1..f4a04d798 100644 --- a/addons/project/kateprojectinfoviewcodeanalysis.h +++ b/addons/project/kateprojectinfoviewcodeanalysis.h @@ -1,124 +1,131 @@ /* This file is part of the Kate project. * * Copyright (C) 2010 Christoph Cullmann * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KATE_PROJECT_INFO_VIEW_CODE_ANALYSIS_H #define KATE_PROJECT_INFO_VIEW_CODE_ANALYSIS_H #include "kateproject.h" #include #include #include +#include class KateProjectPluginView; +class KateProjectCodeAnalysisTool; class KMessageWidget; /** * View for Code Analysis. * cppcheck and perhaps later more... */ class KateProjectInfoViewCodeAnalysis : public QWidget { Q_OBJECT public: /** * construct project info view for given project * @param pluginView our plugin view * @param project project this view is for */ KateProjectInfoViewCodeAnalysis(KateProjectPluginView *pluginView, KateProject *project); /** * deconstruct info view */ ~KateProjectInfoViewCodeAnalysis() override; /** * our project. * @return project */ KateProject *project() const { return m_project; } private Q_SLOTS: /** * Called if start/stop button is clicked. */ void slotStartStopClicked(); /** * More checker output is available */ void slotReadyRead(); /** * item got clicked, do stuff, like open document * @param index model index of clicked item */ void slotClicked(const QModelIndex &index); /** * Analysis finished * @param exitCode analyser process exit code * @param exitStatus analyser process exit status */ void finished(int exitCode, QProcess::ExitStatus exitStatus); private: /** * our plugin view */ KateProjectPluginView *m_pluginView; /** * our project */ KateProject *m_project; /** * information widget showing a warning about missing ctags. */ KMessageWidget *m_messageWidget; /** * start/stop analysis button */ QPushButton *m_startStopAnalysis; /** * tree view for results */ QTreeView *m_treeView; /** * standard item model for results */ QStandardItemModel *m_model; /** * running analyzer process */ QProcess *m_analyzer; + + KateProjectCodeAnalysisTool *m_analysisTool; + + QComboBox *m_toolSelector; + }; #endif diff --git a/addons/project/tools/kateprojectcodeanalysisselector.cpp b/addons/project/tools/kateprojectcodeanalysisselector.cpp new file mode 100644 index 000000000..d8dfbf35d --- /dev/null +++ b/addons/project/tools/kateprojectcodeanalysisselector.cpp @@ -0,0 +1,53 @@ +/* This file is part of the Kate project. + * + * Copyright (C) 2017 Héctor Mesa Jiménez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "kateprojectcodeanalysisselector.h" + +#include "kateprojectcodeanalysistoolcppcheck.h" +#include "kateprojectcodeanalysistoolflake8.h" + +QStandardItemModel *KateProjectCodeAnalysisSelector::model(QObject *parent) +{ + auto model = new QStandardItemModel(parent); + + /* + * available linters + */ + const QList tools = { + // cppcheck, for C++ + new KateProjectCodeAnalysisToolCppcheck(model), + // flake8, for Python + new KateProjectCodeAnalysisToolFlake8(model) + }; + + QList column; + + for (auto tool : tools) { + auto item = new QStandardItem(tool->name()); + item->setData(QVariant::fromValue(tool), Qt::UserRole + 1); + + column << item; + } + + model->appendColumn(column); + + return model; +} + diff --git a/addons/project/tools/kateprojectcodeanalysisselector.h b/addons/project/tools/kateprojectcodeanalysisselector.h new file mode 100644 index 000000000..3ff0b3dfc --- /dev/null +++ b/addons/project/tools/kateprojectcodeanalysisselector.h @@ -0,0 +1,39 @@ +/* This file is part of the Kate project. + * + * Copyright (C) 2017 Héctor Mesa Jiménez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KATE_PROJECT_CODE_ANALYSIS_SELECTOR_H +#define KATE_PROJECT_CODE_ANALYSIS_SELECTOR_H + +#include + +class KateProjectCodeAnalysisSelector +{ +public: + + /** + * Model attachable to a code analysis tool selector. + * + * Each item contains a pointer to a KateProjectCodeAnalysisTool + * associated to the role Qt::UserRole + 1 + */ + static QStandardItemModel *model(QObject* parent = nullptr); +}; + +#endif // KATE_PROJECT_CODE_ANALYSIS_SELECTOR_H diff --git a/addons/project/tools/kateprojectcodeanalysistoolcppcheck.cpp b/addons/project/tools/kateprojectcodeanalysistoolcppcheck.cpp new file mode 100644 index 000000000..ea6a6d7a8 --- /dev/null +++ b/addons/project/tools/kateprojectcodeanalysistoolcppcheck.cpp @@ -0,0 +1,85 @@ +/* This file is part of the Kate project. + * + * Copyright (C) 2017 Héctor Mesa Jiménez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "kateprojectcodeanalysistoolcppcheck.h" + +#include +#include + +KateProjectCodeAnalysisToolCppcheck::KateProjectCodeAnalysisToolCppcheck(QObject *parent) + : KateProjectCodeAnalysisTool(parent) +{ + +} + +KateProjectCodeAnalysisToolCppcheck::~KateProjectCodeAnalysisToolCppcheck() +{ + +} + +QString KateProjectCodeAnalysisToolCppcheck::name() +{ + return i18n("cppcheck"); +} + +QStringList KateProjectCodeAnalysisToolCppcheck::filter(const QStringList &files) +{ + // c++ files + return files.filter(QRegularExpression(QStringLiteral("\\.(cpp|cxx|cc|c\\+\\+|c|tpp|txx)$"))); +} + +QString KateProjectCodeAnalysisToolCppcheck::path() +{ + return QStringLiteral("cppcheck"); +} + +QStringList KateProjectCodeAnalysisToolCppcheck::arguments() +{ + QStringList _args; + + _args << QStringLiteral("-q") + << QStringLiteral("--inline-suppr") + << QStringLiteral("--enable=all") + << QStringLiteral("--template={file}////{line}////{severity}////{message}") + << QStringLiteral("--file-list=-"); + + return _args; +} + +QString KateProjectCodeAnalysisToolCppcheck::notInstalledMessage() +{ + return i18n("Please install 'cppcheck'."); +} + +QStringList KateProjectCodeAnalysisToolCppcheck::parseLine(const QString &line) +{ + return line.split(QRegExp(QStringLiteral("////")), QString::SkipEmptyParts); +} + +QString KateProjectCodeAnalysisToolCppcheck::stdinMessages() +{ + // filenames are written to stdin (--file-list=-) + + if (!m_project) { + return QString(); + } + + return filter(m_project->files()).join(QStringLiteral("\n")); +} diff --git a/addons/project/tools/kateprojectcodeanalysistoolcppcheck.h b/addons/project/tools/kateprojectcodeanalysistoolcppcheck.h new file mode 100644 index 000000000..35620251f --- /dev/null +++ b/addons/project/tools/kateprojectcodeanalysistoolcppcheck.h @@ -0,0 +1,51 @@ +/* This file is part of the Kate project. + * + * Copyright (C) 2017 Héctor Mesa Jiménez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KATE_PROJECT_CODE_ANALYSIS_TOOL_CPPCHECK_H +#define KATE_PROJECT_CODE_ANALYSIS_TOOL_CPPCHECK_H + +#include "../kateprojectcodeanalysistool.h" + +/** + * Information provider for cppcheck + */ +class KateProjectCodeAnalysisToolCppcheck: public KateProjectCodeAnalysisTool +{ +public: + explicit KateProjectCodeAnalysisToolCppcheck(QObject *parent = nullptr); + + virtual ~KateProjectCodeAnalysisToolCppcheck() override; + + virtual QString name() override; + + virtual QStringList filter(const QStringList &files) override; + + virtual QString path() override; + + virtual QStringList arguments() override; + + virtual QString notInstalledMessage() override; + + virtual QStringList parseLine(const QString &line) override; + + virtual QString stdinMessages() override; +}; + +#endif // KATE_PROJECT_CODE_ANALYSIS_TOOL_CPPCHECK_H diff --git a/addons/project/tools/kateprojectcodeanalysistoolflake8.cpp b/addons/project/tools/kateprojectcodeanalysistoolflake8.cpp new file mode 100644 index 000000000..ee3f74f63 --- /dev/null +++ b/addons/project/tools/kateprojectcodeanalysistoolflake8.cpp @@ -0,0 +1,89 @@ +/* This file is part of the Kate project. + * + * Copyright (C) 2017 Héctor Mesa Jiménez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "kateprojectcodeanalysistoolflake8.h" + +#include +#include + +KateProjectCodeAnalysisToolFlake8::KateProjectCodeAnalysisToolFlake8(QObject *parent) + : KateProjectCodeAnalysisTool(parent) +{ + +} + +KateProjectCodeAnalysisToolFlake8::~KateProjectCodeAnalysisToolFlake8() +{ + +} + +QString KateProjectCodeAnalysisToolFlake8::name() +{ + return i18n("flake8"); +} + +QStringList KateProjectCodeAnalysisToolFlake8::filter(const QStringList &files) +{ + // for now we expect files with extension + return files.filter(QRegularExpression(QStringLiteral("\\.py$"))); +} + +QString KateProjectCodeAnalysisToolFlake8::path() +{ + /* + * for now, only the executable in the path can be called, + * but it would be great to be able to specify a version + * installed in a virtual environment + */ + return QStringLiteral("flake8"); +} + +QStringList KateProjectCodeAnalysisToolFlake8::arguments() +{ + QStringList _args; + + _args << QStringLiteral("--exit-zero") + /* + * translating a flake8 code to a severity level is subjective, + * so the code is provided as a severity level. + */ + << QStringLiteral("--format=%(path)s////%(row)d////%(code)s////%(text)s"); + + if (m_project) { + _args.append(filter(m_project->files())); + } + + return _args; +} + +QString KateProjectCodeAnalysisToolFlake8::notInstalledMessage() +{ + return i18n("Please install 'flake8'."); +} + +QStringList KateProjectCodeAnalysisToolFlake8::parseLine(const QString &line) +{ + return line.split(QRegExp(QStringLiteral("////")), QString::SkipEmptyParts); +} + +QString KateProjectCodeAnalysisToolFlake8::stdinMessages() +{ + return QString(); +} diff --git a/addons/project/tools/kateprojectcodeanalysistoolflake8.h b/addons/project/tools/kateprojectcodeanalysistoolflake8.h new file mode 100644 index 000000000..7ccec53cb --- /dev/null +++ b/addons/project/tools/kateprojectcodeanalysistoolflake8.h @@ -0,0 +1,51 @@ +/* This file is part of the Kate project. + * + * Copyright (C) 2017 Héctor Mesa Jiménez + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KATE_PROJECT_CODE_ANALYSIS_TOOL_FLAKE8_H +#define KATE_PROJECT_CODE_ANALYSIS_TOOL_FLAKE8_H + +#include "../kateprojectcodeanalysistool.h" + +/** + * Information provider for flake8 + */ +class KateProjectCodeAnalysisToolFlake8: public KateProjectCodeAnalysisTool +{ +public: + explicit KateProjectCodeAnalysisToolFlake8(QObject *parent = nullptr); + + virtual ~KateProjectCodeAnalysisToolFlake8() override; + + virtual QString name() override; + + virtual QStringList filter(const QStringList &files) override; + + virtual QString path() override; + + virtual QStringList arguments() override; + + virtual QString notInstalledMessage() override; + + virtual QStringList parseLine(const QString &line) override; + + virtual QString stdinMessages() override; +}; + +#endif // KATE_PROJECT_CODE_ANALYSIS_TOOL_FLAKE8_H