Remove C++ style/lint cruft

This commit is contained in:
Fabian Boehm 2024-01-07 15:12:21 +01:00
parent 53f7d1aa11
commit 0f5b2d4837
9 changed files with 0 additions and 355 deletions

View file

@ -1,16 +0,0 @@
# Use the Google style with these modifications:
#
# 1) lines can be up to 100 chars long rather than 80, and
# 2) use a four space indent rather than two spaces.
#
BasedOnStyle: Google
ColumnLimit: 100
IndentWidth: 4
# Place config.h first always.
IncludeCategories:
- Regex: '^"config.h"'
Priority: -1
# We don't want OCLint pragmas to be reformatted.
CommentPragmas: '^!OCLINT'

View file

@ -1,17 +0,0 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-valist.Uninitialized,cert-*,performance-*,portability-*,-modernize-use-auto,modernize-loop-convert,modernize-use-bool-literals,modernize-use-using,hicpp-uppercase-literal-suffix,readability-make-member-function-const,readability-redundant-string-init,readability-inconsistent-declaration-parameter-name,readability-redundant-access-specifiers,-performance-noexcept-move-constructor,-cert-dcl21-cpp,-cert-dcl37-c,-cert-dcl50-cpp,-cert-dcl51-cpp,-cert-str34-c,-cert-env33-c,misc-static-assert,readability-use-anyofallof,readability-simplify-*,readability-redundant-*,modernize-redundant-void-arg,modernize-make-shared,modernize-make-unique,modernize-loop-convert,'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: File
CheckOptions:
- key: cert-dcl16-c.NewSuffixes
value: 'L;LL;LU;LLU'
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: '0'
- key: modernize-loop-convert.MinConfidence
value: 'risky'
- key: modernize-use-auto.RemoveStars
value: '1'
...

95
.oclint
View file

@ -1,95 +0,0 @@
rules:
rule-configurations:
#
# This is the default value (as of the time I wrote this) but I'm making
# it explicit since it needs to agree with the value used by clang-format.
# Thus, if we ever change the fish style to allow longer or shorter lines
# this should be changed (as well as the corresponding .clang-format file).
#
- key: LONG_LINE
value: 100
#
# The default limit for the length of variable names is 20. Long names are
# problematic but twenty chars results in way too many errors. So increase
# the limit to something more reasonable.
#
- key: LONG_VARIABLE_NAME
value: 30
#
# This allows us to avoid peppering our code with inline comments such as
#
# scoped_lock locker(m_lock); //!OCLINT(side-effect)
#
# Specifically, this config key tells oclint that the named classes have
# RAII behavior so the local vars are actually used.
#
- key: RAII_CUSTOM_CLASSES
value: scoped_lock scoped_buffer_t builtin_commandline_scoped_transient_t scoped_push
# We're slightly more persmissive regarding the total number of lines in a
# function. Default is 50.
- key: LONG_METHOD
value: 60
# We're slightly more persmissive regarding the number of non-comment
# lines in a function. Default is 30.
- key: NCSS_METHOD
value: 40
# We're willing to allow slighly more linearly independent paths through a
# function. Most of our code has a lot of `switch` blocks or consecutive
# `if` tests that are straightforward to interpret but which increase this
# metric. Default is 10.
- key: CYCLOMATIC_COMPLEXITY
value: 14
# We're willing to allow slighly more execution paths through a function.
# Default is 200.
- key: NPATH_COMPLEXITY
value: 300
disable-rules:
#
# A few instances of "useless parentheses" errors are meaningful. Mostly
# in the context of the `return` statement. Unfortunately the vast
# majority would result in removing parentheses that decreases
# readability. So we're going to ignore this warning and rely on humans to
# notice when the parentheses are truly not needed.
#
# Also, some macro expansions, such as FD_SET(), trigger this warning and
# we don't want to suppress each of those individually.
#
- UselessParentheses
#
# OCLint wants variable names to be at least three characters in length.
# Which would be fine if it supported a reasonable set of exceptions
# (e.g., "i", "j", "k") and allowed adding additional exceptions to match
# conventions employed by a project. Since it doesn't, and thus generates
# a lot of really annoying warnings, we're going to disable this rule.
#
- ShortVariableName
#
# This rule flags perfectly reasonable conditions like `if (!some_condition)`
# and is therefore just noise. Disable this rule.
#
- InvertedLogic
#
# The idea behind the "double negative" rule is sound since constructs
# like "!!(var & flag)" should be written as "static_cast<bool>(var &
# flag)". Unfortunately this rule has way too many false positives;
# especially in the context of assert statements. So disable this rule.
#
- DoubleNegative
#
# Avoiding bitwise operators in a conditional is a good idea with one
# exception: testing whether a bit flag is set. Which happens to be the
# only time you'll see something like `if (j->flags & JOB_CONSTRUCTED)`
# in fish source.
#
- BitwiseOperatorInConditional
#
# I don't think I've ever seen a case where assigning a value to a
# parameter inside the function body was unclear, let along dangerous or
# an error. This rule is therefore just noise. Disable this rule.
#
- ParameterReassignment

View file

@ -1,3 +0,0 @@
# Ignore a one-off leak in __cxa_thread_atexit_impl that isn't under our control.
# See https://github.com/fish-shell/fish-shell/pull/9754#issuecomment-1523782989
fun:__cxa_thread_atexit_impl

View file

@ -1,26 +0,0 @@
<?xml version="1.0"?>
<![CDATA[
<!-- Sadly we can't enable the following two rules since doing so causes false
positives in standard header files rather than just project specific
source files. If we can find a way to enable these rules by also
excluding system include files we should do so.
<rule version="1">
<pattern> wcwidth \(</pattern>
<message>
<id>wcwidthForbidden</id>
<severity>warning</severity>
<summary>Always use fish_wcwidth rather than wcwidth.</summary>
</message>
</rule>
<rule version="1">
<pattern> wcswidth \(</pattern>
<message>
<id>wcswidthForbidden</id>
<severity>warning</severity>
<summary>Always use fish_wcswidth rather than wcswidth.</summary>
</message>
</rule>
<--!>
]]>

View file

@ -1,7 +0,0 @@
#!/bin/sh
cppcheck --std=c++11 --quiet \
--suppressions-list=build_tools/cppcheck.suppressions --inline-suppr \
--rule-file=build_tools/cppcheck.rules \
--force \
${@:---enable=all ./src/}

View file

@ -1,15 +0,0 @@
// suppress all instances of varFuncNullUB: "Passing NULL after the last typed
// argument to a variadic function leads to undefined behaviour." That's
// because all the places we do this are valid and won't cause problems even
// on a ILP64 platform because we're careful about using NULL rather than 0.
varFuncNullUB
// Suppress the warning about unmatched suppressions. At the moment these
// warnings are emitted even when removing the suppression comment results in
// the warning being suppressed. In other words this unmatchedSuppression
// warnings are false positives.
unmatchedSuppression
// Suppress this one because it reports assert(condition && "message"), which we use all over the place
incorrectStringBooleanError
// This is of very little use and pops up *everywhere*.
useStlAlgorithm

View file

@ -1,119 +0,0 @@
#!/usr/bin/env fish
#
# This is meant to be run by "make lint" or "make lint-all". It is not meant to
# be run directly from a shell prompt.
#
# We don't include "missingInclude" as that doesn't find our config.h.
# Missing includes will quickly be found by... compiling the thing anyway.
set -l cppchecks warning,performance,portability,information #,missingInclude
set -l cppcheck_args
set -l c_files
set -l all no
set -l kernel_name (uname -s)
set -l machine_type (uname -m)
argparse a/all p/project= -- $argv
# We only want -D and -I options to be passed thru to cppcheck.
for arg in $argv
if string match -q -- '-D*' $arg
set -a cppcheck_args (string split -- ' ' $arg)
else if string match -q -- '-I*' $arg
set -a cppcheck_args (string split -- ' ' $arg)
else if string match -q -- '-iquote*' $arg
set -a cppcheck_args (string split -- ' ' $arg)
end
end
# Not sure when this became necessary but without these flags cppcheck no longer works on macOS.
# It complains that "Cppcheck cannot find all the include files." Adding these include paths should
# be harmless everywhere else.
set cppcheck_args $cppcheck_args -I /usr/include -I .
if test "$machine_type" = x86_64
set cppcheck_args -D__x86_64__ -D__LP64__ $cppcheck_args
end
if set -q _flag_all
set c_files src/*.cpp
set cppchecks "$cppchecks,unusedFunction"
else
# We haven't been asked to lint all the source. If there are uncommitted
# changes lint those, else lint the files in the most recent commit.
# Select (cached files) (modified but not cached, and untracked files)
set -l files (git diff-index --cached HEAD --name-only)
set files $files (git ls-files --exclude-standard --others --modified)
if not set -q files[1]
# No pending changes so lint the files in the most recent commit.
set files (git diff-tree --no-commit-id --name-only -r HEAD)
end
# Extract just the C/C++ files that exist.
set c_files
for file in (string match -r '.*\.c(?:pp)?$' -- $files)
test -f $file; and set c_files $c_files $file
end
end
# We now have a list of files to check so run the linters.
if set -q c_files[1]
if type -q include-what-you-use
echo
echo ========================================
echo Running IWYU
echo ========================================
for c_file in $c_files
switch $kernel_name
case Darwin FreeBSD
include-what-you-use -Xiwyu --no_default_mappings -Xiwyu \
--mapping_file=build_tools/iwyu.osx.imp --std=c++11 \
$cppcheck_args $c_file 2>&1
case Linux
include-what-you-use -Xiwyu --mapping_file=build_tools/iwyu.linux.imp \
$cppcheck_args $c_file 2>&1
case '*' # hope for the best
include-what-you-use --std=c++11 $cppcheck_args $c_file 2>&1
end
end
end
if type -q cppcheck
echo
echo ========================================
echo Running cppcheck
echo ========================================
build_tools/cppcheck.sh --enable=$cppchecks $c_files 2>&1
echo
echo ========================================
echo 'Running `cppcheck --check-config` to identify missing includes and similar problems.'
echo 'Ignore unmatchedSuppression warnings as they are probably false positives we'
echo 'cannot suppress.'
echo ========================================
cppcheck $cppcheck_args --check-config $c_files 2>&1
end
if type -q oclint
echo
echo ========================================
echo Running oclint
echo ========================================
# The stderr to stdout redirection is because oclint, incorrectly writes its final summary
# counts of the errors detected to stderr. Anyone running this who wants to capture its
# output will expect those messages to be written to stdout.
oclint $c_files -- $argv 2>&1
end
if type -q clang-tidy; and set -q _flag_project
echo
echo ========================================
echo Running clang-tidy
echo ========================================
clang-tidy -p $_flag_project $c_files
end
else
echo
echo 'WARNING: No C/C++ files to check'
echo
end

View file

@ -3,8 +3,6 @@
# This runs C++ files and fish scripts (*.fish) through their respective code
# formatting programs.
#
set -l git_clang_format no
set -l c_files
set -l fish_files
set -l python_files
set -l rust_files
@ -30,27 +28,10 @@ if test $all = yes
exit 1
end
end
set c_files src/*.h src/*.cpp src/*.c
set fish_files share/**.fish
set python_files {doc_src,share,tests}/**.py
set rust_files fish-rust/src/**.rs
else
# We haven't been asked to reformat all the source. If there are uncommitted changes reformat
# those using `git clang-format`. Else reformat the files in the most recent commit.
# Select (cached files) (modified but not cached, and untracked files)
set -l files (git diff-index --cached HEAD --name-only) (git ls-files --exclude-standard --others --modified)
if set -q files[1]
set git_clang_format yes
else
# No pending changes so lint the files in the most recent commit.
set files (git diff-tree --no-commit-id --name-only -r HEAD)
end
# Extract just the C/C++ files that exist.
set c_files
for file in (string match -r '^.*\.(?:c|cpp|h)$' -- $files)
test -f $file; and set c_files $c_files $file
end
# Extract just the fish files.
set fish_files (string match -r '^.*\.fish$' -- $files)
set python_files (string match -r '^.*\.py$' -- $files)
@ -62,44 +43,6 @@ set -l green (set_color green)
set -l blue (set_color blue)
set -l normal (set_color normal)
# Run the C++ reformatter if we have any C++ files.
if set -q c_files[1]
if test $git_clang_format = yes
if type -q git-clang-format
echo === Running "$red"git-clang-format"$normal"
git add $c_files
git-clang-format
else
echo
echo 'WARNING: Cannot find git-clang-format command'
echo
end
else if type -q clang-format
echo === Running "$red"clang-format"$normal"
for file in $c_files
if clang-format --dry-run -Werror $file
# file was clean, remove it from the list
set -e c_files[(contains -i $file $c_files)]
end
end
if set -q c_files[1]
printf "Reformat those %d files?\n" (count $c_files)
read -P 'y/N? ' -n1 -l ans
if string match -qi y -- $ans
clang-format -i --verbose $c_files
else if string match -qi n -- $ans
echo Skipping
else # like they ctrl-C'd or something.
exit 1
end
end
else
echo
echo 'WARNING: Cannot find clang-format command'
echo
end
end
# Run the fish reformatter if we have any fish files.
if set -q fish_files[1]
if not type -q fish_indent