Skip to content

Commit c783cda

Browse files
authored
add a workflow to check clang-format (#79)
1 parent 6815d4b commit c783cda

23 files changed

+116
-64
lines changed

.github/workflows/format.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
on:
2+
push:
3+
branches: master
4+
pull_request:
5+
branches:
6+
- master
7+
8+
name: format_check
9+
10+
jobs:
11+
format_check:
12+
runs-on: ubuntu-18.04
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Install ClangFormat
17+
run: sudo apt-get install -y clang-format-10
18+
19+
- name: Run ClangFormat
20+
run: make format clang_format=clang-format-10
21+
22+
- name: Check for a non-empty diff
23+
run: git diff-files -U --exit-code
24+

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ test: all
1010

1111
clean:
1212
@Rscript -e 'devtools::clean_dll()'
13+
14+
clang_format=`which clang-format`
15+
format: $(shell find . -name *.hpp) $(shell find . -name *.cpp)
16+
ifeq ($(findstring version 10,$(shell ${clang_format} --version 2>/dev/null)),)
17+
@echo "clang-format 10 is required"
18+
else
19+
@${clang_format} -i $?
20+
endif

cpp11test/src/test-list.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ context("list-C++") {
5959
}
6060

6161
test_that("list::iterator uses VECTOR_ELT") {
62-
cpp11::writable::list x({
63-
cpp11::writable::integers({1, 2})
64-
});
62+
cpp11::writable::list x({cpp11::writable::integers({1, 2})});
6563
cpp11::integers first(*x.begin());
6664
expect_true(first[0] == 1);
6765
expect_true(first[1] == 2);

cpp11test/src/test-list_of.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#include <testthat.h>
2-
#include "cpp11/strings.hpp"
32
#include "cpp11/doubles.hpp"
43
#include "cpp11/list.hpp"
54
#include "cpp11/list_of.hpp"
5+
#include "cpp11/strings.hpp"
66

77
context("list_of-C++") {
88
test_that("list_of works") {
99
using namespace cpp11::literals;
1010

1111
cpp11::writable::list x({"x"_nm = cpp11::writable::doubles({1., 2., 3.}),
12-
"y"_nm = cpp11::writable::doubles({4., 5., 6.})});
12+
"y"_nm = cpp11::writable::doubles({4., 5., 6.})});
1313

1414
cpp11::list_of<cpp11::doubles> res(x);
1515

@@ -24,7 +24,7 @@ context("list_of-C++") {
2424
using namespace cpp11::literals;
2525

2626
cpp11::writable::list x({"x"_nm = cpp11::writable::doubles({1., 2., 3.}),
27-
"y"_nm = cpp11::writable::doubles({4., 5., 6.})});
27+
"y"_nm = cpp11::writable::doubles({4., 5., 6.})});
2828

2929
cpp11::writable::list_of<cpp11::writable::doubles> res(x);
3030

inst/include/cpp11.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#include "cpp11/matrix.hpp"
1717
#include "cpp11/named_arg.hpp"
1818
#include "cpp11/protect.hpp"
19+
#include "cpp11/r_string.hpp"
20+
#include "cpp11/r_vector.hpp"
1921
#include "cpp11/raws.hpp"
2022
#include "cpp11/sexp.hpp"
21-
#include "cpp11/r_string.hpp"
2223
#include "cpp11/strings.hpp"
23-
#include "cpp11/r_vector.hpp"

inst/include/cpp11/attribute_proxy.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#pragma once
22

3-
#include <initializer_list> // for initializer_list
4-
#include <string> // for string, basic_string
3+
#include <initializer_list> // for initializer_list
4+
#include <string> // for string, basic_string
5+
56
#include "cpp11/R.hpp" // for SEXP, SEXPREC, Rf_install, PROTECT, Rf_...
67
#include "cpp11/as.hpp" // for as_sexp
78
#include "cpp11/protect.hpp" // for protect, safe, protect::function

inst/include/cpp11/data_frame.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#pragma once
22

3-
#include <cstdlib> // for abs
4-
#include <initializer_list> // for initializer_list
5-
#include <string> // for string, basic_string
6-
#include <utility> // for move
3+
#include <cstdlib> // for abs
4+
#include <cstdlib>
5+
#include <initializer_list> // for initializer_list
6+
#include <string> // for string, basic_string
7+
#include <utility> // for move
8+
79
#include "R_ext/Arith.h" // for NA_INTEGER
810
#include "cpp11/R.hpp" // for Rf_xlength, SEXP, SEXPREC, INTEGER
911
#include "cpp11/attribute_proxy.hpp" // for attribute_proxy
1012
#include "cpp11/list.hpp" // for list, r_vector<>::r_vector, r_v...
1113
#include "cpp11/r_vector.hpp" // for r_vector
1214

13-
#include <cstdlib>
14-
1515
namespace cpp11 {
1616

1717
class named_arg;

inst/include/cpp11/doubles.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#pragma once
22

3-
#include <algorithm> // for min
4-
#include <array> // for array
5-
#include <initializer_list> // for initializer_list
3+
#include <algorithm> // for min
4+
#include <array> // for array
5+
#include <initializer_list> // for initializer_list
6+
67
#include "R_ext/Arith.h" // for ISNA
78
#include "cpp11/R.hpp" // for SEXP, SEXPREC, Rf_allocVector, REAL
89
#include "cpp11/as.hpp" // for as_sexp

inst/include/cpp11/environment.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

3-
#include <string> // for string, basic_string
3+
#include <string> // for string, basic_string
4+
45
#include "Rversion.h" // for R_VERSION, R_Version
56
#include "cpp11/R.hpp" // for SEXP, SEXPREC, Rf_install, Rf_findVarIn...
67
#include "cpp11/as.hpp" // for as_sexp

inst/include/cpp11/external_pointer.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#pragma once
22

3-
#include <cstddef> // for nullptr_t, NULL
4-
#include <memory> // for bad_weak_ptr
5-
#include <type_traits> // for add_lvalue_reference
3+
#include <cstddef> // for nullptr_t, NULL
4+
#include <memory> // for bad_weak_ptr
5+
#include <type_traits> // for add_lvalue_reference
6+
67
#include "cpp11/R.hpp" // for SEXP, SEXPREC, TYPEOF, R_NilValue, R_C...
78
#include "cpp11/protect.hpp" // for protect, safe, protect::function
89
#include "cpp11/r_vector.hpp" // for type_error

0 commit comments

Comments
 (0)