Commit 6c5ce464 authored by Brett Wilkins's avatar Brett Wilkins

Adding coding standards checks to minaccept in Makefile

test/coding-standards-check.pl checks for:
* trailing whitespace and tabs following spaces in indents.
* unresolved merge commits
* Mahara coding guideline conformance

Change-Id: I7e9cd4fff4689455dd6f30e923e23df9d2c63d6a
Signed-off-by: default avatarBrett Wilkins <brett@catalyst.net.nz>
parent d8b9f26e
......@@ -10,10 +10,31 @@ imageoptim:
find . -iname '*.jpg' -exec jpegoptim -q -p --strip-all {} \;
find . -iname '*.jpeg' -exec jpegoptim -q -p --strip-all {} \;
branch := $(GERRIT_REFSPEC)
ifeq (, $(branch))
branch := $(shell bash -c "git branch | grep \* | sed -e 's/ *\* *//'" )
endif
ifeq ("(no branch)", $(branch))
remote := origin
else
remote := $(shell bash -c "git config --get branch.$(branch).remote" )
endif
ifeq (., $(remote))
remote := origin
endif
ifeq (, $(remote))
remote := origin
endif
commitid := $(shell bash -c "git merge-base $(remote)/master HEAD")
minaccept:
@echo "Running minimum acceptance test...";
find htdocs/ -type f -name "*.php" | xargs -n 1 -P 2 php -l > /dev/null && echo All good!
find htdocs/ -type f -name "install.xml" -path "*/db/install.xml" | xargs -n 1 -P 2 xmllint --schema htdocs/lib/xmldb/xmldb.xsd --noout
if git rev-parse --verify HEAD 2>/dev/null; then git diff-index -p -M --cached $(commitid) -- ; fi | test/coding-standard-check.pl
push: minaccept
if test -z "$(TAG)"; then \
......
#!/usr/bin/perl
# This is slightly modified from Andrew Morton's Perfect Patch.
# Lines you introduce should not have trailing whitespace.
# Also check for an indentation that has SP before a TAB.
my $found_bad = 0;
my $filename;
my $reported_filename = "";
my $lineno;
sub bad_line {
my ($why, $line) = @_;
if (!$found_bad) {
print STDERR "*\n";
print STDERR "* You have some suspicious patch lines:\n";
print STDERR "*\n";
$found_bad = 1;
}
if ($reported_filename ne $filename) {
print STDERR "* In $filename\n";
$reported_filename = $filename;
}
print STDERR "* $why (line $lineno)\n";
print STDERR "$filename:$lineno:$line\n";
}
while (<>) {
if (m|^diff --git a/(.*) b/\1$|) {
$filename = $1;
next;
}
if (/^@@ -\S+ \+(\d+)/) {
$lineno = $1 - 1;
next;
}
if (/^ /) {
$lineno++;
next;
}
if (s/^\+//) {
$lineno++;
chomp;
if ($filename !~ /\.(php|js)$/) {
next;
}
if (/\s$/) {
bad_line("trailing whitespace", $_);
}
if (/\t+/) {
bad_line("TABs should be replaced by 4 spaces.", $_);
}
if (/^([<>])\1{6} |^={7}$/) {
bad_line("unresolved merge conflict", $_);
}
if (/\}\s*else/) {
bad_line("cuddled elses are against Mahara coding guidelines", $_);
}
if (/elseif/) {
bad_line("a single space is requred between an else and an if on the same line", $_);
}
if (/(if|while|for)\(/ || /(if|while|for)\s\s+\(/) {
bad_line("conditional and looping statements should have a space between keywords ".
"and the condition brackets", $_);
}
if (/^\s*{/) {
bad_line("opening curly braces are do no need their own line.", $_);
}
if (/require_once\s+\(?/) {
bad_line("a require_once statement should look like a function call, ".
"without a space between the keyword and the bracket.", $_);
}
}
}
exit($found_bad);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment