diff --git a/.clang-tidy b/.clang-tidy --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,5 @@ --- -Checks: 'clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*,cert-dcl03-c,cert-dcl50-cpp,cert-dcl54-cpp,cert-dcl59-cpp,cert-err52-cpp,cert-err58-cpp,cert-err60-cpp,cert-err61-cpp,cert-fio38-c,cert-oop11-cpp,clang-analyzer-core.CallAndMessage,clang-analyzer-core.DivideZero,clang-analyzer-core.DynamicTypePropagation,clang-analyzer-core.NonNullParamChecker,clang-analyzer-core.NullDereference,clang-analyzer-core.StackAddressEscape,clang-analyzer-core.UndefinedBinaryOperatorResult,clang-analyzer-core.VLASize,clang-analyzer-core.builtin.BuiltinFunctions,clang-analyzer-core.builtin.NoReturnFunctions,clang-analyzer-core.uninitialized.ArraySubscript,clang-analyzer-core.uninitialized.Assign,clang-analyzer-core.uninitialized.Branch,clang-analyzer-core.uninitialized.CapturedBlockVariable,clang-analyzer-core.uninitialized.UndefReturn,clang-analyzer-cplusplus.NewDelete,clang-analyzer-cplusplus.NewDeleteLeaks,clang-analyzer-deadcode.DeadStores,clang-analyzer-security.FloatLoopCounter,clang-analyzer-security.insecureAPI.UncheckedReturn,clang-analyzer-security.insecureAPI.getpw,clang-analyzer-security.insecureAPI.gets,clang-analyzer-security.insecureAPI.mkstemp,clang-analyzer-security.insecureAPI.mktemp,clang-analyzer-security.insecureAPI.rand,clang-analyzer-security.insecureAPI.strcpy,clang-analyzer-security.insecureAPI.vfork,cppcoreguidelines-c-copy-assignment-signature,cppcoreguidelines-pro-bounds-array-to-pointer-decay,cppcoreguidelines-pro-bounds-constant-array-index,cppcoreguidelines-pro-bounds-pointer-arithmetic,cppcoreguidelines-pro-type-const-cast,cppcoreguidelines-pro-type-cstyle-cast,cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-type-static-cast-downcast,cppcoreguidelines-pro-type-union-access,cppcoreguidelines-pro-type-vararg,misc-definitions-in-headers,misc-inaccurate-erase,misc-inefficient-algorithm,misc-macro-parentheses,misc-macro-repeated-side-effects,misc-move-const-arg,misc-move-constructor-init,misc-new-delete-overloads,misc-noexcept-move-constructor,misc-non-copyable-objects,misc-sizeof-container,misc-static-assert,misc-string-integer-assignment,misc-swapped-arguments,misc-throw-by-value-catch-by-reference,misc-undelegated-constructor,misc-uniqueptr-reset-release,misc-unused-alias-decls,misc-unused-parameters,misc-unused-raii,misc-virtual-near-miss,modernize-loop-convert,modernize-make-unique,modernize-pass-by-value,modernize-redundant-void-arg,modernize-replace-auto-ptr,modernize-shrink-to-fit,modernize-use-auto,modernize-use-default,modernize-use-nullptr,modernize-use-override,performance-unnecessary-copy-initialization,readability-braces-around-statements,readability-container-size-empty,readability-else-after-return,readability-function-size,readability-identifier-naming,readability-implicit-bool-cast,readability-inconsistent-declaration-parameter-name,readability-named-parameter,readability-redundant-smartptr-get,readability-redundant-string-cstr,readability-simplify-boolean-expr,readability-uniqueptr-delete-release' +Checks: 'clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*,clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*,clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*,cert-dcl03-c,cert-dcl50-cpp,cert-dcl54-cpp,cert-dcl59-cpp,cert-err52-cpp,cert-err58-cpp,cert-err60-cpp,cert-err61-cpp,cert-fio38-c,cert-oop11-cpp,clang-analyzer-core.CallAndMessage,clang-analyzer-core.DivideZero,clang-analyzer-core.DynamicTypePropagation,clang-analyzer-core.NonNullParamChecker,clang-analyzer-core.NullDereference,clang-analyzer-core.StackAddressEscape,clang-analyzer-core.UndefinedBinaryOperatorResult,clang-analyzer-core.VLASize,clang-analyzer-core.builtin.BuiltinFunctions,clang-analyzer-core.builtin.NoReturnFunctions,clang-analyzer-core.uninitialized.ArraySubscript,clang-analyzer-core.uninitialized.Assign,clang-analyzer-core.uninitialized.Branch,clang-analyzer-core.uninitialized.CapturedBlockVariable,clang-analyzer-core.uninitialized.UndefReturn,clang-analyzer-cplusplus.NewDelete,clang-analyzer-cplusplus.NewDeleteLeaks,clang-analyzer-deadcode.DeadStores,clang-analyzer-security.FloatLoopCounter,clang-analyzer-security.insecureAPI.UncheckedReturn,clang-analyzer-security.insecureAPI.getpw,clang-analyzer-security.insecureAPI.gets,clang-analyzer-security.insecureAPI.mkstemp,clang-analyzer-security.insecureAPI.mktemp,clang-analyzer-security.insecureAPI.rand,clang-analyzer-security.insecureAPI.strcpy,clang-analyzer-security.insecureAPI.vfork,cppcoreguidelines-c-copy-assignment-signature,cppcoreguidelines-pro-bounds-array-to-pointer-decay,cppcoreguidelines-pro-bounds-constant-array-index,cppcoreguidelines-pro-bounds-pointer-arithmetic,cppcoreguidelines-pro-type-const-cast,cppcoreguidelines-pro-type-cstyle-cast,cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-type-static-cast-downcast,cppcoreguidelines-pro-type-union-access,cppcoreguidelines-pro-type-vararg,misc-definitions-in-headers,misc-inaccurate-erase,misc-inefficient-algorithm,misc-macro-parentheses,misc-macro-repeated-side-effects,misc-move-const-arg,misc-move-constructor-init,misc-new-delete-overloads,misc-noexcept-move-constructor,misc-non-copyable-objects,misc-sizeof-container,misc-static-assert,misc-string-integer-assignment,misc-swapped-arguments,misc-throw-by-value-catch-by-reference,misc-undelegated-constructor,misc-uniqueptr-reset-release,misc-unused-alias-decls,misc-unused-parameters,misc-unused-raii,misc-virtual-near-miss,modernize-loop-convert,modernize-make-unique,modernize-pass-by-value,modernize-redundant-void-arg,modernize-replace-auto-ptr,modernize-shrink-to-fit,modernize-use-auto,modernize-use-default,modernize-use-nullptr,modernize-use-override,performance-unnecessary-copy-initialization,readability-braces-around-statements,readability-container-size-empty,readability-else-after-return,readability-function-size,readability-identifier-naming,readability-implicit-bool-cast,readability-inconsistent-declaration-parameter-name,readability-named-parameter,readability-redundant-smartptr-get,readability-redundant-string-cstr,readability-simplify-boolean-expr,readability-uniqueptr-delete-release,,readability-identifier-naming,,readability-identifier-naming' HeaderFilterRegex: '' AnalyzeTemporaryDtors: false User: cnihelton @@ -47,27 +47,27 @@ - key: readability-function-size.StatementThreshold value: '800' - key: readability-identifier-naming.AbstractClassCase - value: aNy_CasE + value: CamelCase - key: readability-identifier-naming.AbstractClassPrefix - value: '' + value: 'I' - key: readability-identifier-naming.AbstractClassSuffix value: '' - key: readability-identifier-naming.ClassCase - value: aNy_CasE + value: CamelCase - key: readability-identifier-naming.ClassConstantCase - value: aNy_CasE + value: CamelCase - key: readability-identifier-naming.ClassConstantPrefix value: '' - key: readability-identifier-naming.ClassConstantSuffix value: '' - key: readability-identifier-naming.ClassMemberCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.ClassMemberPrefix value: '' - key: readability-identifier-naming.ClassMemberSuffix value: '' - key: readability-identifier-naming.ClassMethodCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.ClassMethodPrefix value: '' - key: readability-identifier-naming.ClassMethodSuffix @@ -77,15 +77,15 @@ - key: readability-identifier-naming.ClassSuffix value: '' - key: readability-identifier-naming.ConstantCase - value: aNy_CasE + value: CamelCase - key: readability-identifier-naming.ConstantMemberCase - value: aNy_CasE + value: CamelCase - key: readability-identifier-naming.ConstantMemberPrefix value: '' - key: readability-identifier-naming.ConstantMemberSuffix value: '' - key: readability-identifier-naming.ConstantParameterCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.ConstantParameterPrefix value: '' - key: readability-identifier-naming.ConstantParameterSuffix @@ -95,27 +95,27 @@ - key: readability-identifier-naming.ConstantSuffix value: '' - key: readability-identifier-naming.ConstexprFunctionCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.ConstexprFunctionPrefix value: '' - key: readability-identifier-naming.ConstexprFunctionSuffix value: '' - key: readability-identifier-naming.ConstexprMethodCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.ConstexprMethodPrefix value: '' - key: readability-identifier-naming.ConstexprMethodSuffix value: '' - key: readability-identifier-naming.ConstexprVariableCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.ConstexprVariablePrefix value: '' - key: readability-identifier-naming.ConstexprVariableSuffix value: '' - key: readability-identifier-naming.EnumCase - value: aNy_CasE + value: CamelCase - key: readability-identifier-naming.EnumConstantCase - value: aNy_CasE + value: CamelCase - key: readability-identifier-naming.EnumConstantPrefix value: '' - key: readability-identifier-naming.EnumConstantSuffix @@ -125,25 +125,25 @@ - key: readability-identifier-naming.EnumSuffix value: '' - key: readability-identifier-naming.FunctionCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.FunctionPrefix value: '' - key: readability-identifier-naming.FunctionSuffix value: '' - key: readability-identifier-naming.GlobalConstantCase - value: aNy_CasE + value: UPPER_CASE - key: readability-identifier-naming.GlobalConstantPrefix value: '' - key: readability-identifier-naming.GlobalConstantSuffix value: '' - key: readability-identifier-naming.GlobalFunctionCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.GlobalFunctionPrefix value: '' - key: readability-identifier-naming.GlobalFunctionSuffix value: '' - key: readability-identifier-naming.GlobalVariableCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.GlobalVariablePrefix value: '' - key: readability-identifier-naming.GlobalVariableSuffix @@ -151,45 +151,45 @@ - key: readability-identifier-naming.IgnoreFailedSplit value: '0' - key: readability-identifier-naming.InlineNamespaceCase - value: aNy_CasE + value: CamelCase - key: readability-identifier-naming.InlineNamespacePrefix value: '' - key: readability-identifier-naming.InlineNamespaceSuffix value: '' - key: readability-identifier-naming.LocalConstantCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.LocalConstantPrefix value: '' - key: readability-identifier-naming.LocalConstantSuffix value: '' - key: readability-identifier-naming.LocalVariableCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.LocalVariablePrefix value: '' - key: readability-identifier-naming.LocalVariableSuffix value: '' - key: readability-identifier-naming.MemberCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.MemberPrefix - value: '' + value: 'm_' - key: readability-identifier-naming.MemberSuffix value: '' - key: readability-identifier-naming.MethodCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.MethodPrefix value: '' - key: readability-identifier-naming.MethodSuffix value: '' - key: readability-identifier-naming.NamespaceCase - value: aNy_CasE + value: CamelCase - key: readability-identifier-naming.NamespacePrefix value: '' - key: readability-identifier-naming.NamespaceSuffix value: '' - key: readability-identifier-naming.ParameterCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.ParameterPackCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.ParameterPackPrefix value: '' - key: readability-identifier-naming.ParameterPackSuffix @@ -199,103 +199,103 @@ - key: readability-identifier-naming.ParameterSuffix value: '' - key: readability-identifier-naming.PrivateMemberCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.PrivateMemberPrefix - value: '' + value: 'm_' - key: readability-identifier-naming.PrivateMemberSuffix value: '' - key: readability-identifier-naming.PrivateMethodCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.PrivateMethodPrefix value: '' - key: readability-identifier-naming.PrivateMethodSuffix value: '' - key: readability-identifier-naming.ProtectedMemberCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.ProtectedMemberPrefix - value: '' + value: 'm_' - key: readability-identifier-naming.ProtectedMemberSuffix value: '' - key: readability-identifier-naming.ProtectedMethodCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.ProtectedMethodPrefix value: '' - key: readability-identifier-naming.ProtectedMethodSuffix value: '' - key: readability-identifier-naming.PublicMemberCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.PublicMemberPrefix value: '' - key: readability-identifier-naming.PublicMemberSuffix value: '' - key: readability-identifier-naming.PublicMethodCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.PublicMethodPrefix value: '' - key: readability-identifier-naming.PublicMethodSuffix value: '' - key: readability-identifier-naming.StaticConstantCase - value: aNy_CasE + value: CamelCase - key: readability-identifier-naming.StaticConstantPrefix value: '' - key: readability-identifier-naming.StaticConstantSuffix value: '' - key: readability-identifier-naming.StaticVariableCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.StaticVariablePrefix value: '' - key: readability-identifier-naming.StaticVariableSuffix value: '' - key: readability-identifier-naming.StructCase - value: aNy_CasE + value: CamelCase - key: readability-identifier-naming.StructPrefix value: '' - key: readability-identifier-naming.StructSuffix value: '' - key: readability-identifier-naming.TemplateParameterCase - value: aNy_CasE + value: CamelCase - key: readability-identifier-naming.TemplateParameterPrefix value: '' - key: readability-identifier-naming.TemplateParameterSuffix value: '' - key: readability-identifier-naming.TemplateTemplateParameterCase - value: aNy_CasE + value: CamelCase - key: readability-identifier-naming.TemplateTemplateParameterPrefix value: '' - key: readability-identifier-naming.TemplateTemplateParameterSuffix value: '' - key: readability-identifier-naming.TypeTemplateParameterCase - value: aNy_CasE + value: CamelCase - key: readability-identifier-naming.TypeTemplateParameterPrefix value: '' - key: readability-identifier-naming.TypeTemplateParameterSuffix value: '' - key: readability-identifier-naming.TypedefCase - value: aNy_CasE + value: CamelCase - key: readability-identifier-naming.TypedefPrefix value: '' - key: readability-identifier-naming.TypedefSuffix value: '' - key: readability-identifier-naming.UnionCase - value: aNy_CasE + value: CamelCase - key: readability-identifier-naming.UnionPrefix value: '' - key: readability-identifier-naming.UnionSuffix value: '' - key: readability-identifier-naming.ValueTemplateParameterCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.ValueTemplateParameterPrefix value: '' - key: readability-identifier-naming.ValueTemplateParameterSuffix value: '' - key: readability-identifier-naming.VariableCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.VariablePrefix value: '' - key: readability-identifier-naming.VariableSuffix value: '' - key: readability-identifier-naming.VirtualMethodCase - value: aNy_CasE + value: camelBack - key: readability-identifier-naming.VirtualMethodPrefix value: '' - key: readability-identifier-naming.VirtualMethodSuffix diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,11 @@ .kdev4 +.vscode *kdev4 .vscode *~ .*~ build *.yaml +*~ +.*~ !tests/data/* diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,8 +25,8 @@ if(NOT CLANG_TIDY_EXEC) message(ERROR "clang-tidy program not found") else() - configure_file("${PROJECT_SOURCE_DIR}/src/plugin/plugin.h.in" - "${PROJECT_SOURCE_DIR}/src/plugin/plugin.h" ) + configure_file("${PROJECT_SOURCE_DIR}/src/config/configgroup.h.in" + "${PROJECT_SOURCE_DIR}/src/config/configgroup.h" ) configure_file("${PROJECT_SOURCE_DIR}/res/clangtidyconfig.kcfg.in" "${PROJECT_SOURCE_DIR}/res/clangtidyconfig.kcfg" ) diff --git a/cmake/ClangFormatAll.cmake b/cmake/ClangFormatAll.cmake --- a/cmake/ClangFormatAll.cmake +++ b/cmake/ClangFormatAll.cmake @@ -10,7 +10,7 @@ NAMES "clang-format" ) if(NOT CLANG_FMT_CMD) - message(ERROR "clang-format not found!") + message(WARNING "clang-format not found!") else() add_custom_target( ClangFormatAll COMMAND ${CLANG_FMT_CMD} -style=file -i ${ALL_SOURCE_FILES} diff --git a/src/config/clangtidypreferences.h b/src/config/clangtidypreferences.h --- a/src/config/clangtidypreferences.h +++ b/src/config/clangtidypreferences.h @@ -26,18 +26,18 @@ namespace Ui { -class ClangtidySettings; +class ClangTidySettings; }; /** * \class * \brief Implements the session configuration page for clang-tidy. */ -class ClangtidyPreferences : public KDevelop::ConfigPage +class ClangTidyPreferences : public KDevelop::ConfigPage { Q_OBJECT public: - explicit ClangtidyPreferences(KDevelop::IPlugin* plugin = nullptr, QWidget* parent = nullptr); - ~ClangtidyPreferences() override; + explicit ClangTidyPreferences(KDevelop::IPlugin* plugin = nullptr, QWidget* parent = nullptr); + ~ClangTidyPreferences() override; ConfigPage::ConfigPageType configPageType() const override; QString name() const override; QString fullName() const override; @@ -47,7 +47,7 @@ void apply() override; private: - Ui::ClangtidySettings* ui; + Ui::ClangTidySettings* ui; }; #endif diff --git a/src/config/clangtidypreferences.cpp b/src/config/clangtidypreferences.cpp --- a/src/config/clangtidypreferences.cpp +++ b/src/config/clangtidypreferences.cpp @@ -30,43 +30,43 @@ using ClangTidy::ConfigGroup; using KDevelop::ConfigPage; -ClangtidyPreferences::ClangtidyPreferences(IPlugin* plugin, QWidget* parent) +ClangTidyPreferences::ClangTidyPreferences(IPlugin* plugin, QWidget* parent) : ConfigPage(plugin, ClangtidySettings::self(), parent) { - QVBoxLayout* layout = new QVBoxLayout(this); - QWidget* widget = new QWidget(this); - ui = new Ui::ClangtidySettings(); + auto layout = new QVBoxLayout(this); + auto widget = new QWidget(this); + ui = new Ui::ClangTidySettings(); ui->setupUi(widget); layout->addWidget(widget); } -ClangtidyPreferences::~ClangtidyPreferences() +ClangTidyPreferences::~ClangTidyPreferences() { delete ui; } -ConfigPage::ConfigPageType ClangtidyPreferences::configPageType() const +ConfigPage::ConfigPageType ClangTidyPreferences::configPageType() const { return ConfigPage::AnalyzerConfigPage; } -QString ClangtidyPreferences::name() const +QString ClangTidyPreferences::name() const { return i18n("clang-tidy"); } -QString ClangtidyPreferences::fullName() const +QString ClangTidyPreferences::fullName() const { return i18n("Configure clang-tidy settings"); } -QIcon ClangtidyPreferences::icon() const +QIcon ClangTidyPreferences::icon() const { return QIcon::fromTheme(QStringLiteral("dialog-ok")); } -void ClangtidyPreferences::apply() +void ClangTidyPreferences::apply() { - ConfigGroup projConf = KSharedConfig::openConfig()->group("Clangtidy"); - projConf.writeEntry(ConfigGroup::ExecutablePath, ui->kcfg_clangtidyPath->text()); + ConfigGroup projConf = KSharedConfig::openConfig()->group("ClangTidy"); + projConf.writeEntry(ConfigGroup::ExecutablePath, ui->kcfgClangTidyPath->text()); } diff --git a/src/config/configgroup.h b/src/config/configgroup.h --- a/src/config/configgroup.h +++ b/src/config/configgroup.h @@ -26,13 +26,14 @@ #include #include +#define CLANG_TIDY_PATH "/usr/bin/clang-tidy" + namespace ClangTidy { /** * \class * \brief Specializes KConfigGroup for clang-tidy, using a type system to avoid - * configuration control by passing - * strings around. + * configuration control by passing strings around. */ class ConfigGroup { @@ -75,7 +76,7 @@ static const Option LineFilter; static const Option ListChecks; static const Option CheckSystemHeaders; - static const OptionArray m_allOptions; + static const OptionArray AllOptions; QString readEntry(const Option& key) const { return m_group.readEntry(key.first); } diff --git a/src/config/configgroup.h.in b/src/config/configgroup.h.in new file mode 100644 --- /dev/null +++ b/src/config/configgroup.h.in @@ -0,0 +1,101 @@ +/* + * This file is part of KDevelop + * + * Copyright 2016 Carlos Nihelton + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef CLANGTIDY_CONFIG_H +#define CLANGTIDY_CONFIG_H + +#include +#include +#include + +#define CLANG_TIDY_PATH "@CLANG_TIDY_EXEC@" + +namespace ClangTidy +{ +/** + * \class + * \brief Specializes KConfigGroup for clang-tidy, using a type system to avoid + * configuration control by passing strings around. + */ +class ConfigGroup +{ + //\typedef Typedef for pair of QStrings. + using Option = std::pair; + ///\typedef definition of an array of options. + using OptionArray = std::array; + +private: + KConfigGroup m_group; + +public: + ConfigGroup() = default; + ConfigGroup(const KConfigGroup& cg) { m_group = cg; } + ~ConfigGroup() = default; + ConfigGroup& operator=(const KConfigGroup& cg) + { + this->m_group = cg; + return *this; + } + bool isValid() { return m_group.isValid(); } + /// This technique allows us to avoid passing strings to KConfigGroup member + /// functions, thus allowing compile time + /// detection of wrong parameters. + static const Option ExecutablePath; + static const Option FilePath; + static const Option BuildPath; + static const Option AdditionalParameters; + static const Option AnaliseTempDtors; + static const Option EnabledChecks; + static const Option UseConfigFile; + static const Option DumpConfig; + static const Option EnableChecksProfile; + static const Option ExportFixes; + static const Option ExtraArgs; + static const Option ExtraArgsBefore; + static const Option AutoFix; + static const Option AutoFixError; + static const Option HeaderFilter; + static const Option LineFilter; + static const Option ListChecks; + static const Option CheckSystemHeaders; + static const OptionArray AllOptions; + + QString readEntry(const Option& key) const { return m_group.readEntry(key.first); } + + template + void writeEntry(const Option& key, const T& value, KConfig::WriteConfigFlags pFlags = KConfig::Normal) + { + m_group.writeEntry(key.first, key.second.arg(value), pFlags); + } + + void deleteEntry(const Option& key, KConfig::WriteConfigFlags pFlags = KConfig::Normal) + { + m_group.deleteEntry(key.first, pFlags); + } + + void enableEntry(const Option& key, bool enable) + { + enable ? writeEntry(key, QStringLiteral("")) : deleteEntry(key); + } +}; +} + +#endif // CLANGTIDY_CONFIG_H diff --git a/src/config/configgroup.cpp b/src/config/configgroup.cpp --- a/src/config/configgroup.cpp +++ b/src/config/configgroup.cpp @@ -41,7 +41,7 @@ const ConfigGroup::Option ConfigGroup::LineFilter{ { "LineFilter" }, { "--line-filter=%1" } }; const ConfigGroup::Option ConfigGroup::ListChecks{ { "ListChecks" }, { "--list-checks" } }; const ConfigGroup::Option ConfigGroup::CheckSystemHeaders{ { "CheckSystemHeaders" }, { "--system-headers" } }; -const ConfigGroup::OptionArray ConfigGroup::m_allOptions{ +const ConfigGroup::OptionArray ConfigGroup::AllOptions{ { &ConfigGroup::ExecutablePath, &ConfigGroup::FilePath, &ConfigGroup::BuildPath, &ConfigGroup::AdditionalParameters, &ConfigGroup::AnaliseTempDtors, &ConfigGroup::EnabledChecks, &ConfigGroup::UseConfigFile, &ConfigGroup::DumpConfig, &ConfigGroup::EnableChecksProfile, &ConfigGroup::ExportFixes, &ConfigGroup::ExtraArgs, diff --git a/src/config/perprojectconfigpage.h b/src/config/perprojectconfigpage.h --- a/src/config/perprojectconfigpage.h +++ b/src/config/perprojectconfigpage.h @@ -28,6 +28,7 @@ #include #include "config/configgroup.h" +#include "ui_perprojectconfig.h" class QIcon; class QStringListModel; @@ -56,15 +57,15 @@ public: PerProjectConfigPage(KDevelop::IProject* project, QWidget* parent); - ~PerProjectConfigPage() override; + ~PerProjectConfigPage() = default; ConfigPageType configPageType() const override; QString name() const override; QIcon icon() const override; - void setList(QStringList list); - void setActiveChecksReceptorList(QStringList* list); + void setList(const QStringList& list); signals: + void selectedChecksChanged(const QStringList& selectedChecks); public slots: void apply() override; @@ -72,10 +73,9 @@ void reset() override; private: - KDevelop::IProject* m_project; - Ui::PerProjectConfig* ui; + QScopedPointer ui; ConfigGroup m_config; - QStringList* m_activeChecksReceptor; + QStringList m_selectedChecks; QStringList m_underlineAvailChecks; QStringListModel* m_availableChecksModel; QItemSelectionModel* m_selectedItemModel; diff --git a/src/config/perprojectconfigpage.cpp b/src/config/perprojectconfigpage.cpp --- a/src/config/perprojectconfigpage.cpp +++ b/src/config/perprojectconfigpage.cpp @@ -20,7 +20,6 @@ */ #include "config/perprojectconfigpage.h" -#include "ui_perprojectconfig.h" #include #include @@ -30,9 +29,8 @@ PerProjectConfigPage::PerProjectConfigPage(KDevelop::IProject* project, QWidget* parent) : KDevelop::ConfigPage(nullptr, nullptr, parent) - , m_project(project) + , ui(new Ui::PerProjectConfig()) { - ui = new Ui::PerProjectConfig(); ui->setupUi(this); m_availableChecksModel = new QStringListModel(); @@ -41,17 +39,12 @@ m_selectedItemModel = new QItemSelectionModel(m_availableChecksModel); ui->checkListView->setSelectionModel(m_selectedItemModel); - m_config = m_project->projectConfiguration()->group("Clangtidy"); -} - -PerProjectConfigPage::~PerProjectConfigPage(void) -{ - delete ui; + m_config = project->projectConfiguration()->group("ClangTidy"); } QIcon PerProjectConfigPage::icon() const { - return QIcon::fromTheme(QStringLiteral("dialog-ok")); + return QIcon::fromTheme(QStringLiteral("emblem-checked")); } KDevelop::ConfigPage::ConfigPageType PerProjectConfigPage::configPageType() const @@ -64,21 +57,16 @@ return i18n("clang-tidy"); } -void PerProjectConfigPage::setActiveChecksReceptorList(QStringList* list) +void PerProjectConfigPage::setList(const QStringList& list) { - m_activeChecksReceptor = list; - *m_activeChecksReceptor = m_config.readEntry(ConfigGroup::EnabledChecks).split(','); -} -void PerProjectConfigPage::setList(QStringList list) -{ m_underlineAvailChecks = list; m_availableChecksModel->setStringList(m_underlineAvailChecks); for (int i = 0; i < m_availableChecksModel->rowCount(); ++i) { QModelIndex index = m_availableChecksModel->index(i, 0); if (index.isValid()) { - if (m_activeChecksReceptor->contains((index.data().toString()))) { + if (m_selectedChecks.contains((index.data().toString()))) { m_selectedItemModel->select(index, QItemSelectionModel::Select); } else { m_selectedItemModel->select(index, QItemSelectionModel::Deselect); @@ -89,11 +77,10 @@ void PerProjectConfigPage::apply() { - // TODO: discover a way to set the project folders where user header files - // might exist into this option. - // Right now it only works with manual entry. + // TODO (coliveira): discover a way to set the project folders where user header files + // might exist into this option. Right now it only works with manual entry. m_config.writeEntry(ConfigGroup::HeaderFilter, ui->headerFilterText->text()); - m_config.writeEntry(ConfigGroup::AdditionalParameters, ui->clangtidyParameters->text()); + m_config.writeEntry(ConfigGroup::AdditionalParameters, ui->clangTidyParameters->text()); m_config.enableEntry(ConfigGroup::CheckSystemHeaders, ui->sysHeadersCheckBox->isChecked()); m_config.enableEntry(ConfigGroup::UseConfigFile, !ui->overrideConfigFileCheckBox->isChecked()); m_config.enableEntry(ConfigGroup::DumpConfig, ui->dumpCheckBox->isChecked()); @@ -104,14 +91,18 @@ bool isSelected = m_selectedItemModel->isSelected(index); auto check = index.data().toString(); if (isSelected) { - *m_activeChecksReceptor << check; + m_selectedChecks << check; } else { - m_activeChecksReceptor->removeAll(check); + m_selectedChecks.removeAll(check); } } } - m_activeChecksReceptor->removeDuplicates(); - m_config.writeEntry(ConfigGroup::EnabledChecks, m_activeChecksReceptor->join(',')); + m_selectedChecks.removeDuplicates(); + if (m_selectedChecks.at(0).isEmpty()) { + m_selectedChecks.removeFirst(); + } + m_config.writeEntry(ConfigGroup::EnabledChecks, m_selectedChecks.join(',')); + emit selectedChecksChanged(m_selectedChecks); } void PerProjectConfigPage::defaults() @@ -119,16 +110,15 @@ bool wasBlocked = signalsBlocked(); blockSignals(true); - // TODO: discover a way to set the project folders where user header files - // might exist into this option. - // Right now it only works with manual entry. - m_config.writeEntry(ConfigGroup::ExecutablePath, "/usr/bin/clang-tidy"); + m_config.writeEntry(ConfigGroup::ExecutablePath, CLANG_TIDY_PATH); + // TODO: discover a way to set the project folders where user header files + // might exist into this option. Right now it only works with manual entry. m_config.writeEntry(ConfigGroup::HeaderFilter, ""); ui->headerFilterText->setText(""); m_config.writeEntry(ConfigGroup::AdditionalParameters, ""); - ui->clangtidyParameters->setText(QString("")); + ui->clangTidyParameters->setText(QString("")); m_config.writeEntry(ConfigGroup::CheckSystemHeaders, ""); ui->sysHeadersCheckBox->setChecked(false); @@ -152,14 +142,14 @@ || check.contains("-deadcode") || check.contains("-security") || check.contains("cppcoreguide"); m_selectedItemModel->select(index, enable ? QItemSelectionModel::Select : QItemSelectionModel::Deselect); if (enable) { - *m_activeChecksReceptor << check; + m_selectedChecks << check; } else { - m_activeChecksReceptor->removeAll(check); + m_selectedChecks.removeAll(check); } } } - m_activeChecksReceptor->removeDuplicates(); - m_config.writeEntry(ConfigGroup::EnabledChecks, m_activeChecksReceptor->join(',')); + m_selectedChecks.removeDuplicates(); + m_config.writeEntry(ConfigGroup::EnabledChecks, m_selectedChecks.join(',')); blockSignals(wasBlocked); } @@ -169,7 +159,7 @@ return; } ui->headerFilterText->setText(m_config.readEntry(ConfigGroup::HeaderFilter).remove("--header-filter=")); - ui->clangtidyParameters->setText(m_config.readEntry(ConfigGroup::AdditionalParameters)); + ui->clangTidyParameters->setText(m_config.readEntry(ConfigGroup::AdditionalParameters)); ui->sysHeadersCheckBox->setChecked(!m_config.readEntry(ConfigGroup::CheckSystemHeaders).isEmpty()); ui->overrideConfigFileCheckBox->setChecked(m_config.readEntry(ConfigGroup::UseConfigFile).isEmpty()); ui->checkListGroupBox->setEnabled(m_config.readEntry(ConfigGroup::UseConfigFile).isEmpty()); diff --git a/src/config/ui/clangtidysettings.ui b/src/config/ui/clangtidysettings.ui --- a/src/config/ui/clangtidysettings.ui +++ b/src/config/ui/clangtidysettings.ui @@ -1,7 +1,7 @@ - ClangtidySettings - + ClangTidySettings + 0 @@ -23,7 +23,7 @@ - + clang-tidy executable @@ -31,7 +31,7 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - kcfg_clangtidyPath + kcfgClangTidyPath @@ -40,7 +40,7 @@ - + diff --git a/src/config/ui/perprojectconfig.ui b/src/config/ui/perprojectconfig.ui --- a/src/config/ui/perprojectconfig.ui +++ b/src/config/ui/perprojectconfig.ui @@ -44,7 +44,7 @@ - + <html><head/><body><p>Additional command line options to pass to clang-tidy.</p></body></html> @@ -56,7 +56,7 @@ Extra &Parameters: - clangtidyParameters + clangTidyParameters diff --git a/src/parsers/clangtidyparser.h b/src/parsers/clangtidyparser.h --- a/src/parsers/clangtidyparser.h +++ b/src/parsers/clangtidyparser.h @@ -31,11 +31,11 @@ * \class * \brief Implements a parser for clang-tidy's standard output. */ -class ClangtidyParser : public QObject +class ClangTidyParser : public QObject { public: - explicit ClangtidyParser(QObject* parent = nullptr); - ~ClangtidyParser() = default; + explicit ClangTidyParser(QObject* parent = nullptr); + ~ClangTidyParser() = default; /** * \return all problems collected from clang-tidy stdout. */ diff --git a/src/parsers/clangtidyparser.cpp b/src/parsers/clangtidyparser.cpp --- a/src/parsers/clangtidyparser.cpp +++ b/src/parsers/clangtidyparser.cpp @@ -33,44 +33,15 @@ using KDevelop::DetectedProblem; using KDevelop::DocumentRange; using KDevelop::IndexedString; -/** - * Convert the value of attribute of element from clangtidy's - * XML-output to 'good-looking' HTML-version. This is necessary because the - * displaying of the original message is performed without line breaks - such - * tooltips are uncomfortable to read, and large messages will not fit into the - * screen. - * - * This function put the original message into tag that automatically - * provides line wrapping by builtin capabilities of Qt library. The source text - * also can contain tokens '\012' (line break) - they are present in the case of - * source code examples. In such cases, the entire text between the first and - * last tokens (i.e. source code) is placed into
 tag.
- *
- * @param[in] input the original value of  attribute
- * @return HTML version for displaying in problem's tooltip
- */
-QString verboseMessageToHtml(const QString& input)
-{
-    QString output(QString("%1").arg(input.toHtmlEscaped()));
-
-    output.replace("\\012", "\n");
-
-    if (output.count('\n') >= 2) {
-        output.replace(output.indexOf('\n'), 1, "
");
-        output.replace(output.lastIndexOf('\n'), 1, "

"); - } - - return output; -} -ClangtidyParser::ClangtidyParser(QObject* parent) +ClangTidyParser::ClangTidyParser(QObject* parent) : QObject(parent) { } -void ClangtidyParser::parse() +void ClangTidyParser::parse() { - QRegularExpression regex(QStringLiteral("(\\/.+\\.cpp):(\\d+):(\\d+): (.+): (.+) (\\[.+\\])")); + QRegularExpression regex(QStringLiteral("(\\/.+\\.[ch]{1,2}[px]{0,2}):(\\d+):(\\d+): (.+): (.+) (\\[.+\\])")); for (auto line : m_stdout) { auto smatch = regex.match(line); @@ -104,8 +75,9 @@ auto problem = m_problems.last(); line.prepend(problem->explanation() + '\n'); problem->setExplanation(line); - } else + } else { continue; + } } } } // namespace ClangTidy diff --git a/src/parsers/replacementparser.h b/src/parsers/replacementparser.h --- a/src/parsers/replacementparser.h +++ b/src/parsers/replacementparser.h @@ -53,25 +53,25 @@ class ReplacementParser { private: - size_t currentLine; ///< current line on source code while parsing. - size_t currentColumn; ///< current column on source code while parsing. - size_t currentOffset; ///< current offset in bytes since the beginning of the source code while parsing. - size_t cReplacements; ///< current count of replacements parsed. + size_t m_currentLine; ///< current line on source code while parsing. + size_t m_currentColumn; ///< current column on source code while parsing. + size_t m_currentOffset; ///< current offset in bytes since the beginning of the source code while parsing. + size_t m_countOfReplacements; ///< current count of replacements parsed. - QString m_yamlname; + QString m_yamlName; QString m_sourceFile; - IndexedString i_source; + IndexedString m_iSource; QString m_yamlContent; std::string m_sourceCode; boost::string_ref m_sourceView; - static const QRegularExpression regex, check; - Replacements all_replacements; + static const QRegularExpression Regex, Check; + Replacements m_allReplacements; protected: /** * \function * \brief generates the next replacement from the regex capture list. - * \param smatch: the captured match. + * \param smatch the captured match. * \return Replacement */ Replacement nextNode(const QRegularExpressionMatch& smatch); @@ -86,10 +86,10 @@ public: ReplacementParser() = default; - explicit ReplacementParser(const QString& yaml_file, const QString& source_file); + explicit ReplacementParser(const QString& yamlFileName, const QString& sourceFileName); void parse(); - size_t count() const { return cReplacements; } - Replacements allReplacements() { return all_replacements; } + size_t count() const { return m_countOfReplacements; } + Replacements allReplacements() { return m_allReplacements; } }; } diff --git a/src/parsers/replacementparser.cpp b/src/parsers/replacementparser.cpp --- a/src/parsers/replacementparser.cpp +++ b/src/parsers/replacementparser.cpp @@ -70,36 +70,36 @@ namespace ClangTidy { -const QRegularExpression ReplacementParser::check{ QStringLiteral( +const QRegularExpression ReplacementParser::Check{ QStringLiteral( "---\\s+MainSourceFile:\\s+.+\\s+Replacements:(\\s+.+)+\\s\\.\\.\\.") }; -const QRegularExpression ReplacementParser::regex{ ( +const QRegularExpression ReplacementParser::Regex{ ( QStringLiteral("\\s+\\s+-\\s+FilePath:\\s+(.+\\.cpp)\\s+Offset:\\s+(\\d+)\\s+Length:\\s+" "(\\d+)\\s+ ReplacementText:\\s(.+)")) }; -ReplacementParser::ReplacementParser(const QString& yaml_file, const QString& source_file) - : currentLine{ 0 } - , currentColumn{ 0 } - , currentOffset{ 0 } - , cReplacements{ 0 } - , m_yamlname{ yaml_file } - , m_sourceFile{ source_file } +ReplacementParser::ReplacementParser(const QString& yamlFileName, const QString& sourceFileName) + : m_currentLine{ 0 } + , m_currentColumn{ 0 } + , m_currentOffset{ 0 } + , m_countOfReplacements{ 0 } + , m_yamlName{ yamlFileName } + , m_sourceFile{ sourceFileName } { - if (m_yamlname.endsWith(".yaml")) { - QFile yaml(m_yamlname); + if (m_yamlName.endsWith(".yaml")) { + QFile yaml(m_yamlName); yaml.open(QIODevice::ReadOnly); m_yamlContent = yaml.readAll(); - auto checkMatch = check.match(m_yamlContent); + auto checkMatch = Check.match(m_yamlContent); if (!checkMatch.hasMatch()) { - m_yamlname.clear(); + m_yamlName.clear(); m_yamlContent.clear(); } } // TODO (CarlosNihelton): Discover a way to get that from KDevelop. if (m_sourceFile.endsWith(".cpp")) { - i_source = IndexedString(m_sourceFile); + m_iSource = IndexedString(m_sourceFile); // See std::ifstream cpp; cpp.open(m_sourceFile.toUtf8()); @@ -115,10 +115,10 @@ return; // Nothing to parse. } - for (auto iMatch = regex.globalMatch(m_yamlContent); iMatch.hasNext(); ++cReplacements) { + for (auto iMatch = Regex.globalMatch(m_yamlContent); iMatch.hasNext(); ++m_countOfReplacements) { auto smatch = iMatch.next(); auto rep = nextNode(smatch); - all_replacements.push_back(rep); + m_allReplacements.push_back(rep); } } @@ -151,45 +151,45 @@ KDevelop::DocumentRange ReplacementParser::composeNextNodeRange(size_t offset, size_t length) { - qDebug() << "count: " << cReplacements << "\toffset: " << offset << "\tlength: " << length << '\n'; + qDebug() << "count: " << m_countOfReplacements << "\toffset: " << offset << "\tlength: " << length << '\n'; KDevelop::DocumentRange range{ KDevelop::IndexedString(), KTextEditor::Range::invalid() }; /// See https://github.com/CarlosNihelton/kdev-clang-tidy/issues/2. if (offset < 1 || offset + length >= m_sourceView.length()) { return range; } - range.document = i_source; - auto sourceView = m_sourceView.substr(currentOffset, offset - currentOffset); + range.document = m_iSource; + auto sourceView = m_sourceView.substr(m_currentOffset, offset - m_currentOffset); auto pos = ::countOfRowAndColumnToTheEndOfSubstr(sourceView); if (pos.first == 0) { - currentColumn += pos.second; + m_currentColumn += pos.second; } else { - currentColumn = pos.second; + m_currentColumn = pos.second; } - currentLine += pos.first; - currentOffset = offset; + m_currentLine += pos.first; + m_currentOffset = offset; if (length == 0) { - range.setBothColumns(currentColumn); - range.setBothLines(currentLine); + range.setBothColumns(m_currentColumn); + range.setBothLines(m_currentLine); return range; } sourceView = m_sourceView.substr(offset, length); pos = ::countOfRowAndColumnToTheEndOfSubstr(sourceView); - KTextEditor::Cursor start(currentLine, currentColumn); + KTextEditor::Cursor start(m_currentLine, m_currentColumn); size_t endCol; if (pos.first == 0) { - endCol = currentColumn + pos.second; + endCol = m_currentColumn + pos.second; } else { endCol = pos.second; } - KTextEditor::Cursor end(currentLine + pos.first, endCol); + KTextEditor::Cursor end(m_currentLine + pos.first, endCol); range.setRange(start, end); diff --git a/src/plugin/job.h b/src/plugin/job.h --- a/src/plugin/job.h +++ b/src/plugin/job.h @@ -75,7 +75,6 @@ void postProcessStderr(const QStringList& lines) override; void childProcessExited(int exitCode, QProcess::ExitStatus exitStatus) override; - void childProcessError(QProcess::ProcessError processError) override; protected: void buildCommandLine(); @@ -83,8 +82,7 @@ void processStderrLines(const QStringList& lines); QStringList m_standardOutput; - QStringList m_xmlOutput; - bool mustDumpConfig; + bool m_mustDumpConfig; Job::Parameters m_parameters; QVector m_problems; diff --git a/src/plugin/job.cpp b/src/plugin/job.cpp --- a/src/plugin/job.cpp +++ b/src/plugin/job.cpp @@ -38,7 +38,7 @@ , m_parameters(params) { setJobName(i18n("clang-tidy output")); - mustDumpConfig = !(params.dumpConfig.isEmpty()); + m_mustDumpConfig = !(params.dumpConfig.isEmpty()); setCapabilities(KJob::Killable); setStandardToolView(KDevelop::IOutputView::TestView); @@ -49,10 +49,11 @@ *this << params.executablePath; - if (params.useConfigFile.isEmpty()) + if (params.useConfigFile.isEmpty()) { *this << QString("--checks=%1").arg(params.enabledChecks); - else + } else { *this << params.useConfigFile; + } if (!params.exportFixes.isEmpty()) { *this << params.exportFixes + QStringLiteral("%1.yaml").arg(params.filePath); } @@ -69,7 +70,7 @@ if (!params.checkSystemHeaders.isEmpty()) { *this << params.checkSystemHeaders; } - if (mustDumpConfig) { + if (m_mustDumpConfig) { *this << params.dumpConfig; } @@ -83,7 +84,7 @@ void Job::processStdoutLines(const QStringList& lines) { - if (!mustDumpConfig) { + if (!m_mustDumpConfig) { m_standardOutput << lines; } else { QFile file(m_parameters.projectRootDir + "/.clang-tidy"); @@ -95,22 +96,8 @@ void Job::processStderrLines(const QStringList& lines) { - static const auto xmlStartRegex = QRegularExpression("\\s*<"); - for (const QString& line : lines) { - // unfortunately sometime clangtidy send non-XML messages to stderr. - // For example, if we pass '-I /missing_include_dir' to the argument list, - // then stderr output will contains such line (tested on clangtidy 1.72): - // - // (information) Couldn't find path given by -I '/missing_include_dir' - // - // Therefore we must 'move' such messages to m_standardOutput. - - if (line.indexOf(xmlStartRegex) != -1) { // the line contains XML - m_xmlOutput << line; - } else { - m_standardOutput << line; - } + m_standardOutput << line; } } @@ -131,10 +118,7 @@ void Job::start() { m_standardOutput.clear(); - m_xmlOutput.clear(); - qCDebug(KDEV_CLANGTIDY) << "executing:" << commandLine().join(' '); - KDevelop::OutputExecuteJob::start(); } @@ -143,55 +127,15 @@ return m_problems; } -void Job::childProcessError(QProcess::ProcessError e) -{ - QString message; - - switch (e) { - case QProcess::FailedToStart: - message = i18n("Failed to start Clangtidy from %1.", commandLine()[0]); - break; - - case QProcess::Crashed: - message = i18n("Clangtidy crashed."); - break; - - case QProcess::Timedout: - message = i18n("Clangtidy process timed out."); - break; - - case QProcess::WriteError: - message = i18n("Write to Clangtidy process failed."); - break; - - case QProcess::ReadError: - message = i18n("Read from Clangtidy process failed."); - break; - - case QProcess::UnknownError: - // current clangtidy errors will be displayed in the output view - // don't notify the user - break; - } - - if (!message.isEmpty()) { - KMessageBox::error(qApp->activeWindow(), message, i18n("Clangtidy Error")); - } - - KDevelop::OutputExecuteJob::childProcessError(e); -} - void Job::childProcessExited(int exitCode, QProcess::ExitStatus exitStatus) { qCDebug(KDEV_CLANGTIDY) << "Process Finished, exitCode" << exitCode << "process exit status" << exitStatus; if (exitCode != 0) { - qCDebug(KDEV_CLANGTIDY) << "clangtidy failed, standard output: "; + qCDebug(KDEV_CLANGTIDY) << "clangTidy failed, standard output: "; qCDebug(KDEV_CLANGTIDY) << m_standardOutput.join('\n'); - qCDebug(KDEV_CLANGTIDY) << "clangtidy failed, XML output: "; - qCDebug(KDEV_CLANGTIDY) << m_xmlOutput.join('\n'); } else { - ClangtidyParser parser; + ClangTidyParser parser; parser.addData(m_standardOutput); parser.parse(); m_problems = parser.problems(); diff --git a/src/plugin/plugin.h b/src/plugin/plugin.h --- a/src/plugin/plugin.h +++ b/src/plugin/plugin.h @@ -56,7 +56,7 @@ Q_OBJECT public: - Plugin(QObject* parent, const QVariantList& = QVariantList()); + Plugin(QObject* parent, const QVariantList& /* unused */ = QVariantList()); ~Plugin() = default; void unload() override; KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context) override; @@ -84,16 +84,17 @@ * \function * \brief collects all available checks by running clang-tidy with the following parameters: "--checks=* * --list-checks". - * \param clangtidyPath QString - the system path for the clang-tidy program. + * \param clangTidyPath QString - the system path for the clang-tidy program. */ - void collectAllAvailableChecks(QString clangtidyPath); + void collectAllAvailableChecks(QString clangTidyPath); private slots: void loadOutput(); - void runClangtidy(bool allFiles); - void runClangtidyFile(); - void runClangtidyAll(); + void runClangTidy(bool allFiles); + void runClangTidyFile(); + void runClangTidyAll(); void result(KJob* job); + void setSelectedChecks(const QStringList& selectedChecks) { m_activeChecks = selectedChecks; } private: ConfigGroup m_config; diff --git a/src/plugin/plugin.h.in b/src/plugin/plugin.h.in deleted file mode 100644 --- a/src/plugin/plugin.h.in +++ /dev/null @@ -1,107 +0,0 @@ -/* - * This file is part of KDevelop - * - * Copyright 2016 Carlos Nihelton - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#ifndef CLANGTIDY_PLUGIN_H -#define CLANGTIDY_PLUGIN_H - -#include -#include - -#include -#include -#include - -#include -#include -#include - -#include "config/configgroup.h" -#include "qCDebug/debug.h" - -class KJob; - -namespace KDevelop -{ -class ProblemModel; -} - -#define CLANG_TIDY_PATH "@CLANG_TIDY_EXEC@" - -namespace ClangTidy -{ -/** - * \class - * \brief implements the support for clang-tidy inside KDevelop by using the IPlugin interface. - */ -class Plugin : public KDevelop::IPlugin -{ - Q_OBJECT - -public: - Plugin(QObject* parent, const QVariantList& = QVariantList()); - ~Plugin() = default; - void unload() override; - KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context) override; - int configPages() const override { return 1; } - /** - * \function - * \return the session configuration page for clang-tidy plugin. - */ - KDevelop::ConfigPage* configPage(int number, QWidget* parent) override; - int perProjectConfigPages() const override { return 1; } - /** - * \function - * \return the clang-tidy configuration page for the current project. - */ - KDevelop::ConfigPage* perProjectConfigPage(int number, const KDevelop::ProjectConfigOptions& options, - QWidget* parent) override; - /** - *\function - *\returns all available checks, obtained from clang-tidy program, ran with with "--checks=* --list-checks" - * parameters. - */ - QStringList allAvailableChecks() { return m_allChecks; } -protected: - /** - * \function - * \brief collects all available checks by running clang-tidy with the following parameters: "--checks=* - * --list-checks". - * \param clangtidyPath QString - the system path for the clang-tidy program. - */ - void collectAllAvailableChecks(QString clangtidyPath); - -private slots: - void loadOutput(); - void runClangtidy(bool allFiles); - void runClangtidyFile(); - void runClangtidyAll(); - void result(KJob* job); - -private: - ConfigGroup m_config; - QScopedPointer m_model; - QStringList m_allChecks; - QStringList m_activeChecks; -}; - -} // namespace ClangTidy - -#endif // CLANGTIDY_PLUGIN_H diff --git a/src/plugin/plugin.cpp b/src/plugin/plugin.cpp --- a/src/plugin/plugin.cpp +++ b/src/plugin/plugin.cpp @@ -57,30 +57,30 @@ using namespace KDevelop; -K_PLUGIN_FACTORY_WITH_JSON(ClangtidyFactory, "res/kdevclangtidy.json", registerPlugin();) +K_PLUGIN_FACTORY_WITH_JSON(ClangTidyFactory, "res/kdevclangtidy.json", registerPlugin();) namespace ClangTidy { Plugin::Plugin(QObject* parent, const QVariantList& /*unused*/) : IPlugin("kdevclangtidy", parent) , m_model(new KDevelop::ProblemModel(parent)) { - qCDebug(KDEV_CLANGTIDY) << "setting clangtidy rc file"; + qCDebug(KDEV_CLANGTIDY) << "setting clangTidy rc file"; setXMLFile("kdevclangtidy.rc"); - QAction* act_checkfile; - act_checkfile = actionCollection()->addAction("clangtidy_file", this, SLOT(runClangtidyFile())); - act_checkfile->setStatusTip(i18n("Launches Clangtidy for current file")); - act_checkfile->setText(i18n("clang-tidy")); + QAction* actionCheckFile; + actionCheckFile = actionCollection()->addAction("clangTidy_file", this, SLOT(runClangTidyFile())); + actionCheckFile->setStatusTip(i18n("Launches ClangTidy for current file")); + actionCheckFile->setText(i18n("clang-tidy")); - /* TODO: Uncomment this only when discover a safe way to run clang-tidy on + /* TODO(coliveira): Uncomment this only when discover a safe way to run clang-tidy on the whole project. - // QAction* act_check_all_files; - // act_check_all_files = actionCollection()->addAction ( "clangtidy_all", - this, SLOT ( runClangtidyAll() ) ); - // act_check_all_files->setStatusTip ( i18n ( "Launches clangtidy for all + // QAction* actionCheckAllFiles; + // actionCheckAllFiles = actionCollection()->addAction ( "clangTidy_all", + this, SLOT ( runClangTidyAll() ) ); + // actionCheckAllFiles->setStatusTip ( i18n ( "Launches clangTidy for all translation " // "units of current project" ) ); - // act_check_all_files->setText ( i18n ( "clang-tidy (all)" ) ); + // actionCheckAllFiles->setText ( i18n ( "clang-tidy (all)" ) ); */ IExecutePlugin* iface = KDevelop::ICore::self() @@ -90,18 +90,18 @@ Q_ASSERT(iface); ProblemModelSet* pms = core()->languageController()->problemModelSet(); - pms->addModel(QStringLiteral("Clangtidy"), m_model.data()); + pms->addModel(QStringLiteral("ClangTidy"), m_model.data()); - m_config = KSharedConfig::openConfig()->group("Clangtidy"); - auto clangtidyPath = m_config.readEntry(ConfigGroup::ExecutablePath); + m_config = KSharedConfig::openConfig()->group("ClangTidy"); + auto clangTidyPath = m_config.readEntry(ConfigGroup::ExecutablePath); - // TODO(cnihelton): auto detect clang-tidy executable instead of hard-coding - // it. - if (clangtidyPath.isEmpty()) { - clangtidyPath = QString(CLANG_TIDY_PATH); + // TODO(coliveira): auto detect clang-tidy executable instead of hard-coding it. + // Done: var CLANG_TIDY_PATH is set from CMake. + if (clangTidyPath.isEmpty()) { + clangTidyPath = QString(CLANG_TIDY_PATH); } - collectAllAvailableChecks(clangtidyPath); + collectAllAvailableChecks(clangTidyPath); m_config.writeEntry(ConfigGroup::AdditionalParameters, ""); for (auto check : m_allChecks) { @@ -120,14 +120,14 @@ void Plugin::unload() { ProblemModelSet* pms = core()->languageController()->problemModelSet(); - pms->removeModel(QStringLiteral("Clangtidy")); + pms->removeModel(QStringLiteral("ClangTidy")); } -void Plugin::collectAllAvailableChecks(QString clangtidyPath) +void Plugin::collectAllAvailableChecks(QString clangTidyPath) { m_allChecks.clear(); KProcess tidy; - tidy << clangtidyPath << QLatin1String("-checks=*") << QLatin1String("--list-checks"); + tidy << clangTidyPath << QLatin1String("-checks=*") << QLatin1String("--list-checks"); tidy.setOutputChannelMode(KProcess::OnlyStdoutChannel); tidy.start(); @@ -154,7 +154,7 @@ m_allChecks.removeDuplicates(); } -void Plugin::runClangtidy(bool allFiles) +void Plugin::runClangTidy(bool allFiles) { KDevelop::IDocument* doc = core()->documentController()->activeDocument(); if (doc == nullptr) { @@ -169,26 +169,27 @@ return; } - m_config = project->projectConfiguration()->group("Clangtidy"); + m_config = project->projectConfiguration()->group("ClangTidy"); if (!m_config.isValid()) { - QMessageBox::critical(nullptr, i18n("Error starting Clangtidy"), + QMessageBox::critical(nullptr, i18n("Error starting ClangTidy"), i18n("Can't load parameters. They must be set in the " "project settings.")); return; } - auto clangtidyPath = m_config.readEntry(ConfigGroup::ExecutablePath); + auto clangTidyPath = m_config.readEntry(ConfigGroup::ExecutablePath); auto buildSystem = project->buildSystemManager(); Job::Parameters params; params.projectRootDir = project->path().toLocalFile(); - // TODO: auto detect clang-tidy executable instead of hard-coding it. - if (clangtidyPath.isEmpty()) { - params.executablePath = QStringLiteral("/usr/bin/clang-tidy"); + // TODO(coliveira): auto detect clang-tidy executable instead of hard-coding it. + // Done: var CLANG_TIDY_PATH is set from CMake. + if (clangTidyPath.isEmpty()) { + params.executablePath = QStringLiteral(CLANG_TIDY_PATH); } else { - params.executablePath = clangtidyPath; + params.executablePath = clangTidyPath; } if (allFiles) { @@ -222,16 +223,16 @@ core()->runController()->registerJob(job2); } -void Plugin::runClangtidyFile() +void Plugin::runClangTidyFile() { bool allFiles = false; - runClangtidy(allFiles); + runClangTidy(allFiles); } -void Plugin::runClangtidyAll() +void Plugin::runClangTidyAll() { bool allFiles = true; - runClangtidy(allFiles); + runClangTidy(allFiles); } void Plugin::loadOutput() @@ -247,9 +248,7 @@ if (aj->status() == KDevelop::OutputExecuteJob::JobStatus::JobSucceeded) { m_model->setProblems(aj->problems()); - - core()->uiController()->findToolView(i18nd("kdevproblemreporter", "Problems"), nullptr, - KDevelop::IUiController::FindFlags::Raise); + core()->languageController()->problemModelSet()->showModel(i18nd("kdevproblemreporter", "ClangTidy")); } } @@ -259,11 +258,10 @@ KDevelop::ContextMenuExtension extension = KDevelop::IPlugin::contextMenuExtension(context); if (context->type() == KDevelop::Context::EditorContext) { - auto mime = doc->mimeType().name(); if (mime == QLatin1String("text/x-c++src") || mime == QLatin1String("text/x-csrc")) { QAction* action = new QAction(QIcon::fromTheme("dialog-ok"), i18n("Check unit with clang-tidy"), this); - connect(action, SIGNAL(triggered(bool)), this, SLOT(runClangtidyFile())); + connect(action, SIGNAL(triggered(bool)), this, SLOT(runClangTidyFile())); extension.addAction(KDevelop::ContextMenuExtension::ExtensionGroup, action); } } @@ -276,7 +274,7 @@ return nullptr; } auto config = new PerProjectConfigPage(options.project, parent); - config->setActiveChecksReceptorList(&m_activeChecks); + connect(config, &PerProjectConfigPage::selectedChecksChanged, this, &Plugin::setSelectedChecks); config->setList(m_allChecks); return config; } @@ -286,7 +284,7 @@ if (number != 0) { return nullptr; } - return new ClangtidyPreferences(this, parent); + return new ClangTidyPreferences(this, parent); } } // namespace ClangTidy diff --git a/src/qCDebug/debug.cpp b/src/qCDebug/debug.cpp --- a/src/qCDebug/debug.cpp +++ b/src/qCDebug/debug.cpp @@ -20,4 +20,4 @@ */ #include "debug.h" -Q_LOGGING_CATEGORY(KDEV_CLANGTIDY, "kdev.clangtidy") +Q_LOGGING_CATEGORY(KDEV_CLANGTIDY, "kdev.clangTidy") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,7 +24,12 @@ ) # TODO: Discover how to test the plugin class. -# ecm_add_test(test_plugin.cpp ${PROJECT_SOURCE_DIR}/src/plugin.cpp ${PROJECT_SOURCE_DIR}/src/job.cpp -# ${PROJECT_SOURCE_DIR}/src/debug.cpp -# TEST_NAME test_clangtidyplugin -# LINK_LIBRARIES Qt5::Test KDev::Tests) +# ecm_add_test( test_plugin.cpp +# ../src/plugin/plugin.cpp +# ../src/plugin/job.cpp +# ../src/parsers/clangtidyparser.cpp +# ../src/parsers/replacementparser.cpp +# ../src/qCDebug/debug.cpp +# TEST_NAME test_clangtidyplugin +# LINK_LIBRARIES Qt5::Test KDev::Tests +# ) diff --git a/tests/data/nihon_plugin.cpp b/tests/data/nihon_plugin.cpp --- a/tests/data/nihon_plugin.cpp +++ b/tests/data/nihon_plugin.cpp @@ -189,25 +189,25 @@ using namespace KDevelop; -K_PLUGIN_FACTORY_WITH_JSON(ClangtidyFactory, "res/kdevclangtidy.json", registerPlugin();) +K_PLUGIN_FACTORY_WITH_JSON(ClangTidyFactory, "res/kdevclangTidy.json", registerPlugin();) namespace ClangTidy { Plugin::Plugin(QObject* parent, const QVariantList& /*unused*/) : IPlugin("kdevclangtidy", parent) , m_model(new KDevelop::ProblemModel(parent)) { - qCDebug(KDEV_CLANGTIDY) << "setting clangtidy rc file"; - setXMLFile("kdevclangtidy.rc"); + qCDebug(KDEV_CLANGTIDY) << "setting clangTidy rc file"; + setXMLFile("kdevclangTidy.rc"); QAction* act_checkfile; - act_checkfile = actionCollection()->addAction("clangtidy_file", this, SLOT(runClangtidyFile())); - act_checkfile->setStatusTip(i18n("Launches Clangtidy for current file")); + act_checkfile = actionCollection()->addAction("clangTidy_file", this, SLOT(runClangTidyFile())); + act_checkfile->setStatusTip(i18n("Launches ClangTidy for current file")); act_checkfile->setText(i18n("clang-tidy")); /* TODO: Uncomment this only when discover a safe way to run clang-tidy on the whole project. // QAction* act_check_all_files; - // act_check_all_files = actionCollection()->addAction ( "clangtidy_all", this, SLOT ( runClangtidyAll() ) ); - // act_check_all_files->setStatusTip ( i18n ( "Launches clangtidy for all translation " + // act_check_all_files = actionCollection()->addAction ( "clangTidy_all", this, SLOT ( runClangTidyAll() ) ); + // act_check_all_files->setStatusTip ( i18n ( "Launches clangTidy for all translation " // "units of current project" ) ); // act_check_all_files->setText ( i18n ( "clang-tidy (all)" ) ); */ @@ -219,17 +219,17 @@ Q_ASSERT(iface); ProblemModelSet* pms = core()->languageController()->problemModelSet(); - pms->addModel(QStringLiteral("Clangtidy"), m_model.data()); + pms->addModel(QStringLiteral("ClangTidy"), m_model.data()); - m_config = KSharedConfig::openConfig()->group("Clangtidy"); - auto clangtidyPath = m_config.readEntry(ConfigGroup::ExecutablePath); + m_config = KSharedConfig::openConfig()->group("ClangTidy"); + auto clangTidyPath = m_config.readEntry(ConfigGroup::ExecutablePath); // TODO(cnihelton): auto detect clang-tidy executable instead of hard-coding it. - if (clangtidyPath.isEmpty()) { - clangtidyPath = QString("/usr/bin/clang-tidy"); + if (clangTidyPath.isEmpty()) { + clangTidyPath = QString("/usr/bin/clang-tidy"); } - collectAllAvailableChecks(clangtidyPath); + collectAllAvailableChecks(clangTidyPath); m_config.writeEntry(ConfigGroup::AdditionalParameters, ""); for (auto check : m_allChecks) { @@ -248,14 +248,14 @@ void Plugin::unload() { ProblemModelSet* pms = core()->languageController()->problemModelSet(); - pms->removeModel(QStringLiteral("Clangtidy")); + pms->removeModel(QStringLiteral("ClangTidy")); } -void Plugin::collectAllAvailableChecks(QString clangtidyPath) +void Plugin::collectAllAvailableChecks(QString clangTidyPath) { m_allChecks.clear(); KProcess tidy; - tidy << clangtidyPath << QLatin1String("-checks=*") << QLatin1String("--list-checks"); + tidy << clangTidyPath << QLatin1String("-checks=*") << QLatin1String("--list-checks"); tidy.setOutputChannelMode(KProcess::OnlyStdoutChannel); tidy.start(); @@ -282,7 +282,7 @@ m_allChecks.removeDuplicates(); } -void Plugin::runClangtidy(bool allFiles) +void Plugin::runClangTidy(bool allFiles) { KDevelop::IDocument* doc = core()->documentController()->activeDocument(); if (!doc) { @@ -297,14 +297,14 @@ return; } - m_config = project->projectConfiguration()->group("Clangtidy"); + m_config = project->projectConfiguration()->group("ClangTidy"); if (!m_config.isValid()) { - QMessageBox::critical(nullptr, i18n("Error starting Clangtidy"), + QMessageBox::critical(nullptr, i18n("Error starting ClangTidy"), i18n("Can't load parameters. They must be set in the project settings.")); return; } - auto clangtidyPath = m_config.readEntry(ConfigGroup::ExecutablePath); + auto clangTidyPath = m_config.readEntry(ConfigGroup::ExecutablePath); auto buildSystem = project->buildSystemManager(); Job::Parameters params; @@ -312,10 +312,10 @@ params.projectRootDir = project->path().toLocalFile(); // TODO: auto detect clang-tidy executable instead of hard-coding it. - if (clangtidyPath.isEmpty()) { + if (clangTidyPath.isEmpty()) { params.executablePath = QStringLiteral("/usr/bin/clang-tidy"); } else { - params.executablePath = clangtidyPath; + params.executablePath = clangTidyPath; } if (allFiles) { @@ -349,16 +349,16 @@ core()->runController()->registerJob(job2); } -void Plugin::runClangtidyFile() +void Plugin::runClangTidyFile() { bool allFiles = false; - runClangtidy(allFiles); + runClangTidy(allFiles); } -void Plugin::runClangtidyAll() +void Plugin::runClangTidyAll() { bool allFiles = true; - runClangtidy(allFiles); + runClangTidy(allFiles); } void Plugin::loadOutput() @@ -391,7 +391,7 @@ if (mime == QLatin1String("text/x-c++src") || mime == QLatin1String("text/x-csrc")) { QAction* action = new QAction(QIcon::fromTheme("document-new"), i18n("Check current unit with clang-tidy"), this); - connect(action, SIGNAL(triggered(bool)), this, SLOT(runClangtidyFile())); + connect(action, SIGNAL(triggered(bool)), this, SLOT(runClangTidyFile())); extension.addAction(KDevelop::ContextMenuExtension::ExtensionGroup, action); } } @@ -415,7 +415,7 @@ if (number != 0) { return nullptr; } else { - return new ClangtidyPreferences(this, parent); + return new ClangTidyPreferences(this, parent); } } } diff --git a/tests/data/plugin.cpp b/tests/data/plugin.cpp --- a/tests/data/plugin.cpp +++ b/tests/data/plugin.cpp @@ -56,25 +56,25 @@ using namespace KDevelop; -K_PLUGIN_FACTORY_WITH_JSON(ClangtidyFactory, "res/kdevclangtidy.json", registerPlugin();) +K_PLUGIN_FACTORY_WITH_JSON(ClangTidyFactory, "res/kdevclangtidy.json", registerPlugin();) namespace ClangTidy { Plugin::Plugin(QObject* parent, const QVariantList& /*unused*/) : IPlugin("kdevclangtidy", parent) , m_model(new KDevelop::ProblemModel(parent)) { - qCDebug(KDEV_CLANGTIDY) << "setting clangtidy rc file"; + qCDebug(KDEV_CLANGTIDY) << "setting clangTidy rc file"; setXMLFile("kdevclangtidy.rc"); QAction* act_checkfile; - act_checkfile = actionCollection()->addAction("clangtidy_file", this, SLOT(runClangtidyFile())); - act_checkfile->setStatusTip(i18n("Launches Clangtidy for current file")); + act_checkfile = actionCollection()->addAction("clangTidy_file", this, SLOT(runClangTidyFile())); + act_checkfile->setStatusTip(i18n("Launches ClangTidy for current file")); act_checkfile->setText(i18n("clang-tidy")); /* TODO: Uncomment this only when discover a safe way to run clang-tidy on the whole project. // QAction* act_check_all_files; - // act_check_all_files = actionCollection()->addAction ( "clangtidy_all", this, SLOT ( runClangtidyAll() ) ); - // act_check_all_files->setStatusTip ( i18n ( "Launches clangtidy for all translation " + // act_check_all_files = actionCollection()->addAction ( "clangTidy_all", this, SLOT ( runClangTidyAll() ) ); + // act_check_all_files->setStatusTip ( i18n ( "Launches clangTidy for all translation " // "units of current project" ) ); // act_check_all_files->setText ( i18n ( "clang-tidy (all)" ) ); */ @@ -86,17 +86,17 @@ Q_ASSERT(iface); ProblemModelSet* pms = core()->languageController()->problemModelSet(); - pms->addModel(QStringLiteral("Clangtidy"), m_model.data()); + pms->addModel(QStringLiteral("ClangTidy"), m_model.data()); - m_config = KSharedConfig::openConfig()->group("Clangtidy"); - auto clangtidyPath = m_config.readEntry(ConfigGroup::ExecutablePath); + m_config = KSharedConfig::openConfig()->group("ClangTidy"); + auto clangTidyPath = m_config.readEntry(ConfigGroup::ExecutablePath); // TODO(cnihelton): auto detect clang-tidy executable instead of hard-coding it. - if (clangtidyPath.isEmpty()) { - clangtidyPath = QString("/usr/bin/clang-tidy"); + if (clangTidyPath.isEmpty()) { + clangTidyPath = QString("/usr/bin/clang-tidy"); } - collectAllAvailableChecks(clangtidyPath); + collectAllAvailableChecks(clangTidyPath); m_config.writeEntry(ConfigGroup::AdditionalParameters, ""); for (auto check : m_allChecks) { @@ -115,14 +115,14 @@ void Plugin::unload() { ProblemModelSet* pms = core()->languageController()->problemModelSet(); - pms->removeModel(QStringLiteral("Clangtidy")); + pms->removeModel(QStringLiteral("ClangTidy")); } -void Plugin::collectAllAvailableChecks(QString clangtidyPath) +void Plugin::collectAllAvailableChecks(QString clangTidyPath) { m_allChecks.clear(); KProcess tidy; - tidy << clangtidyPath << QLatin1String("-checks=*") << QLatin1String("--list-checks"); + tidy << clangTidyPath << QLatin1String("-checks=*") << QLatin1String("--list-checks"); tidy.setOutputChannelMode(KProcess::OnlyStdoutChannel); tidy.start(); @@ -149,7 +149,7 @@ m_allChecks.removeDuplicates(); } -void Plugin::runClangtidy(bool allFiles) +void Plugin::runClangTidy(bool allFiles) { KDevelop::IDocument* doc = core()->documentController()->activeDocument(); if (!doc) { @@ -164,14 +164,14 @@ return; } - m_config = project->projectConfiguration()->group("Clangtidy"); + m_config = project->projectConfiguration()->group("ClangTidy"); if (!m_config.isValid()) { - QMessageBox::critical(nullptr, i18n("Error starting Clangtidy"), + QMessageBox::critical(nullptr, i18n("Error starting ClangTidy"), i18n("Can't load parameters. They must be set in the project settings.")); return; } - auto clangtidyPath = m_config.readEntry(ConfigGroup::ExecutablePath); + auto clangTidyPath = m_config.readEntry(ConfigGroup::ExecutablePath); auto buildSystem = project->buildSystemManager(); Job::Parameters params; @@ -179,10 +179,10 @@ params.projectRootDir = project->path().toLocalFile(); // TODO: auto detect clang-tidy executable instead of hard-coding it. - if (clangtidyPath.isEmpty()) { + if (clangTidyPath.isEmpty()) { params.executablePath = QStringLiteral("/usr/bin/clang-tidy"); } else { - params.executablePath = clangtidyPath; + params.executablePath = clangTidyPath; } if (allFiles) { @@ -216,16 +216,16 @@ core()->runController()->registerJob(job2); } -void Plugin::runClangtidyFile() +void Plugin::runClangTidyFile() { bool allFiles = false; - runClangtidy(allFiles); + runClangTidy(allFiles); } -void Plugin::runClangtidyAll() +void Plugin::runClangTidyAll() { bool allFiles = true; - runClangtidy(allFiles); + runClangTidy(allFiles); } void Plugin::loadOutput() @@ -258,7 +258,7 @@ if (mime == QLatin1String("text/x-c++src") || mime == QLatin1String("text/x-csrc")) { QAction* action = new QAction(QIcon::fromTheme("document-new"), i18n("Check current unit with clang-tidy"), this); - connect(action, SIGNAL(triggered(bool)), this, SLOT(runClangtidyFile())); + connect(action, SIGNAL(triggered(bool)), this, SLOT(runClangTidyFile())); extension.addAction(KDevelop::ContextMenuExtension::ExtensionGroup, action); } } @@ -282,7 +282,7 @@ if (number != 0) { return nullptr; } else { - return new ClangtidyPreferences(this, parent); + return new ClangTidyPreferences(this, parent); } } } diff --git a/tests/test_clangtidyjob.h b/tests/test_clangtidyjob.h --- a/tests/test_clangtidyjob.h +++ b/tests/test_clangtidyjob.h @@ -24,7 +24,7 @@ #include -class TestClangtidyJob : public QObject +class TestClangTidyJob : public QObject { Q_OBJECT private slots: diff --git a/tests/test_clangtidyjob.cpp b/tests/test_clangtidyjob.cpp --- a/tests/test_clangtidyjob.cpp +++ b/tests/test_clangtidyjob.cpp @@ -44,22 +44,22 @@ QString standardOutput() const { return m_standardOutput.join('\n'); } }; -void TestClangtidyJob::initTestCase() +void TestClangTidyJob::initTestCase() { AutoTestShell::init({ "kdevclangtidy" }); TestCore::initialize(Core::NoUi); } -void TestClangtidyJob::cleanupTestCase() +void TestClangTidyJob::cleanupTestCase() { TestCore::shutdown(); } -void TestClangtidyJob::testJob() +void TestClangTidyJob::testJob() { - QFile output_example_file("data/output_example"); - output_example_file.open(QIODevice::ReadOnly); - QTextStream ios(&output_example_file); + QFile outputExampleFile("data/output_example"); + outputExampleFile.open(QIODevice::ReadOnly); + QTextStream ios(&outputExampleFile); QStringList stdoutOutput; QString line; while (ios.readLineInto(&line)) { @@ -89,4 +89,4 @@ problems[2]->explanation().startsWith(QStringLiteral("[cppcoreguidelines-pro-bounds-array-to-pointer-decay]"))); } -QTEST_GUILESS_MAIN(TestClangtidyJob); +QTEST_GUILESS_MAIN(TestClangTidyJob); diff --git a/tests/test_clangtidyparser.h b/tests/test_clangtidyparser.h --- a/tests/test_clangtidyparser.h +++ b/tests/test_clangtidyparser.h @@ -24,7 +24,7 @@ #include -class TestClangtidyParser : public QObject +class TestClangTidyParser : public QObject { Q_OBJECT private slots: diff --git a/tests/test_clangtidyparser.cpp b/tests/test_clangtidyparser.cpp --- a/tests/test_clangtidyparser.cpp +++ b/tests/test_clangtidyparser.cpp @@ -33,32 +33,32 @@ using namespace KDevelop; using namespace ClangTidy; -void TestClangtidyParser::initTestCase() +void TestClangTidyParser::initTestCase() { AutoTestShell::init(); TestCore::initialize(Core::NoUi); } -void TestClangtidyParser::cleanupTestCase() +void TestClangTidyParser::cleanupTestCase() { TestCore::shutdown(); } -void TestClangtidyParser::testParser() +void TestClangTidyParser::testParser() { // prepare QStringList from file to be parsed. - QFile output_example_file("data/output_example"); - output_example_file.open(QIODevice::ReadOnly); - QTextStream ios(&output_example_file); - QStringList clangtidy_example_output; + QFile outputExampleFile("data/output_example"); + outputExampleFile.open(QIODevice::ReadOnly); + QTextStream ios(&outputExampleFile); + QStringList clangTidyExampleOutput; QString line; while (ios.readLineInto(&line)) { - clangtidy_example_output << line; + clangTidyExampleOutput << line; } - QVERIFY(!clangtidy_example_output.isEmpty()); - ClangTidy::ClangtidyParser parser; - parser.addData(clangtidy_example_output); + QVERIFY(!clangTidyExampleOutput.isEmpty()); + ClangTidy::ClangTidyParser parser; + parser.addData(clangTidyExampleOutput); parser.parse(); const auto problems = parser.problems(); @@ -97,4 +97,4 @@ QCOMPARE(p->source(), IProblem::Plugin); } -QTEST_GUILESS_MAIN(TestClangtidyParser); +QTEST_GUILESS_MAIN(TestClangTidyParser); diff --git a/tests/test_plugin.h b/tests/test_plugin.h --- a/tests/test_plugin.h +++ b/tests/test_plugin.h @@ -24,7 +24,7 @@ #include -class TestClangtidyPlugin : public QObject +class TestClangTidyPlugin : public QObject { Q_OBJECT private slots: diff --git a/tests/test_plugin.cpp b/tests/test_plugin.cpp --- a/tests/test_plugin.cpp +++ b/tests/test_plugin.cpp @@ -30,22 +30,24 @@ using namespace KDevelop; // using namespace ClangTidy; -void TestClangtidyPlugin::initTestCase() +void TestClangTidyPlugin::initTestCase() { AutoTestShell::init(); TestCore::initialize(Core::NoUi); } -void TestClangtidyPlugin::cleanupTestCase() +void TestClangTidyPlugin::cleanupTestCase() { TestCore::shutdown(); } -void TestClangtidyPlugin::testPlugin() +void TestClangTidyPlugin::testPlugin() { ClangTidy::Plugin plugin(nullptr); QCOMPARE(plugin.configPages(), 1); QVERIFY(!plugin.allAvailableChecks().isEmpty()); + + // TODO(coliveira): Create more useful tests. } -QTEST_GUILESS_MAIN(TestClangtidyPlugin); +QTEST_GUILESS_MAIN(TestClangTidyPlugin);