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
BasedOnStyle: LLVM
IndentWidth: 4

View file

@ -1,39 +1,20 @@
Checks: "*,
-abseil-*,
-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
Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,-modernize-use-trailing-return-type,readability-*'
WarningsAsErrors: '*'
CheckOptions:
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.ClassConstantCase, value: UPPER_CASE }
- { key: readability-identifier-naming.ClassMemberCase, value: lower_case }
- { key: readability-identifier-naming.ClassMethodCase, value: lower_case }
- { key: readability-identifier-naming.EnumCase, value: CamelCase }
- { key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE }
- { key: readability-identifier-naming.FunctionCase, value: lower_case }
- { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE }
- { key: readability-identifier-naming.MemberCase, value: lower_case }
- { key: readability-identifier-naming.MethodCase, value: lower_case }
- { key: readability-identifier-naming.ParameterCase, value: lower_case }
- { key: readability-identifier-naming.StructCase, value: CamelCase }
- { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase }
- { key: readability-identifier-naming.FunctionCase, value: camelBack }
- { key: readability-identifier-naming.UnionCase, value: CamelCase }
- { key: readability-identifier-naming.TypedefCase, value: CamelCase }
- { key: readability-identifier-naming.TypeAliasCase, value: CamelCase }
- { key: readability-identifier-naming.VariableCase, value: lower_case }
- { key: readability-identifier-naming.PrivateMemberSuffix, value: _ }
- { key: readability-identifier-naming.ProtectedMemberSuffix, value: _ }
- { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }
- { key: readability-identifier-naming.EnumConstantCase, value: CamelCase }
- { key: readability-identifier-naming.EnumConstantPrefix, value: k }
- { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase }
- { key: readability-identifier-naming.ConstexprVariablePrefix, value: k }
- { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase }
- { key: readability-identifier-naming.GlobalConstantPrefix, value: k }
- { key: readability-identifier-naming.MemberConstantCase, value: CamelCase }
- { key: readability-identifier-naming.MemberConstantPrefix, value: k }
- { 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)
project(yadro-task VERSION 0.1)
project(yadro-task VERSION 0.1 LANGUAGES CXX)
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})
@ -13,3 +18,4 @@ target_include_directories(${PROJECT_NAME}
${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.
*/
struct FileTapeSettings {
unsigned int readDelayMs;
unsigned int writeDelayMs;
unsigned int seekForwardDelayMs;
unsigned int seekBackwardsDelayMs;
unsigned int read_delay_ms;
unsigned int write_delay_ms;
unsigned int seek_forward_delay_ms;
unsigned int seek_backwards_delay_ms;
};
/**
@ -29,8 +29,8 @@ struct FileTapeSettings {
*/
class FileTape : public Tape {
private:
std::fstream file_;
FileTapeSettings settings_;
std::fstream file;
FileTapeSettings settings;
public:
FileTape &operator=(const FileTape &) = delete;
@ -46,21 +46,21 @@ public:
* @param file_name Name of a file to be opened.
* @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.
*
* @return false if EOF is reached, otherwise true.
*/
bool seekForward() override;
bool seek_forward() override;
/**
* Rewinds the underlying fstream to a previous line.
*
* @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.

View file

@ -30,7 +30,7 @@ public:
* @return false if the next cell doesn't exist (reached end of tape),
* otherwise true.
*/
virtual bool seekForward() = 0;
virtual bool seek_forward() = 0;
/**
* Rewinds the tape one cell backwards.
@ -38,7 +38,7 @@ public:
* @return false if the previous cell doesn't exist (reached beginning of
* tape), otherwise true.
*/
virtual bool seekBackwards() = 0;
virtual bool seek_backwards() = 0;
/**
* Reads data from the current cell.

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 <string>
tape::FileTape::FileTape(const std::string &fileName, FileTapeSettings settings)
: settings_(settings) {
this->file_ = std::fstream(fileName);
tape::FileTape::FileTape(const std::string &file_name,
FileTapeSettings settings)
: 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; }
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 <ostream>
int main(int /*argc*/, char * /*argv*/[]) {
int main(int argc, char *argv[]) {
std::cout << "Hello, World!" << std::endl;
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{};
}