mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 15:14:39 +00:00
Merge pull request #148 from skrobinson/feat-add-sa-pr-action
Add StaticAnalysis PR Action
This commit is contained in:
commit
fcfbe7141e
24
.clang-tidy
Normal file
24
.clang-tidy
Normal 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
42
.github/workflows/static_analysis.yml
vendored
Normal 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
|
@ -453,7 +453,7 @@ public:
|
|||||||
mUsedName = usedName;
|
mUsedName = usedName;
|
||||||
if (mNumArgs == 0) {
|
if (mNumArgs == 0) {
|
||||||
mValues.emplace_back(mImplicitValue);
|
mValues.emplace_back(mImplicitValue);
|
||||||
std::visit([](auto &aAction) { aAction({}); }, mAction);
|
std::visit([](const auto &aAction) { aAction({}); }, mAction);
|
||||||
return start;
|
return start;
|
||||||
} else if (mNumArgs <= std::distance(start, end)) {
|
} else if (mNumArgs <= std::distance(start, end)) {
|
||||||
if (auto expected = maybe_nargs()) {
|
if (auto expected = maybe_nargs()) {
|
||||||
@ -857,6 +857,9 @@ public:
|
|||||||
|
|
||||||
ArgumentParser(const ArgumentParser &other)
|
ArgumentParser(const ArgumentParser &other)
|
||||||
: mProgramName(other.mProgramName),
|
: mProgramName(other.mProgramName),
|
||||||
|
mVersion(other.mVersion),
|
||||||
|
mDescription(other.mDescription),
|
||||||
|
mEpilog(other.mEpilog),
|
||||||
mIsParsed(other.mIsParsed),
|
mIsParsed(other.mIsParsed),
|
||||||
mPositionalArguments(other.mPositionalArguments),
|
mPositionalArguments(other.mPositionalArguments),
|
||||||
mOptionalArguments(other.mOptionalArguments) {
|
mOptionalArguments(other.mOptionalArguments) {
|
||||||
@ -999,7 +1002,6 @@ public:
|
|||||||
// Print help message
|
// Print help message
|
||||||
friend auto operator<<(std::ostream &stream, const ArgumentParser &parser)
|
friend auto operator<<(std::ostream &stream, const ArgumentParser &parser)
|
||||||
-> std::ostream & {
|
-> std::ostream & {
|
||||||
if (auto sen = std::ostream::sentry(stream)) {
|
|
||||||
stream.setf(std::ios_base::left);
|
stream.setf(std::ios_base::left);
|
||||||
stream << "Usage: " << parser.mProgramName << " [options] ";
|
stream << "Usage: " << parser.mProgramName << " [options] ";
|
||||||
std::size_t tLongestArgumentLength = parser.get_length_of_longest_argument();
|
std::size_t tLongestArgumentLength = parser.get_length_of_longest_argument();
|
||||||
@ -1031,7 +1033,6 @@ public:
|
|||||||
|
|
||||||
if (!parser.mEpilog.empty())
|
if (!parser.mEpilog.empty())
|
||||||
stream << parser.mEpilog << "\n\n";
|
stream << parser.mEpilog << "\n\n";
|
||||||
}
|
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
@ -1046,7 +1047,7 @@ public:
|
|||||||
// Printing the one and only help message
|
// Printing the one and only help message
|
||||||
// I've stuck with a simple message format, nothing fancy.
|
// I've stuck with a simple message format, nothing fancy.
|
||||||
[[deprecated("Use cout << program; instead. See also help().")]] std::string
|
[[deprecated("Use cout << program; instead. See also help().")]] std::string
|
||||||
print_help() {
|
print_help() const {
|
||||||
auto out = help();
|
auto out = help();
|
||||||
std::cout << out.rdbuf();
|
std::cout << out.rdbuf();
|
||||||
return out.str();
|
return out.str();
|
||||||
|
@ -57,3 +57,10 @@ set_property(TARGET ARGPARSE PROPERTY CXX_STANDARD 17)
|
|||||||
|
|
||||||
# Set ${PROJECT_NAME} as the startup project
|
# Set ${PROJECT_NAME} as the startup project
|
||||||
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ARGPARSE)
|
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
4
test/tidy-base.cpp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
#include "argparse/argparse.hpp"
|
||||||
|
|
||||||
|
int main(int argc, const char* argv[]) {}
|
4
tools/static_analysis_setup.sh
Executable file
4
tools/static_analysis_setup.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Change to the "test" subdir before "build" subdir is made.
|
||||||
|
cd test
|
Loading…
Reference in New Issue
Block a user