Skip to content

Commit

Permalink
Add clang-format linter to descriptor files
Browse files Browse the repository at this point in the history
Modifies the c and cpp descriptor files so clang-format is added to them.

In addition this modifies the c and cpp test files so clang-format now
passes.
  • Loading branch information
daltonv committed Nov 8, 2023
1 parent 418e3e3 commit 2addd28
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .automation/test/c/c_bad_01.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <iostream>

int main() {
int main()
{
std::cout << "Hello World!";
return 0;
}
3 changes: 2 additions & 1 deletion .automation/test/c/c_bad_02.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <iostream>

int main() {
int main()
{
std::cout << "Hello World!";
return 0;
}
6 changes: 3 additions & 3 deletions .automation/test/c/c_good_01.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <stdio.h>
int main() {
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
}
6 changes: 3 additions & 3 deletions .automation/test/c/c_good_02.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <stdio.h>
int main() {
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
}
6 changes: 3 additions & 3 deletions .automation/test/cpp/cpp_good_01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <stdio.h>
int main() {
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
}
6 changes: 3 additions & 3 deletions .automation/test/cpp/cpp_good_02.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <stdio.h>
int main() {
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-linter.yml file, or with `oxsecurity/megalinter:beta` docker image

- New linters
- Add [clang-format](https://releases.llvm.org/16.0.0/tools/clang/docs/ClangFormat.html) c & cpp formatting linter

- Allow to use value `any` to always activate a linter who as a **_DIRECTORY** variable. Example: `KUBERNETES_DIRECTORY: any`
- New flavor **c_cpp**: New flavor for pure C/C++ projects

Expand Down
30 changes: 30 additions & 0 deletions megalinter/descriptors/c.megalinter-descriptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,33 @@ linters:
install:
pip:
- cpplint

- linter_name: clang-format
name: C_CLANG_FORMAT
descriptor_flavors:
- c_cpp
linter_url: https://releases.llvm.org/16.0.0/tools/clang/docs/ClangFormat.html
linter_repo: https://github.com/llvm/llvm-project
linter_rules_url: https://releases.llvm.org/16.0.0/tools/clang/docs/ClangFormat.html
linter_rules_inline_disable_url: https://releases.llvm.org/16.0.0/tools/clang/docs/ClangFormatStyleOptions.html#disabling-formatting-on-a-piece-of-code
cli_lint_mode: list_of_files
cli_help_arg_name: "--help"
cli_lint_extra_args:
- "--Werror"
- "--dry-run"
config_file_name: .clang-format
cli_config_arg_name: "--style"
cli_lint_errors_count: regex_count
cli_lint_errors_regex: "code should be clang-formatted"
examples:
- "clang-format --Werror --dry-run myfile.c"
install:
apk:
- clang16-extra-tools
ide:
vscode:
name: Clang-Format
url: https://marketplace.visualstudio.com/items?itemName=xaver.clang-format
emacs:
name: clang-format
url: https://releases.llvm.org/16.0.0/tools/clang/docs/ClangFormat.html#emacs-integration
30 changes: 30 additions & 0 deletions megalinter/descriptors/cpp.megalinter-descriptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,33 @@ linters:
install:
pip:
- cpplint

- linter_name: clang-format
name: CPP_CLANG_FORMAT
descriptor_flavors:
- c_cpp
linter_url: https://releases.llvm.org/16.0.0/tools/clang/docs/ClangFormat.html
linter_repo: https://github.com/llvm/llvm-project
linter_rules_url: https://releases.llvm.org/16.0.0/tools/clang/docs/ClangFormat.html
linter_rules_inline_disable_url: https://releases.llvm.org/16.0.0/tools/clang/docs/ClangFormatStyleOptions.html#disabling-formatting-on-a-piece-of-code
cli_lint_mode: list_of_files
cli_help_arg_name: "--help"
cli_lint_extra_args:
- "--Werror"
- "--dry-run"
config_file_name: .clang-format
cli_config_arg_name: "--style"
cli_lint_errors_count: regex_count
cli_lint_errors_regex: "code should be clang-formatted"
examples:
- "clang-format --Werror --dry-run myfile.cpp"
install:
apk:
- clang16-extra-tools
ide:
vscode:
name: Clang-Format
url: https://marketplace.visualstudio.com/items?itemName=xaver.clang-format
emacs:
name: clang-format
url: https://releases.llvm.org/16.0.0/tools/clang/docs/ClangFormat.html#emacs-integration

0 comments on commit 2addd28

Please sign in to comment.