pw_presubmit: Formatting for .java, .js, .proto
Add support for formatting Java, JavaScript, and Protocol Buffers, which
are all supported by clang-format.
Change-Id: I64a9fa7ddd767672751d86d13e9c2b072a134d39
diff --git a/pw_presubmit/py/pw_presubmit/format_code.py b/pw_presubmit/py/pw_presubmit/format_code.py
index dc56d17..8842f4d 100755
--- a/pw_presubmit/py/pw_presubmit/format_code.py
+++ b/pw_presubmit/py/pw_presubmit/format_code.py
@@ -107,12 +107,12 @@
**kwargs).stdout
-def check_c_format(files: Iterable[Path]) -> Dict[Path, str]:
+def clang_format_check(files: Iterable[Path]) -> Dict[Path, str]:
"""Checks formatting; returns {path: diff} for files with bad formatting."""
return _check_files(files, lambda path, _: _clang_format(path))
-def fix_c_format(files: Iterable) -> None:
+def clang_format_fix(files: Iterable) -> None:
"""Fixes formatting for the provided files in place."""
_clang_format('-i', *files)
@@ -251,7 +251,17 @@
C_FORMAT: CodeFormat = CodeFormat(
'C and C++', frozenset(['.h', '.hh', '.hpp', '.c', '.cc', '.cpp']),
- check_c_format, fix_c_format)
+ clang_format_check, clang_format_fix)
+
+PROTO_FORMAT: CodeFormat = CodeFormat('Protocol buffer', ('.proto', ),
+ clang_format_check, clang_format_fix)
+
+JAVA_FORMAT: CodeFormat = CodeFormat('Java', ('.java', ), clang_format_check,
+ clang_format_fix)
+
+JAVASCRIPT_FORMAT: CodeFormat = CodeFormat('JavaScript', ('.js', ),
+ clang_format_check,
+ clang_format_fix)
GO_FORMAT: CodeFormat = CodeFormat('Go', ('.go', ), check_go_format,
fix_go_format)
@@ -278,6 +288,9 @@
CODE_FORMATS: Sequence[CodeFormat] = (
C_FORMAT,
+ JAVA_FORMAT,
+ JAVASCRIPT_FORMAT,
+ PROTO_FORMAT,
GO_FORMAT,
PYTHON_FORMAT,
GN_FORMAT,
diff --git a/pw_protobuf/pw_protobuf_protos/test_protos/full_test.proto b/pw_protobuf/pw_protobuf_protos/test_protos/full_test.proto
index 112161d..07d8995 100644
--- a/pw_protobuf/pw_protobuf_protos/test_protos/full_test.proto
+++ b/pw_protobuf/pw_protobuf_protos/test_protos/full_test.proto
@@ -26,7 +26,6 @@
// A message!
message Pigweed {
-
// Nested messages and enums.
message Pigweed {
enum Binary {