Skip to content

Commit

Permalink
Add pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
ehennestad committed Oct 26, 2024
1 parent 2170225 commit 6512f59
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions dev/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -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);"
21 changes: 21 additions & 0 deletions dev/hooks/pre_commit.m
Original file line number Diff line number Diff line change
@@ -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<UNRCH>
failed = [failed, "stylecheck"];
end

if ~isempty(failed)
message = strjoin(" " + failed, newline);
error('The following checks failed:\n%s', message)
end
6 changes: 3 additions & 3 deletions dev/tasks/codecheckToolbox.m
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6512f59

Please sign in to comment.