Run a syntax checker in a pre-commit hook

Issue #123 closed
Erik Schnetter created an issue

I am getting annoyed by the frequent syntax errors in SimFactory that used to be caught by Perl and are now not caught by Python. It would be ideal if syntax checking could be built into SimFactory, so that it executes automatically during startup if that isn't too slow.

Keyword:

Comments (8)

  1. Ian Hinder
    • changed status to open
    • removed comment

    The attached patch runs pylint and pychecker on every invocation of the "sim" shell script. On my laptop it adds approximately one second to the execution time for "sim help". It looks for the checker binary under several names. For example, fink installs pychecker as pychecker-py26.

    Currently, pychecker reports very few warnings, but pylint reports a large number. It would be good to understand and fix these, and if they are false positives, to add exceptions for them, before committing this patch.

  2. Erik Schnetter reporter
    • removed comment

    On my system, pylint is called "pylint-2.4".

    What do pychecker and pylint do? Do they only output warnings, or abort the code?

    In my experience, aborting on errors and on some warnings is the best thing to do. This may seem inconvenient at first, but very quickly one obtains a much more solid code base.

  3. Ian Hinder
    • removed comment

    They output warnings to the screen and return a nonzero exit code if there were any. I decided not to check the exit code in the current patch because that would stop people from running even for non-problems, and because there are currently a large number of reports from pylint, and a small number from pychecker.

    Once we have fixed all the current reports, or marked them as OK in the checkers, we can check the exit code and abort in the case of an error, but I think it's premature to do it until that is the case.

    I can add pylint-2.4 to the list of pylints. I don't know a good generic way of locating it.

    Michael: could you give the patch a try and see if you understand any of the warnings which are being produced? Some of them looked trivial to fix, such as missing docstrings, and we could even suppress that particular one for now. It would be good to get these down to zero.

    Of course, this should not take priority over the "blocker" and "critical" tickets.

  4. Erik Schnetter reporter
    • removed comment

    I updated the patch to include nicer output, in particular separating the checking output from the command output.

    All problems reported should be rather easy to correct. I suggest to apply the patch, in the hope to nag others into addressing some of the reported issues.

  5. Erik Schnetter reporter
    • removed comment

    I tried the patch for some time, and found that it didn't help. Most of the reported problems are trivial, while the additional delay is annoying. It also doesn't work on all systems; on some systems, an error message and the help text is output instead.

    I would now suggest to add a new simfactory command that runs the syntax checker, instead of running it all the time.

  6. Log in to comment