Skip to content

Commit

Permalink
[checkTranslator.sh] Warn about unnecassary indexOf() (zotero#1536)
Browse files Browse the repository at this point in the history
  • Loading branch information
zuphilip authored Jan 28, 2018
1 parent ba56c70 commit 310114b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion .ci/checkTranslator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ declare -a ERROR_CHECKS=(
declare -a WARN_CHECKS=(
"badLicense"
"problematicJS"
"unnecessaryIndexOf"
)

#-----------------------------------------------------------------------
Expand Down Expand Up @@ -89,6 +90,14 @@ deprecatedForEach () {
fi
}

unnecessaryIndexOf () {
if grep -qE '\.indexOf(.*) *(=+ *-1|!=+ *-1|> *-1|>= *0|< *0)' "$TRANSLATOR";then
warn "Unnecessary '.indexOf()', use '.includes()' instead:"
grep -nE '\.indexOf(.*) *(=+ *-1|!=+ *-1|> *-1|>= *0|< *0)' "$TRANSLATOR"
return 1
fi
}

badLicense () {
if ! grep -q "GNU Affero General Public License" "$TRANSLATOR";then
warn "Must be AGPL licensed"
Expand All @@ -112,7 +121,7 @@ problematicJS () {
| sed '/BEGIN TEST/,$ d' \
| jshint --config="$SCRIPT_DIR"/jshintrc --reporter=unix -)
if (( $? > 0 ));then
warn "JSHint shows issues with this code"
warn "JSHint shows issues with this code:"
warn "$jshint_error"
return 1
fi
Expand Down

0 comments on commit 310114b

Please sign in to comment.