aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Kurtis Rader <krader@skepticism.us>2016-06-17 20:16:21 -0700
committerGravatar Kurtis Rader <krader@skepticism.us>2016-06-17 20:16:21 -0700
commitdc58edd521942c0a5a42541d5b5c39b09c226665 (patch)
treef68df7afd78e084ae4771219ac658c3a18427a7b
parente6d4ac5ee25f09bd661e0360844ca107fb6c3491 (diff)
implement custom cppcheck rules
I recently noticed there were several invocations of `wcwidth()` that should have been `fish_wcwidth()`. This adds custom cppcheck rules to detect that mistake.
-rw-r--r--.cppcheck.rule18
-rw-r--r--CONTRIBUTING.md2
-rwxr-xr-xbuild_tools/lint.fish2
3 files changed, 21 insertions, 1 deletions
diff --git a/.cppcheck.rule b/.cppcheck.rule
new file mode 100644
index 00000000..d8f67a83
--- /dev/null
+++ b/.cppcheck.rule
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<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>
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 2e7733ab..bac0e467 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -30,6 +30,8 @@ Ultimately we want lint free code. However, at the moment a lot of cleanup is re
To make linting the code easy there are two make targets: `lint` and `lint-all`. The latter does just what the name implies. The former will lint any modified but not committed `*.cpp` files. If there is no uncommitted work it will lint the files in the most recent commit.
+Fish has custom cppcheck rules in the file `.cppcheck.rule`. These help catch mistakes such as using `wcwidth()` rather than `fish_wcwidth()`. Please add a new rule if you find similar mistakes being made.
+
### Dealing With Lint Warnings
You are strongly encouraged to address a lint warning by refactoring the code, changing variable names, or whatever action is implied by the warning.
diff --git a/build_tools/lint.fish b/build_tools/lint.fish
index 2b21402c..f3350aee 100755
--- a/build_tools/lint.fish
+++ b/build_tools/lint.fish
@@ -92,7 +92,7 @@ if set -q c_files[1]
# The stderr to stdout redirection is because cppcheck, incorrectly IMHO, writes its
# diagnostic messages to stderr. Anyone running this who wants to capture its output will
# expect those messages to be written to stdout.
- cppcheck -q --verbose --std=posix --std=c11 --language=c++ --template "[{file}:{line}]: {severity} ({id}): {message}" --suppress=missingIncludeSystem --inline-suppr --enable=$cppchecks $cppcheck_args $c_files 2>&1
+ cppcheck -q --verbose --std=posix --std=c11 --language=c++ --template "[{file}:{line}]: {severity} ({id}): {message}" --suppress=missingIncludeSystem --inline-suppr --enable=$cppchecks --rule-file=.cppcheck.rule $cppcheck_args $c_files 2>&1
end
if type -q oclint