Skip to content

Commit

Permalink
clang-format: Handle Objective-C(++) in config
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Mar 15, 2023
1 parent b3a199f commit 7ecbfae
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
31 changes: 30 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ TabWidth: 8
UseTab: Never
# A ColumnLimit > 0 causes clang-format to unbreaks all short lines,
# which is undesired here.
# If the line length exceeds 100, "ColumnLimit: 80" is used in scripts/line-length.py
# If the line length exceeds 100, "ColumnLimit: 80" is used in tools/clang_format.py
ColumnLimit: 0
---
Language: Cpp
Expand Down Expand Up @@ -40,6 +40,35 @@ StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
---
Language: ObjC
# We exclude Objective-C(++) from the second line-wrapping pass in tools/clang_format.py
# since this pass only applies C++ rules and therefore include the ColumnLimit in the
# 'main' clang-format config here.
ColumnLimit: 80
# Apply the same customizations that we use for Cpp to ObjC.
AccessModifierOffset: -2
AlignAfterOpenBracket: DontAlign
AlignOperands: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
BinPackArguments: false
BinPackParameters: false
ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 8
IndentCaseLabels: false
DerivePointerAlignment: false
SpaceAfterTemplateKeyword: false
SpacesBeforeTrailingComments: 1
StatementMacros:
- Q_DECLARE_FLAGS
- Q_DECLARE_METATYPE
- Q_DECLARE_OPERATORS_FOR_FLAGS
- Q_OBJECT
- Q_PROPERTY
- Q_UNUSED
- QT_REQUIRE_VERSION
---
Language: JavaScript
# Don't format .js files yet
DisableFormat: true
Expand Down
9 changes: 6 additions & 3 deletions tools/clang_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def get_clang_format_config_with_columnlimit(rootdir, limit):
text=True,
)
proc.check_returncode()

return re.sub(
r"(ColumnLimit:\s*)\d+", r"\g<1>{}".format(BREAK_BEFORE), proc.stdout
r"(ColumnLimit:\s*)\d+", r"\g<1>{}".format(limit), proc.stdout
)


Expand Down Expand Up @@ -119,14 +120,16 @@ def main(argv: typing.Optional[typing.List[str]] = None) -> int:
for changed_file in files_with_added_lines:
run_clang_format_on_lines(rootdir, changed_file)

# Second pass: Wrap long added/changed lines using clang-format
# Second pass: Wrap long added/changed lines in C++ using clang-format
logger.info("Second pass: Breaking long added/changed lines...")
files_with_long_added_lines = githelper.get_changed_lines_grouped(
from_ref=args.from_ref,
to_ref=args.to_ref,
filter_lines=lambda line: line.added
and len(line.text) > LINE_LENGTH_THRESHOLD,
include_files=args.files,
include_files=[
file for file in args.files if re.search(r"\.(?:cpp|h)$", file)
],
)
config = get_clang_format_config_with_columnlimit(rootdir, BREAK_BEFORE)
with tempfile.TemporaryDirectory(prefix="clang-format") as tempdir:
Expand Down

0 comments on commit 7ecbfae

Please sign in to comment.