Merge pull request #148 from skrobinson/feat-add-sa-pr-action

Add StaticAnalysis PR Action
This commit is contained in:
Pranav 2022-01-11 09:11:10 -06:00 committed by GitHub
commit fcfbe7141e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 115 additions and 33 deletions

24
.clang-tidy Normal file
View File

@ -0,0 +1,24 @@
Checks:
-*,
readability-*,
-readability-braces-around-statements,
-readability-container-size-empty,
-readability-else-after-return,
-readability-implicit-bool-conversion,
-readability-function-cognitive-complexity,
-readability-magic-numbers,
-readability-named-parameter,
-readability-qualified-auto,
-readability-static-accessed-through-instance,
CheckOptions:
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.ConstexprVariableCase, value: lower_case }
- { key: readability-identifier-naming.FunctionCase, value: lower_case }
- { key: readability-identifier-naming.LocalVariableIgnoredRegexp, value: "^[a-z][a-z_]+" }
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
- { key: readability-identifier-naming.PrivateMemberPrefix, value: m }
- { key: readability-identifier-naming.StructCase, value: lower_case }
- { key: readability-identifier-naming.VariableCase, value: camelBack }
HeaderFilterRegex: '.*'

42
.github/workflows/static_analysis.yml vendored Normal file
View File

@ -0,0 +1,42 @@
name: Static Analysis
on: pull_request_target
jobs:
static_analysis:
name: ${{ matrix.toolchain }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
toolchain:
- ubuntu-latest
include:
- toolchain: ubuntu-latest
os: ubuntu-latest
compiler: clang
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Analyze
uses: JacobDomagala/StaticAnalysis@master
with:
clang_tidy_args: >-
--config-file=$GITHUB_WORKSPACE/.clang-tidy
--extra-arg=-I$GITHUB_WORKSPACE/include --extra-arg=-std=c++17
cppcheck_args: >-
--enable=all --inconclusive --inline-suppr
-i$GITHUB_WORKSPACE/test/main.cpp
-i$GITHUB_WORKSPACE/test/test_*.cpp
--suppress=missingInclude
--suppress='*:$GITHUB_WORKSPACE/test/doctest.hpp'
init_script: tools/static_analysis_setup.sh

View File

@ -453,7 +453,7 @@ public:
mUsedName = usedName;
if (mNumArgs == 0) {
mValues.emplace_back(mImplicitValue);
std::visit([](auto &aAction) { aAction({}); }, mAction);
std::visit([](const auto &aAction) { aAction({}); }, mAction);
return start;
} else if (mNumArgs <= std::distance(start, end)) {
if (auto expected = maybe_nargs()) {
@ -857,6 +857,9 @@ public:
ArgumentParser(const ArgumentParser &other)
: mProgramName(other.mProgramName),
mVersion(other.mVersion),
mDescription(other.mDescription),
mEpilog(other.mEpilog),
mIsParsed(other.mIsParsed),
mPositionalArguments(other.mPositionalArguments),
mOptionalArguments(other.mOptionalArguments) {
@ -999,7 +1002,6 @@ public:
// Print help message
friend auto operator<<(std::ostream &stream, const ArgumentParser &parser)
-> std::ostream & {
if (auto sen = std::ostream::sentry(stream)) {
stream.setf(std::ios_base::left);
stream << "Usage: " << parser.mProgramName << " [options] ";
std::size_t tLongestArgumentLength = parser.get_length_of_longest_argument();
@ -1031,7 +1033,6 @@ public:
if (!parser.mEpilog.empty())
stream << parser.mEpilog << "\n\n";
}
return stream;
}
@ -1046,7 +1047,7 @@ public:
// Printing the one and only help message
// I've stuck with a simple message format, nothing fancy.
[[deprecated("Use cout << program; instead. See also help().")]] std::string
print_help() {
print_help() const {
auto out = help();
std::cout << out.rdbuf();
return out.str();

View File

@ -57,3 +57,10 @@ set_property(TARGET ARGPARSE PROPERTY CXX_STANDARD 17)
# Set ${PROJECT_NAME} as the startup project
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ARGPARSE)
file(GLOB ARGPARSE_LINT_SOURCES
tidy-base.cpp
)
ADD_EXECUTABLE(ARGPARSE_LINT ${ARGPARSE_LINT_SOURCES})
set_target_properties(ARGPARSE_LINT PROPERTIES OUTPUT_NAME tidy-base)
set_property(TARGET ARGPARSE_LINT PROPERTY CXX_STANDARD 17)

4
test/tidy-base.cpp Normal file
View File

@ -0,0 +1,4 @@
#include "argparse/argparse.hpp"
int main(int argc, const char* argv[]) {}

4
tools/static_analysis_setup.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
# Change to the "test" subdir before "build" subdir is made.
cd test