Skip to content

Commit

Permalink
Fix issue with clang-format's config arg
Browse files Browse the repository at this point in the history
clang-format has a very special syntax for passing a config file as an arg.
You must use --style=:myconfig.file.

To make this work with megalinter I updated the clang descriptor files
to correctly list the config file arg as "--style=:" and modified
the Linter.py file to not add a space to any config file args ending
in ":" as clang-format cannot have a space for its cli syntax here.
  • Loading branch information
daltonv committed Nov 19, 2023
1 parent badd723 commit 8dc7234
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion megalinter/Linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,9 @@ def build_lint_command(self, file=None) -> list:
self.final_config_file = self.final_config_file.replace(
self.workspace, DEFAULT_DOCKER_WORKSPACE_DIR
)
if self.cli_config_arg_name.endswith("="):
if self.cli_config_arg_name.endswith(
"="
) or self.cli_config_arg_name.endswith(":"):
cmd += [self.cli_config_arg_name + self.final_config_file]
elif self.cli_config_arg_name != "":
cmd += [self.cli_config_arg_name, self.final_config_file]
Expand Down
2 changes: 1 addition & 1 deletion megalinter/descriptors/c.megalinter-descriptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ linters:
- "--Werror"
- "--dry-run"
config_file_name: .clang-format
cli_config_arg_name: "--style"
cli_config_arg_name: "--style=file:"
cli_lint_errors_count: regex_count
cli_lint_errors_regex: "code should be clang-formatted"
examples:
Expand Down
2 changes: 1 addition & 1 deletion megalinter/descriptors/cpp.megalinter-descriptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ linters:
- "--Werror"
- "--dry-run"
config_file_name: .clang-format
cli_config_arg_name: "--style"
cli_config_arg_name: "--style=file:"
cli_lint_errors_count: regex_count
cli_lint_errors_regex: "code should be clang-formatted"
examples:
Expand Down

0 comments on commit 8dc7234

Please sign in to comment.