Skip to content

Commit

Permalink
Formatting (#28)
Browse files Browse the repository at this point in the history
- Add clang-format config
- Add CI job for formatting
  • Loading branch information
bugdea1er authored Apr 14, 2024
1 parent fbef626 commit 5e4ba6a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
22 changes: 22 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -4
AllowShortFunctionsOnASingleLine: Empty

IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^(<tmp)'
CaseSensitive: true
Priority: 1
- Regex: ".*"
CaseSensitive: true
Priority: 2

IndentWidth: 4
InsertBraces: true
KeepEmptyLinesAtTheStartOfBlocks: false
PackConstructorInitializers: Never
PointerAlignment: Left
QualifierAlignment: Left
SpacesBeforeTrailingComments: 4
22 changes: 22 additions & 0 deletions .github/workflows/Lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Lint

on: pull_request

permissions:
contents: read

jobs:
format:
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install clang-format
run: brew install clang-format

- name: Run clang-format
run: |
(find include/tmp -type f; find src tests -name '*.cpp') \
| xargs clang-format -i -style=file --verbose
git diff --color --exit-code
15 changes: 5 additions & 10 deletions src/tmp.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <tmp/directory>
#include <tmp/file>
#include <tmp/fs>
#include <tmp/path>
#include <tmp/file>
#include <tmp/directory>

#include <fstream>
#include <string_view>
Expand All @@ -14,8 +14,8 @@ namespace tmp {
namespace {

/// Options for recursive overwriting copying
const fs::copy_options copy_options = fs::copy_options::recursive
| fs::copy_options::overwrite_existing;
const fs::copy_options copy_options =
fs::copy_options::recursive | fs::copy_options::overwrite_existing;

/// Creates the parent directory of the given path if it does not exist
/// @param path The path for which the parent directory needs to be created
Expand Down Expand Up @@ -104,7 +104,6 @@ std::ofstream stream(const file& file, bool binary, bool append) noexcept {
}
} // namespace


//===----------------------------------------------------------------------===//
// tmp::path implementation
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -162,7 +161,6 @@ void path::move(const fs::path& to) {
release();
}


//===----------------------------------------------------------------------===//
// tmp::file implementation
//===----------------------------------------------------------------------===//
Expand All @@ -186,9 +184,7 @@ file file::copy(const fs::path& path, std::string_view prefix) {

std::ifstream file::read() const {
const fs::path& file = *this;
return binary
? std::ifstream(file, std::ios::binary)
: std::ifstream(file);
return binary ? std::ifstream(file, std::ios::binary) : std::ifstream(file);
}

std::string file::slurp() const {
Expand All @@ -209,7 +205,6 @@ file::~file() noexcept = default;
file::file(file&&) noexcept = default;
file& file::operator=(file&&) noexcept = default;


//===----------------------------------------------------------------------===//
// tmp::directory implementation
//===----------------------------------------------------------------------===//
Expand Down
5 changes: 3 additions & 2 deletions tests/directory_test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <tmp/directory>
#include <tmp/file>

#include <gtest/gtest.h>
#include <tmp/file>

namespace fs = tmp::fs;

Expand Down Expand Up @@ -121,6 +121,7 @@ TEST(DirectoryTest, Copy) {
}
{
const auto tmpfile = tmp::file(PREFIX);
ASSERT_THROW(tmp::directory::copy(tmpfile, PREFIX), fs::filesystem_error);
ASSERT_THROW(tmp::directory::copy(tmpfile, PREFIX),
fs::filesystem_error);
}
}
3 changes: 1 addition & 2 deletions tests/file_test.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <tmp/directory>
#include <tmp/file>

#include <gtest/gtest.h>
#include <tmp/directory>
#include <fstream>

namespace fs = tmp::fs;

Expand Down

0 comments on commit 5e4ba6a

Please sign in to comment.