diff --git a/dev/hooks/pre-commit b/dev/hooks/pre-commit new file mode 100644 index 00000000..299391da --- /dev/null +++ b/dev/hooks/pre-commit @@ -0,0 +1,4 @@ +#!/bin/bash +# Run MATLAB script before committing + +matlab -batch "try; run('dev/hooks/pre_commit.m'); catch e; disp(getReport(e)); exit(1); end; exit(0);" diff --git a/dev/hooks/pre_commit.m b/dev/hooks/pre_commit.m new file mode 100644 index 00000000..b20cc8b8 --- /dev/null +++ b/dev/hooks/pre_commit.m @@ -0,0 +1,21 @@ +toolsDir = fileparts(fileparts(mfilename('fullpath'))); +addpath(genpath(toolsDir)) + +failed = string.empty; + +try + ommtools.codespellToolbox +catch + failed = [failed, "codespell"]; +end + +try + %ommtools.stylecheckToolbox %todo... +catch %#ok + failed = [failed, "stylecheck"]; +end + +if ~isempty(failed) + message = strjoin(" " + failed, newline); + error('The following checks failed:\n%s', message) +end diff --git a/dev/tasks/codecheckToolbox.m b/dev/tasks/codecheckToolbox.m index 65a0ec9f..1d123ab9 100644 --- a/dev/tasks/codecheckToolbox.m +++ b/dev/tasks/codecheckToolbox.m @@ -1,9 +1,9 @@ -function codecheckToolbox() +function issues = codecheckToolbox() % codecheckToolbox - Identify code issues for openMINDS_MATLAB toolbox ommtools.installMatBox("commit") projectRootDirectory = ommtools.projectdir(); - matbox.tasks.codecheckToolbox(projectRootDirectory, ... - "CreateBadge", true) + issues = matbox.tasks.codecheckToolbox(projectRootDirectory, ... + "CreateBadge", true); end