Skip to content

Commit

Permalink
chore: simplify clang-format and update ruff (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig authored Apr 28, 2024
1 parent 69432ce commit 77bd12c
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 188 deletions.
18 changes: 6 additions & 12 deletions .github/workflows/lint_and_format_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,13 @@ jobs:
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4

- name: Install clang-format
run: |
sudo apt update && sudo apt install clang-format-15 -y
sudo ln -sf /usr/bin/clang-format-15 /usr/bin/clang-format
- name: Build with Lint and Format Check
run: |
cmake -B build && cmake --build build
env:
CXX: clang++-14
LINT_AND_FORMAT_CHECK: true
- name: Run clang-format
uses: jidicula/clang-format-action@f62da5e3d3a2d88ff364771d9d938773a618ab5e # v4.11.0
with:
clang-format-version: '17'
fallback-style: 'Google'

- uses: chartboost/ruff-action@e18ae971ccee1b2d7bbef113930f00c670b78da4 # v1.0.0
name: Lint with Ruff
with:
version: 0.0.263
version: 0.4.2
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ set(ADA_LIB_SOVERSION "2" CACHE STRING "ada library soversion")

include(GNUInstallDirs)

include (cmake/clang-format.cmake)

include(CTest)
include(cmake/ada-flags.cmake)

Expand Down
41 changes: 0 additions & 41 deletions cmake/clang-format.cmake

This file was deleted.

62 changes: 33 additions & 29 deletions include/ada/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -974,8 +974,9 @@ struct expected_operations_base<void, E> : expected_storage_base<void, E> {
// This class manages conditionally having a trivial copy constructor
// This specialization is for when T and E are trivially copy constructible
template <class T, class E,
bool = is_void_or<T, TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T)>::
value &&TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(E)::value>
bool = is_void_or<T, TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(
T)>::value &&
TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(E)::value>
struct expected_copy_base : expected_operations_base<T, E> {
using expected_operations_base<T, E>::expected_operations_base;
};
Expand Down Expand Up @@ -1007,8 +1008,9 @@ struct expected_copy_base<T, E, false> : expected_operations_base<T, E> {
// move constructible
#ifndef TL_EXPECTED_GCC49
template <class T, class E,
bool = is_void_or<T, std::is_trivially_move_constructible<T>>::value
&&std::is_trivially_move_constructible<E>::value>
bool =
is_void_or<T, std::is_trivially_move_constructible<T>>::value &&
std::is_trivially_move_constructible<E>::value>
struct expected_move_base : expected_copy_base<T, E> {
using expected_copy_base<T, E>::expected_copy_base;
};
Expand Down Expand Up @@ -1037,14 +1039,16 @@ struct expected_move_base<T, E, false> : expected_copy_base<T, E> {
};

// This class manages conditionally having a trivial copy assignment operator
template <class T, class E,
bool = is_void_or<
T, conjunction<TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T),
TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T),
TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T)>>::value
&&TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(E)::value
&&TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(E)::value
&&TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(E)::value>
template <
class T, class E,
bool =
is_void_or<
T, conjunction<TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T),
TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T),
TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T)>>::value &&
TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(E)::value &&
TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(E)::value &&
TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(E)::value>
struct expected_copy_assign_base : expected_move_base<T, E> {
using expected_move_base<T, E>::expected_move_base;
};
Expand All @@ -1071,14 +1075,15 @@ struct expected_copy_assign_base<T, E, false> : expected_move_base<T, E> {
// to make do with a non-trivial move assignment operator even if T is trivially
// move assignable
#ifndef TL_EXPECTED_GCC49
template <class T, class E,
bool =
is_void_or<T, conjunction<std::is_trivially_destructible<T>,
std::is_trivially_move_constructible<T>,
std::is_trivially_move_assignable<T>>>::
value &&std::is_trivially_destructible<E>::value
&&std::is_trivially_move_constructible<E>::value
&&std::is_trivially_move_assignable<E>::value>
template <
class T, class E,
bool = is_void_or<
T, conjunction<std::is_trivially_destructible<T>,
std::is_trivially_move_constructible<T>,
std::is_trivially_move_assignable<T>>>::value &&
std::is_trivially_destructible<E>::value &&
std::is_trivially_move_constructible<E>::value &&
std::is_trivially_move_assignable<E>::value>
struct expected_move_assign_base : expected_copy_assign_base<T, E> {
using expected_copy_assign_base<T, E>::expected_copy_assign_base;
};
Expand All @@ -1100,10 +1105,10 @@ struct expected_move_assign_base<T, E, false>
expected_move_assign_base &operator=(const expected_move_assign_base &rhs) =
default;

expected_move_assign_base &
operator=(expected_move_assign_base &&rhs) noexcept(
std::is_nothrow_move_constructible<T>::value
&&std::is_nothrow_move_assignable<T>::value) {
expected_move_assign_base &operator=(
expected_move_assign_base
&&rhs) noexcept(std::is_nothrow_move_constructible<T>::value &&
std::is_nothrow_move_assignable<T>::value) {
this->assign(std::move(rhs));
return *this;
}
Expand Down Expand Up @@ -1992,11 +1997,10 @@ class expected : private detail::expected_move_assign_base<T, E>,
detail::is_swappable<OE>::value &&
(std::is_nothrow_move_constructible<OT>::value ||
std::is_nothrow_move_constructible<OE>::value)>
swap(expected &rhs) noexcept(
std::is_nothrow_move_constructible<T>::value
&&detail::is_nothrow_swappable<T>::value
&&std::is_nothrow_move_constructible<E>::value
&&detail::is_nothrow_swappable<E>::value) {
swap(expected &rhs) noexcept(std::is_nothrow_move_constructible<T>::value &&
detail::is_nothrow_swappable<T>::value &&
std::is_nothrow_move_constructible<E>::value &&
detail::is_nothrow_swappable<E>::value) {
if (has_value() && rhs.has_value()) {
swap_where_both_have_value(rhs, typename std::is_void<T>::type{});
} else if (!has_value() && rhs.has_value()) {
Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[tool.ruff]
select = [
'lint.select' = [
"C90", # McCabe cyclomatic complexity
"E", # pycodestyle
"F", # Pyflakes
Expand All @@ -22,8 +21,8 @@ exclude = [
"docs",
"tests",
]
ignore = [
'lint.ignore' = [
"E722" # Do not use bare `except`
]
line-length = 120
target-version = "py37"
target-version = "py312"
3 changes: 1 addition & 2 deletions singleheader/amalgamate.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def dofile(fid: str, prepath: str, filename: str) -> None:
try:
timestamp = subprocess.run(['git', 'show', '-s', '--format=%ci', 'HEAD'],
stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
except:
except Exception:
print("git not found, timestamp based on current time")
timestamp = str(datetime.datetime.now())
print(f"timestamp is {timestamp}")
Expand Down Expand Up @@ -143,4 +143,3 @@ def dofile(fid: str, prepath: str, filename: str) -> None:

print(f"Files have been written to directory: {AMALGAMATE_OUTPUT_PATH}/")
print("Done with all files generation.")

2 changes: 1 addition & 1 deletion src/unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ ada_really_inline bool has_tabs_or_newline(
ada_really_inline bool has_tabs_or_newline(
std::string_view user_input) noexcept {
auto has_zero_byte = [](uint64_t v) {
return ((v - 0x0101010101010101) & ~(v)&0x8080808080808080);
return ((v - 0x0101010101010101) & ~(v) & 0x8080808080808080);
};
size_t i = 0;
uint64_t mask1 = broadcast('\r');
Expand Down
91 changes: 0 additions & 91 deletions tools/lint_and_format.py

This file was deleted.

2 changes: 1 addition & 1 deletion tools/release/lib/tests/test_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def test_get_last_release():

# Should return None (in case there are no releases yet)
last_release = release.get_last_release([])
assert last_release == None
assert last_release is None


def test_get_old_contributors():
Expand Down
10 changes: 5 additions & 5 deletions tools/run-clangcldocker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
MAINSOURCE=$SCRIPTPATH/..
ALL_ADA_FILES=$(cd $MAINSOURCE && git ls-tree --full-tree --name-only -r HEAD | grep -e ".*\.\(c\|h\|cc\|cpp\|hh\)\$" | grep -vFf clang-format-ignore.txt)

if clang-format-15 --version 2>/dev/null | grep -qF 'version 15.'; then
cd $MAINSOURCE; clang-format-15 --style=file --verbose -i "$@" $ALL_ADA_FILES
if clang-format-17 --version 2>/dev/null | grep -qF 'version 17.'; then
cd $MAINSOURCE; clang-format-17 --style=file --verbose -i "$@" $ALL_ADA_FILES
exit 0
elif clang-format --version 2>/dev/null | grep -qF 'version 15.'; then
elif clang-format --version 2>/dev/null | grep -qF 'version 17.'; then
cd $MAINSOURCE; clang-format --style=file --verbose -i "$@" $ALL_ADA_FILES
exit 0
fi
Expand All @@ -17,6 +17,6 @@ command -v docker >/dev/null 2>&1 || { echo >&2 "Please install docker. E.g., go
docker info >/dev/null 2>&1 || { echo >&2 "Docker server is not running? type 'docker info'."; exit 1; }

if [ -t 0 ]; then DOCKER_ARGS=-it; fi
docker pull kszonek/clang-format-15
docker pull kszonek/clang-format-17

docker run --rm $DOCKER_ARGS -v "$MAINSOURCE":"$MAINSOURCE":Z -w "$MAINSOURCE" -u "$(id -u $USER):$(id -g $USER)" kszonek/clang-format-15 --style=file --verbose -i "$@" $ALL_ADA_FILES
docker run --rm $DOCKER_ARGS -v "$MAINSOURCE":"$MAINSOURCE":Z -w "$MAINSOURCE" -u "$(id -u $USER):$(id -g $USER)" kszonek/clang-format-17 --style=file --verbose -i "$@" $ALL_ADA_FILES

0 comments on commit 77bd12c

Please sign in to comment.