Integrated clang-tidy into cmake

Enabled warnings as errors when building project target
Changed checks for clang-tidy
Changed indentation from 2 spaces to 4 in clang-format
Added pre-commit hook to apply clang-format formatting to the source tree
This commit is contained in:
Egor 2024-10-23 14:41:12 +03:00
parent afbdb87f54
commit e16a1a6f6e
10 changed files with 151 additions and 128 deletions

View file

@ -1,3 +1,3 @@
Language: Cpp Language: Cpp
BasedOnStyle: LLVM BasedOnStyle: LLVM
IndentWidth: 4

View file

@ -1,39 +1,20 @@
Checks: "*, Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,-modernize-use-trailing-return-type,readability-*'
-abseil-*, WarningsAsErrors: '*'
-altera-*,
-android-*,
-fuchsia-*,
-google-*,
-llvm*,
-modernize-use-trailing-return-type,
-zircon-*,
-readability-else-after-return,
-readability-static-accessed-through-instance,
-readability-avoid-const-params-in-decls,
-cppcoreguidelines-non-private-member-variables-in-classes,
-misc-non-private-member-variables-in-classes,
"
WarningsAsErrors: ''
HeaderFilterRegex: ''
FormatStyle: none
CheckOptions: CheckOptions:
- { key: readability-identifier-naming.NamespaceCase, value: lower_case } - { key: readability-identifier-naming.NamespaceCase, value: lower_case }
- { key: readability-identifier-naming.ClassCase, value: CamelCase } - { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.StructCase, value: CamelCase } - { key: readability-identifier-naming.ClassConstantCase, value: UPPER_CASE }
- { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase } - { key: readability-identifier-naming.ClassMemberCase, value: lower_case }
- { key: readability-identifier-naming.FunctionCase, value: camelBack } - { key: readability-identifier-naming.ClassMethodCase, value: lower_case }
- { key: readability-identifier-naming.VariableCase, value: lower_case } - { key: readability-identifier-naming.EnumCase, value: CamelCase }
- { key: readability-identifier-naming.PrivateMemberSuffix, value: _ } - { key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE }
- { key: readability-identifier-naming.ProtectedMemberSuffix, value: _ } - { key: readability-identifier-naming.FunctionCase, value: lower_case }
- { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE } - { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE }
- { key: readability-identifier-naming.EnumConstantCase, value: CamelCase } - { key: readability-identifier-naming.MemberCase, value: lower_case }
- { key: readability-identifier-naming.EnumConstantPrefix, value: k } - { key: readability-identifier-naming.MethodCase, value: lower_case }
- { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase } - { key: readability-identifier-naming.ParameterCase, value: lower_case }
- { key: readability-identifier-naming.ConstexprVariablePrefix, value: k } - { key: readability-identifier-naming.StructCase, value: CamelCase }
- { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase } - { key: readability-identifier-naming.UnionCase, value: CamelCase }
- { key: readability-identifier-naming.GlobalConstantPrefix, value: k } - { key: readability-identifier-naming.TypedefCase, value: CamelCase }
- { key: readability-identifier-naming.MemberConstantCase, value: CamelCase } - { key: readability-identifier-naming.TypeAliasCase, value: CamelCase }
- { key: readability-identifier-naming.MemberConstantPrefix, value: k } - { key: readability-identifier-naming.VariableCase, value: lower_case }
- { key: readability-identifier-naming.StaticConstantCase, value: CamelCase }
- { key: readability-identifier-naming.StaticConstantPrefix, value: k }

5
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,5 @@
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.2
hooks:
- id: clang-format

View file

@ -1,10 +1,15 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)
project(yadro-task VERSION 0.1) project(yadro-task VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
file(GLOB SOURCES "src/*.cpp") # clang-tidy
find_program(CLANG_TIDY_EXE NAMES clang-tidy REQUIRED)
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_EXE})
file(GLOB SOURCES src/*.cpp)
add_executable(${PROJECT_NAME} ${SOURCES}) add_executable(${PROJECT_NAME} ${SOURCES})
@ -13,3 +18,4 @@ target_include_directories(${PROJECT_NAME}
${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/include
) )
set_property(TARGET ${PROJECT_NAME} PROPERTY COMPILE_WARNINGS_AS_ERRORS ON)

View file

@ -13,10 +13,10 @@ namespace tape {
* such as read dealy, write delay etc. * such as read dealy, write delay etc.
*/ */
struct FileTapeSettings { struct FileTapeSettings {
unsigned int readDelayMs; unsigned int read_delay_ms;
unsigned int writeDelayMs; unsigned int write_delay_ms;
unsigned int seekForwardDelayMs; unsigned int seek_forward_delay_ms;
unsigned int seekBackwardsDelayMs; unsigned int seek_backwards_delay_ms;
}; };
/** /**
@ -28,53 +28,53 @@ struct FileTapeSettings {
* cell data is stored as plain text. * cell data is stored as plain text.
*/ */
class FileTape : public Tape { class FileTape : public Tape {
private: private:
std::fstream file_; std::fstream file;
FileTapeSettings settings_; FileTapeSettings settings;
public: public:
FileTape &operator=(const FileTape &) = delete; FileTape &operator=(const FileTape &) = delete;
FileTape(const FileTape &) = delete; FileTape(const FileTape &) = delete;
FileTape(FileTape &&) = delete; FileTape(FileTape &&) = delete;
FileTape &operator=(FileTape &&) = delete; FileTape &operator=(FileTape &&) = delete;
~FileTape() override; ~FileTape() override;
/** /**
* Initialize a new instance of FileTape that will open a file with the * Initialize a new instance of FileTape that will open a file with the
* specified name. File must be read and write accessible. * specified name. File must be read and write accessible.
* *
* @param file_name Name of a file to be opened. * @param file_name Name of a file to be opened.
* @param settings File tape settings * @param settings File tape settings
*/ */
explicit FileTape(const std::string &fileName, FileTapeSettings settings); explicit FileTape(const std::string &file_name, FileTapeSettings settings);
/** /**
* Advances the underlying fstream to a new line. * Advances the underlying fstream to a new line.
* *
* @return false if EOF is reached, otherwise true. * @return false if EOF is reached, otherwise true.
*/ */
bool seekForward() override; bool seek_forward() override;
/** /**
* Rewinds the underlying fstream to a previous line. * Rewinds the underlying fstream to a previous line.
* *
* @return false if called from the first line of a file, otherwise true. * @return false if called from the first line of a file, otherwise true.
*/ */
bool seekBackwards() override; bool seek_backwards() override;
/** /**
* Reads and parses data from the current line. * Reads and parses data from the current line.
* *
* @return number from the line, or 0 if data can not be parsed. * @return number from the line, or 0 if data can not be parsed.
*/ */
int32_t read() override; int32_t read() override;
/** /**
* Writes data to the current line. * Writes data to the current line.
* *
* @param data Number, that should be written to the current line. * @param data Number, that should be written to the current line.
*/ */
void write(int32_t data) override; void write(int32_t data) override;
}; };
} // namespace tape } // namespace tape

View file

@ -16,43 +16,43 @@ namespace tape {
* forward or backwards is a very time-consuming operation. * forward or backwards is a very time-consuming operation.
*/ */
class Tape { class Tape {
public: public:
Tape(const Tape &) = default; Tape(const Tape &) = default;
Tape(Tape &&) = default; Tape(Tape &&) = default;
Tape &operator=(const Tape &) = default; Tape &operator=(const Tape &) = default;
Tape &operator=(Tape &&) = default; Tape &operator=(Tape &&) = default;
Tape() = default; Tape() = default;
virtual ~Tape() = default; virtual ~Tape() = default;
/** /**
* Advances the tape one cell forward. * Advances the tape one cell forward.
* *
* @return false if the next cell doesn't exist (reached end of tape), * @return false if the next cell doesn't exist (reached end of tape),
* otherwise true. * otherwise true.
*/ */
virtual bool seekForward() = 0; virtual bool seek_forward() = 0;
/** /**
* Rewinds the tape one cell backwards. * Rewinds the tape one cell backwards.
* *
* @return false if the previous cell doesn't exist (reached beginning of * @return false if the previous cell doesn't exist (reached beginning of
* tape), otherwise true. * tape), otherwise true.
*/ */
virtual bool seekBackwards() = 0; virtual bool seek_backwards() = 0;
/** /**
* Reads data from the current cell. * Reads data from the current cell.
* *
* @return number, that is stored on the current cell. * @return number, that is stored on the current cell.
*/ */
virtual int32_t read() = 0; virtual int32_t read() = 0;
/** /**
* Writes data to the current cell. * Writes data to the current cell.
* *
* @param data Number, that should be written to the current cell. * @param data Number, that should be written to the current cell.
*/ */
virtual void write(int32_t data) = 0; virtual void write(int32_t data) = 0;
}; };
} // namespace tape } // namespace tape

12
include/tapeconfig.h Normal file
View file

@ -0,0 +1,12 @@
#ifndef TAPE_CONFIG_H
#define TAPE_CONFIG_H
#include "filetape.h"
namespace tape {
FileTapeSettings init_settings(int argc, char **argv);
} // namespace tape
#endif // !TAPE_CONFIG_H

View file

@ -3,17 +3,18 @@
#include <fstream> #include <fstream>
#include <string> #include <string>
tape::FileTape::FileTape(const std::string &fileName, FileTapeSettings settings) tape::FileTape::FileTape(const std::string &file_name,
: settings_(settings) { FileTapeSettings settings)
this->file_ = std::fstream(fileName); : settings(settings) {
this->file = std::fstream(file_name);
} }
bool tape::FileTape::seekForward() { return true; } bool tape::FileTape::seek_forward() { return true; }
bool tape::FileTape::seekBackwards() { return true; } bool tape::FileTape::seek_backwards() { return true; }
int32_t tape::FileTape::read() { return 0; } int32_t tape::FileTape::read() { return 0; }
void tape::FileTape::write(int32_t data) {} void tape::FileTape::write(int32_t data) {}
tape::FileTape::~FileTape() { this->file_.close(); } tape::FileTape::~FileTape() { this->file.close(); }

View file

@ -1,7 +1,7 @@
#include <iostream> #include <iostream>
#include <ostream> #include <ostream>
int main(int /*argc*/, char * /*argv*/[]) { int main(int argc, char *argv[]) {
std::cout << "Hello, World!" << std::endl; std::cout << "Hello, World!" << std::endl;
return 0; return 0;
} }

18
src/tapeconfig.cpp Normal file
View file

@ -0,0 +1,18 @@
#include "tapeconfig.h"
#include "filetape.h"
#include <string>
struct CommandLineArgs {
std::string config_file_path;
tape::FileTapeSettings settings;
};
// const static struct Options COMMAND_LINE_OPTIONS[]{};
CommandLineArgs parse_command_line(int argc, char **argv) {
return CommandLineArgs{};
}
tape::FileTapeSettings tape::init_settings(int argc, char **argv) {
return FileTapeSettings{};
}