Skip to content

Commit

Permalink
clang-format: DontAlignAfterOpenBracket only for pydrake (#10118)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwnimmer-tri committed Nov 30, 2018
1 parent 785463d commit 98d71e3
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 12 deletions.
5 changes: 0 additions & 5 deletions .clang-format
Expand Up @@ -11,11 +11,6 @@ Language: Cpp
DerivePointerAlignment: false
PointerAlignment: Left

# When a function signature's parameters or a function call's arguments need to
# wrap onto another line, indent by four spaces -- do not whitespace castle all
# the way over to the open-paren.
AlignAfterOpenBracket: DontAlign

# Specify the #include statement order. This implements the order mandated by
# the Google C++ Style Guide: related header, C headers, C++ headers, library
# headers, and finally the project headers.
Expand Down
58 changes: 58 additions & 0 deletions bindings/pydrake/.clang-format
@@ -0,0 +1,58 @@
# -*- yaml -*-

# This portion of the file contains settings that are local to the
# //bindings/... code, rather than all of Drake.

# When a function signature's parameters or a function call's arguments need to
# wrap onto another line, indent by four spaces -- do not whitespace castle all
# the way over to the open-paren.
AlignAfterOpenBracket: DontAlign

# -----------------------------------------------------------------------------
# The contents of the root dotfile should be exactly copied below this point.
# -----------------------------------------------------------------------------
# -*- yaml -*-

# This file determines clang-format's style settings; for details, refer to
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html

BasedOnStyle: Google

Language: Cpp

# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Left

# Specify the #include statement order. This implements the order mandated by
# the Google C++ Style Guide: related header, C headers, C++ headers, library
# headers, and finally the project headers.
#
# To obtain updated lists of system headers used in the below expressions, see:
# http://stackoverflow.com/questions/2027991/list-of-standard-header-files-in-c-and-c/2029106#2029106.
IncludeCategories:
# Spacers used by drake/tools/formatter.py.
- Regex: '^<clang-format-priority-15>$'
Priority: 15
- Regex: '^<clang-format-priority-25>$'
Priority: 25
- Regex: '^<clang-format-priority-35>$'
Priority: 35
- Regex: '^<clang-format-priority-45>$'
Priority: 45
# C system headers.
- Regex: '^[<"](aio|arpa/inet|assert|complex|cpio|ctype|curses|dirent|dlfcn|errno|fcntl|fenv|float|fmtmsg|fnmatch|ftw|glob|grp|iconv|inttypes|iso646|langinfo|libgen|limits|locale|math|monetary|mqueue|ndbm|netdb|net/if|netinet/in|netinet/tcp|nl_types|poll|pthread|pwd|regex|sched|search|semaphore|setjmp|signal|spawn|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|strings|stropts|sys/ipc|syslog|sys/mman|sys/msg|sys/resource|sys/select|sys/sem|sys/shm|sys/socket|sys/stat|sys/statvfs|sys/time|sys/times|sys/types|sys/uio|sys/un|sys/utsname|sys/wait|tar|term|termios|tgmath|threads|time|trace|uchar|ulimit|uncntrl|unistd|utime|utmpx|wchar|wctype|wordexp)\.h[">]$'
Priority: 20
# C++ system headers (as of C++14).
- Regex: '^[<"](algorithm|array|atomic|bitset|cassert|ccomplex|cctype|cerrno|cfenv|cfloat|chrono|cinttypes|ciso646|climits|clocale|cmath|codecvt|complex|condition_variable|csetjmp|csignal|cstdalign|cstdarg|cstdbool|cstddef|cstdint|cstdio|cstdlib|cstring|ctgmath|ctime|cuchar|cwchar|cwctype|deque|exception|forward_list|fstream|functional|future|initializer_list|iomanip|ios|iosfwd|iostream|istream|iterator|limits|list|locale|map|memory|mutex|new|numeric|ostream|queue|random|ratio|regex|scoped_allocator|set|shared_mutex|sstream|stack|stdexcept|streambuf|string|strstream|system_error|thread|tuple|type_traits|typeindex|typeinfo|unordered_map|unordered_set|utility|valarray|vector)[">]$'
Priority: 30
# Other libraries' h files (with angles).
- Regex: '^<'
Priority: 40
# Your project's h files.
- Regex: '^"drake'
Priority: 50
# Other libraries' h files (with quotes).
- Regex: '^"'
Priority: 41

14 changes: 14 additions & 0 deletions bindings/pydrake/BUILD.bazel
Expand Up @@ -26,6 +26,10 @@ package(default_visibility = [
"//bindings:__subpackages__",
])

exports_files([
".clang-format",
])

# This determines how `PYTHONPATH` is configured, and how to install the
# bindings.
PACKAGE_INFO = get_pybind_package_info(base_package = "//bindings")
Expand Down Expand Up @@ -434,7 +438,17 @@ drake_py_binary(
],
)

drake_py_unittest(
name = "dot_clang_format_test",
data = [
"//:.clang-format",
"//bindings/pydrake:.clang-format",
],
tags = ["lint"],
)

add_lint_tests(
cpplint_data = ["//bindings/pydrake:.clang-format"],
enable_clang_format_lint = True,
python_lint_extra_srcs = [
":test/all_install_test.py",
Expand Down
1 change: 1 addition & 0 deletions bindings/pydrake/doc/BUILD.bazel
Expand Up @@ -36,6 +36,7 @@ drake_py_binary(
)

add_lint_tests(
cpplint_data = ["//bindings/pydrake:.clang-format"],
enable_clang_format_lint = True,
python_lint_exclude = [":conf.py"],
)
1 change: 1 addition & 0 deletions bindings/pydrake/examples/BUILD.bazel
Expand Up @@ -184,5 +184,6 @@ drake_py_unittest(
)

add_lint_tests(
cpplint_data = ["//bindings/pydrake:.clang-format"],
enable_clang_format_lint = True,
)
1 change: 1 addition & 0 deletions bindings/pydrake/examples/multibody/BUILD.bazel
Expand Up @@ -68,5 +68,6 @@ install(
)

add_lint_tests(
cpplint_data = ["//bindings/pydrake:.clang-format"],
enable_clang_format_lint = True,
)
1 change: 1 addition & 0 deletions bindings/pydrake/maliput/BUILD.bazel
Expand Up @@ -98,5 +98,6 @@ drake_py_unittest(
)

add_lint_tests(
cpplint_data = ["//bindings/pydrake:.clang-format"],
enable_clang_format_lint = True,
)
1 change: 1 addition & 0 deletions bindings/pydrake/manipulation/BUILD.bazel
Expand Up @@ -105,5 +105,6 @@ install(
)

add_lint_tests(
cpplint_data = ["//bindings/pydrake:.clang-format"],
enable_clang_format_lint = True,
)
1 change: 1 addition & 0 deletions bindings/pydrake/multibody/BUILD.bazel
Expand Up @@ -283,5 +283,6 @@ drake_py_unittest(
)

add_lint_tests(
cpplint_data = ["//bindings/pydrake:.clang-format"],
enable_clang_format_lint = True,
)
1 change: 1 addition & 0 deletions bindings/pydrake/solvers/BUILD.bazel
Expand Up @@ -186,5 +186,6 @@ drake_py_unittest(
)

add_lint_tests(
cpplint_data = ["//bindings/pydrake:.clang-format"],
enable_clang_format_lint = True,
)
1 change: 1 addition & 0 deletions bindings/pydrake/systems/BUILD.bazel
Expand Up @@ -444,5 +444,6 @@ drake_py_binary(
)

add_lint_tests(
cpplint_data = ["//bindings/pydrake:.clang-format"],
enable_clang_format_lint = True,
)
24 changes: 24 additions & 0 deletions bindings/pydrake/test/dot_clang_format_test.py
@@ -0,0 +1,24 @@
import unittest


class TestDotfile(unittest.TestCase):
def setUp(self):
self.maxDiff = None

def test_dotfile_consistency(self):
# Drake's bindings/pydrake/.clang-format file should be a prologue atop
# the root .clang-format file.
with open(".clang-format") as f:
root_contents = f.readlines()
with open("bindings/pydrake/.clang-format") as f:
bindings_contents = f.readlines()

# The bindings file should be longer.
self.assertGreater(len(bindings_contents), len(root_contents))
offset = len(bindings_contents) - len(root_contents)
assert offset > 0

# Every line in root should appear in bindings.
self.assertMultiLineEqual(
"".join(root_contents),
"".join(bindings_contents[offset:]))
1 change: 1 addition & 0 deletions bindings/pydrake/third_party/BUILD.bazel
Expand Up @@ -76,5 +76,6 @@ install(
)

add_lint_tests(
cpplint_data = ["//bindings/pydrake:.clang-format"],
enable_clang_format_lint = True,
)
8 changes: 4 additions & 4 deletions tools/vector_gen/test/goal/sample_translator.cc
Expand Up @@ -16,8 +16,8 @@ SampleTranslator::AllocateOutputVector() const {
return std::make_unique<Sample<double>>();
}

void SampleTranslator::Serialize(double time,
const drake::systems::VectorBase<double>& vector_base,
void SampleTranslator::Serialize(
double time, const drake::systems::VectorBase<double>& vector_base,
std::vector<uint8_t>* lcm_message_bytes) const {
const auto* const vector = dynamic_cast<const Sample<double>*>(&vector_base);
DRAKE_DEMAND(vector != nullptr);
Expand All @@ -32,8 +32,8 @@ void SampleTranslator::Serialize(double time,
message.encode(lcm_message_bytes->data(), 0, lcm_message_length);
}

void SampleTranslator::Deserialize(const void* lcm_message_bytes,
int lcm_message_length,
void SampleTranslator::Deserialize(
const void* lcm_message_bytes, int lcm_message_length,
drake::systems::VectorBase<double>* vector_base) const {
DRAKE_DEMAND(vector_base != nullptr);
auto* const my_vector = dynamic_cast<Sample<double>*>(vector_base);
Expand Down
6 changes: 3 additions & 3 deletions tools/vector_gen/test/goal/sample_translator.h
Expand Up @@ -26,10 +26,10 @@ class SampleTranslator final
std::unique_ptr<drake::systems::BasicVector<double>> AllocateOutputVector()
const final;
void Deserialize(const void* lcm_message_bytes, int lcm_message_length,
drake::systems::VectorBase<double>* vector_base) const final;
drake::systems::VectorBase<double>* vector_base) const final;
void Serialize(double time,
const drake::systems::VectorBase<double>& vector_base,
std::vector<uint8_t>* lcm_message_bytes) const final;
const drake::systems::VectorBase<double>& vector_base,
std::vector<uint8_t>* lcm_message_bytes) const final;
};

} // namespace test
Expand Down

0 comments on commit 98d71e3

Please sign in to comment.