sco1 / pre-commit-matlab

A collection of pre-commit hooks (ok, just one) for MATLAB
MIT License
3 stars 1 forks source link

Add support for MATLAB codecheck, codeIssues #42

Open stv0g opened 1 month ago

stv0g commented 1 month ago

There are several code-quality tools provided by MATLAB:

It would be great if we could add support for running the MATLAB code quality checkers in a dedicated pre-commit hook.

sco1 commented 1 month ago

As far as I can tell the latter two are MATLAB only, the MATLAB Language Server may facilitate these but I am not familiar with its use so not sure if it would help here.

mlint may be pretty feasible since it has a standalone executable. I'll try and take a look at it this week and see what can be accomplished.

stv0g commented 1 month ago

As far as I can tell the latter two are MATLAB only

Yes that's true. But mlint itself is a MATLAB function as well. I think it should be pretty straight forward to wrap the MATLAB function into a standalone script/executable to work around this.

The language server sounds quite interesting too, but I am looking for running the checks in our CI too. Maybe there is a pre-commit hook to single-run the code through a LSP language server? That would be interesting for other languages as well.

There is also the pretty nice VSCode extension by Mathworks themselves: https://github.com/mathworks/MATLAB-extension-for-vscode

But I don't think it's using the language server?

sco1 commented 1 month ago

I think it should be pretty straight forward to wrap the MATLAB function into a standalone script/executable to work around this.

I do not have a personal license for the MATLAB Compiler, and even if I did the MATLAB Runtime is version-specific and ensuring that either myself or the end users or both are synchronized isn't a maintenance burden I want to handle. Keeping track of spawning MATLAB instances for every commit is also out of scope for me, and Windows still lacks a headless launch option.

The language server sounds quite interesting too, but I am looking for running the checks in our CI too. Maybe there is a pre-commit hook to single-run the code through a LSP language server?

The MathWorks maintains a set of GitHub actions that may be more useful for use-cases that require managing an existing MATLAB installation.

The ideal path would be to add MATLAB language support to pre-commit (see: adding support for a new hook language), likely through the use of the language server, though I'm not sure how feasible it would be to have functional enough tests to contribute this without requiring maintenance of a MATLAB license. I have had this thought on occasion but has not been an effort I have been able to take on.

But I don't think it's using the language server?

It does. It is vendored as a submodule.