aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/lint.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lint.sh')
-rwxr-xr-xscripts/lint.sh63
1 files changed, 58 insertions, 5 deletions
diff --git a/scripts/lint.sh b/scripts/lint.sh
index d0f82b1..9e33c87 100755
--- a/scripts/lint.sh
+++ b/scripts/lint.sh
@@ -14,21 +14,74 @@
# Lints C++ files for conformance with the Google C++ style guide
-options=(
+# Joins the given arguments with the separator given as the first argument.
+function join() {
+ local IFS="$1"
+ shift
+ echo "$*"
+}
+
+git_options=(
-z # \0 terminate output
)
+objc_lint_filters=(
+ # Objective-C uses #import and does not use header guards
+ -build/header_guard
+
+ # Inline definitions of Objective-C blocks confuse
+ -readability/braces
+
+ # C-style casts are acceptable in Objective-C++
+ -readability/casting
+
+ # Objective-C needs use type 'long' for interop between types like NSInteger
+ # and printf-style functions.
+ -runtime/int
+
+ # cpplint is generally confused by Objective-C mixing with C++.
+ # * Objective-C method invocations in a for loop make it think its a
+ # range-for
+ # * Objective-C dictionary literals confuse brace spacing
+ # * Empty category declarations ("@interface Foo ()") look like function
+ # invocations
+ -whitespace
+)
+
+objc_lint_options=(
+ # cpplint normally excludes Objective-C++
+ --extensions=h,m,mm
+
+ # Objective-C style allows longer lines
+ --linelength=100
+
+ --filter=$(join , "${objc_lint_filters[@]}")
+)
+
if [[ $# -gt 0 ]]; then
# Interpret any command-line argument as a revision range
command=(git diff --name-only)
- options+=("$@")
+ git_options+=("$@")
else
# Default to operating on all files that match the pattern
command=(git ls-files)
fi
-
-"${command[@]}" "${options[@]}" \
+# Straight C++ files get regular cpplint
+"${command[@]}" "${git_options[@]}" \
-- 'Firestore/core/**/*.'{h,cc} \
- | xargs -0 python scripts/cpplint.py --quiet
+ | xargs -0 python scripts/cpplint.py --quiet 2>&1
+CPP_STATUS=$?
+
+# Objective-C++ files get a looser cpplint
+"${command[@]}" "${git_options[@]}" \
+ -- 'Firestore/Source/**/*.'{h,m,mm} \
+ 'Firestore/Example/Tests/**/*.'{h,m,mm} \
+ 'Firestore/core/**/*.mm' \
+ | xargs -0 python scripts/cpplint.py "${objc_lint_options[@]}" --quiet 2>&1
+OBJC_STATUS=$?
+
+if [[ $CPP_STATUS != 0 || $OBJC_STATUS != 0 ]]; then
+ exit 1
+fi