From 9bc991fd112ae8ac41aca1eed4a9c5189c428a41 Mon Sep 17 00:00:00 2001 From: Dalton Verhagen Date: Wed, 8 Nov 2023 16:13:28 +0100 Subject: [PATCH] Fix issue with clang-format's config arg 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. --- megalinter/Linter.py | 4 +++- megalinter/descriptors/c.megalinter-descriptor.yml | 2 +- megalinter/descriptors/cpp.megalinter-descriptor.yml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/megalinter/Linter.py b/megalinter/Linter.py index c70ca3a68e3..0a6af015724 100644 --- a/megalinter/Linter.py +++ b/megalinter/Linter.py @@ -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] diff --git a/megalinter/descriptors/c.megalinter-descriptor.yml b/megalinter/descriptors/c.megalinter-descriptor.yml index abb0dfc8439..f3230d85930 100644 --- a/megalinter/descriptors/c.megalinter-descriptor.yml +++ b/megalinter/descriptors/c.megalinter-descriptor.yml @@ -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: diff --git a/megalinter/descriptors/cpp.megalinter-descriptor.yml b/megalinter/descriptors/cpp.megalinter-descriptor.yml index b7cacb90fc7..7701147c144 100644 --- a/megalinter/descriptors/cpp.megalinter-descriptor.yml +++ b/megalinter/descriptors/cpp.megalinter-descriptor.yml @@ -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: