Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Johnfreeman/linting spack support #9

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions cpplint/dune-cpp-style-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,32 @@ else
ups_get_clang
fi


files=$( echo $files | tr " " "\n" | sort | tr "\n" " " )
DIR="$(dirname "$(readlink -f "$0")")"

for file in $files ; do

if [[ $file =~ .*/Structs.hpp || $file =~ .*/Nljs.hpp ]]; then
continue
fi
if [[ $file =~ .*/Structs.hpp || $file =~ .*/Nljs.hpp ]]; then
continue
fi

echo
echo "Applying dunecpplint.sh"
$DIR/dunecpplint.sh $file

done

for file in $files ; do

echo
echo "Applying dunecpplint.sh"
$DIR/dunecpplint.sh $file
if [[ "$file" =~ .*cxx$ || "$file" =~ .*cpp$ ]]; then
echo
echo "Applying duneclang-tidy.sh"
# JCF, May-27-2022: use of carets in echo below because duneclang-tidy_scrub_output.awk breaks records with carets rather than newlines
echo "^Applying duneclang-tidy.sh to ${file}^"
echo $DIR/duneclang-tidy.sh $compile_commands_dir $file
$DIR/duneclang-tidy.sh $compile_commands_dir $file
fi

done
done |& awk -f $(dirname $0)/duneclang-tidy_scrub_output.awk


exit 0
13 changes: 8 additions & 5 deletions cpplint/duneclang-tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,17 @@ if [[ "$retval" != "0" ]]; then
fi
fi

# Left out:
# Some of the warnings/errors left out:

# misc-non-private-member-variables-in-classes: since clang-tidy bizarrely includes this complaint for structs

# cppcoreguidelines-special-member-functions: as this is overly picky
# ("if you explicitly define one of the five special member functions,
# you must define them all")

# cppcoreguidelines-pro-bounds-pointer-arithmetic: since we use C++17 and not C++20 (Jun-1-2022) we don't have access
# to std::span making it very difficult to live without subscripting arrays

musts="bugprone-assert-side-effect,\
bugprone-copy-constructor-init,\
bugprone-infinite-loop,\
Expand Down Expand Up @@ -139,7 +142,7 @@ cppcoreguidelines-macro-usage,\
cppcoreguidelines-narrowing-conversions,\
cppcoreguidelines-no-malloc,\
cppcoreguidelines-pro-bounds-constant-array-index,\
cppcoreguidelines-pro-bounds-pointer-arithmetic,\
#cppcoreguidelines-pro-bounds-pointer-arithmetic,\
cppcoreguidelines-pro-type-const-cast,\
cppcoreguidelines-pro-type-cstyle-cast,\
cppcoreguidelines-pro-type-reinterpret-cast,\
Expand Down Expand Up @@ -207,7 +210,7 @@ google-runtime-int,\
google-runtime-operator,\
hicpp-exception-baseclass,\
hicpp-multiway-paths-covered,\
misc-no-recursion,\
#misc-no-recursion,\
misc-unconventional-assign-operator,\
modernize-make-shared,\
modernize-make-unique,\
Expand Down Expand Up @@ -267,9 +270,9 @@ for source_file in $source_files; do
echo
echo "=========================Checking $source_file========================="

clang-tidy -extra-arg=-ferror-limit=0 -p=$tmpdir -checks=${musts},${maybes} -config="{CheckOptions: [{key: cppcoreguidelines-narrowing-conversions.IgnoreConversionFromTypes, value: size_t;ptrdiff_t;size_type;difference_type}]}" -header-filter=.* $source_file |& awk -f $(dirname $0)/duneclang-tidy_scrub_output.awk
clang-tidy -extra-arg=-ferror-limit=0 -p=$tmpdir -checks=${musts},${maybes} -config="{CheckOptions: [{key: cppcoreguidelines-narrowing-conversions.IgnoreConversionFromTypes, value: unsigned;size_t;ptrdiff_t;size_type;difference_type}, {key: performance-move-const-arg.CheckTriviallyCopyableMove, value: false}]}" -header-filter=.* $source_file

done
done

#echo "Deleting $tmpdir/compile_commands.json"
rm -f $tmpdir/compile_commands.json
Expand Down
51 changes: 46 additions & 5 deletions cpplint/duneclang-tidy_scrub_output.awk
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ BEGIN {
next
}

# ...and catch instances of external header errors where the awk record includes the opening blurb

if (NR == 1 && $0 ~ /Error while processing/ && $0 ~ /\/cvmfs/) {
next
}

# Get rid of complaints about moo-generated code
if ($0 ~/\/codegen\//) {
Expand Down Expand Up @@ -72,5 +67,51 @@ BEGIN {
next
}

# Catch instances of external header errors where the awk record includes the opening blurb

if ($0 ~ /Error while processing/ && $0 ~ /\/cvmfs/) {
next
}

# JCF, May-27-2022: there's a phenomenon where two warnings will appear in the same record, and the first is actually
# the last (unwanted) performance-unnecessary-value-param warning at the end of an ERS line

if ($0 ~ /\[performance-unnecessary-value-param\].*\[[[:alnum:]-]+\]/) {
match($0, /\[performance-unnecessary-value-param\].*\n/)
printf("\n%s", substr($0, RSTART+RLENGTH))
next
}

# JCF, May-27-2022: a frequent idiom is to use bind to register a
# member function as a callback (with "this" as the bound
# variable); this strikes me as easier for both the programmer and
# the reader than the lambda function clang-tidy recommends

if ($0 ~ /\[modernize-avoid-bind\].*,[[:space:]]*this[[:space:]]*,/ ) {
next
}

# JCF, May-27-2022: clang-tidy's good at catching situations where
# using auto would be helpful, but we don't want it to complain if
# someone skipped auto to make it clear what the type passed to a
# templated function is. For example,
# serialization::deserialize<trigger_record_ptr_t>(trigger_record_bytes);

if ($0 ~ /\[modernize-use-auto\].*[[:alnum:]]+<[[:alnum:]]+>\(/ ) {
next
}

# Don't have header linting repeated
match($0, /[[:alnum:]]+.h[px][px]:[0-9]+:[0-9]+/)

repeat = 0
if (RLENGTH != -1) {
header_line_and_loc = substr($0, RSTART, RLENGTH)
if (header_line_and_loc in header_complaints) {
next
}
header_complaints[header_line_and_loc] = 1
}

print
}