Package: code-checker
ContentsAboutCurrently supported checkersProject checkersFile checkersExamplesInstallationUninstallationGit hooks setupCheckers detailsphpunitpep257pylintpep8unittestjshintinternjscsphpcsrst-lintAboutThis app runs any number of checks such as unit tests or linters during pre-commit check.
If at least one check will not pass, commit is aborted.Checkers are treated as jobs divided among couple of workers.
Number of workers is equal to number of your cpu logical cores, every worker is executed in separate process (on separate cpu core).Inprecommit-checkers.ymlyou can configure which checkers checks which files and define checkers configuration.There are two categories of checkers: project-checkers and file-checker.Every project-checker is executed only once during pre-commit check. Example of project-checker isunittest- this checker is executed for whole project.file-checkercan be executed for files in git staging area (git index). SeeExamplesbelow.Result of each checker has status which value is one of:SUCCESS,WARNINGorERROR. OnSUCCESSandWARNINGcommit proceeds, onERRORis aborted.If you want to run checkers without commiting changes usecheck-codecommand.Currently supported checkersProject checkersunittest:Python unittestphpunit:PHP unittest framework.intern:Test system for JavaScript.File checkerspylint:Pylint checker. Fail if code rate is belowaccepted-code-ratepep8:Python PEP8 checker.pep257:Python PEP257 checker.phpcs:PHP Code Sniffer: PHP coding standard linter.jshint:JSHint: JavaScript linter.jscs:JSCS - JavaScript code style linterrst-lint:A reStructuredText linter.ExamplesBelow are exampleprecommit-checkers.ymlcontents.project-checkers:unittestfile-checkers:'*.py':[pylint,pep8]'*.js':jshintIf yourprecommit-checkers.ymlis same as above, pre-commit check will execute pythonunittestfor project,pylintandpep8for*.pyfiles and jshint for js files.pep8andjshintcheckers does not pass if at least one warning will occur.pylintdoes not pass if computed code rate is belowaccepted_code_rate, defaultaccepted_code_rateis 9.project-checkers:unittestfile-checkers:'*.py':[pylint,pep8]'*.js':jshintconfig:pylint:{accepted-code-rate:8}This example shows how to set global configuration for specified checkers. Above configuration has similar effect as previous example but here accepted code rate computed by pylint is set to 8.project-checkers:unittestfile-checkers:'*.py':[pylint,pep8]'tests/*.py':-pylint:{accepted-code-rate:8}config:pylint:{accepted-code-rate:9}Checker options can be set also for specific file pattern. In this example python modules undertests/directory will be checked bypylintwith accepted code rate 8. Rest of python modules will be checkek bypep8andpylintwith accepted code rate 9.project-checkers:unittestfile-checkers:'*.py':[pylint,pep8]'tests/*.py':-pylint:{rcfile:tests/pylintrc}This shows how to set custompylintrcfor tests modulesHow to set jshint rc file:file-checkers:'*.js':jshintconfig:jshint:{config:.jshintrc}Every previous examples assumes that checkers are installed globally in your system or active virtual environment.
Some checkers acceptsexecutableconfig option. Use this option if you want to select specific executable.project-checkers:[phpunit,intern]config:phpunit:{executable:vendor/phpunit/phpunit/phpunit,bootstrap:tests/bootstrap.php,directory:tests/TestSuite},intern:{config:tests/config.js,executable:node_modules/.bin/intern-client}SeeCheckers detailsInstallationpipinstallcode-checkerNoteInstallation of code-checker requires Python 3 and pipUninstallationpipuninstallcode-checkerGit hooks setupInstallcode-checkerInstallationChange current working directory to git repositorycd /path/to/repositoryExecutesetup-githooks. This command createspre-commithook which run checkers defined inprecommit-checkers.ymlNotesetup-githooksfail if.git/hooks/pre-commitalready exists. You should delete it manually first.
Also ifprecommit-checkers.ymlalready existssetup-githooksleaves it untouched.NoteMake sure that every requirement of checkers (pylint, pep8, jshint etc.) are installed in your system, active virtual environment or project repository.
You should install them manually.Checkers detailsphpunitResult statusStatusDescriptionSUCCESSIf phpunit exit status is 0 (all tests passes)WARNINGIf phpunit exit status is 0 and skipped or incomplete test are foundERRORIf phpunit exit status is not 0 (some tests fail)Default configOptionDefaultDescriptiondirectorynullIf not null, pass <value> to phpunit command.executablephpunitSet phpunit executable path.bootstrapnullIf not null, pass –bootstrap <value> to phpunit command.pep257Result statusStatusDescriptionSUCCESSIf checker command exit status is 0ERRORIf checker command exit status is not 0Default configOptionDefaultDescriptionadd-selectnullIf not null, pass –add-select=<value> to pep257 command.selectnullIf not null, pass –select=<value> to pep257 command.countnullIf not null, pass –count=<value> to pep257 command.ignorenullIf not null, pass –ignore=<value> to pep257 command.explainnullIf not null, pass –explain to pep257 command.add-ignorenullIf not null, pass –add-ignore=<value> to pep257 command.sourcenullIf not null, pass –source to pep257 command.pylintResult statusStatusDescriptionSUCCESSIf computed code rate is 10WARNINGIf computed code rate is greater or equal than accepted code rateERRORIf computed code rate is less than accepted code rateDefault configOptionDefaultDescriptionrcfilenullIf not null, pass –rcfile=<value> to pylint command.accepted-code-rate9pep8Result statusStatusDescriptionSUCCESSIf checker command exit status is 0ERRORIf checker command exit status is not 0Default configOptionDefaultDescriptionselectnullIf not null, pass –select=<value> to pep8 command.qqnullIf not null, pass -qq to pep8 command.countnullIf not null, pass –count to pep8 command.hang-closingnullIf not null, pass –hang-closing to pep8 command.max-line-lengthnullIf not null, pass –max-line-length=<value> to pep8 command.formatnullIf not null, pass –format=<value> to pep8 command.confignullIf not null, pass –config=<value> to pep8 command.ignorenullIf not null, pass –ignore=<value> to pep8 command.firstnullIf not null, pass –first to pep8 command.show-pep8nullIf not null, pass –show-pep8 to pep8 command.quietnullIf not null, pass –quiet to pep8 command.statisticsnullIf not null, pass –statistics to pep8 command.show-sourcenullIf not null, pass –show-source to pep8 command.unittestResult statusStatusDescriptionSUCCESSIf unittest exit status is 0 (all tests passes)WARNINGIf unittest exit status is 0 and skipped test are foundERRORIf unittest exit status is not 0 (some tests fail)Default configOptionDefaultDescriptionjshintResult statusStatusDescriptionSUCCESSIf checker command exit status is 0ERRORIf checker command exit status is not 0Default configOptionDefaultDescriptionconfignullIf not null, pass –config <value> to jshint command.executablejshintSet jshint executable path.internResult statusStatusDescriptionSUCCESSIf checker command exit status is 0ERRORIf checker command exit status is not 0Default configOptionDefaultDescriptionconfignullIf not null, pass config=<value> to intern command.executableintern-clientSet intern executable path.jscsResult statusStatusDescriptionSUCCESSIf checker command exit status is 0ERRORIf checker command exit status is not 0Default configOptionDefaultDescriptionconfignullIf not null, pass –config <value> to jscs command.es3nullIf not null, pass –es3 to jscs command.presetnullIf not null, pass –preset <value> to jscs command.executablejscsSet jscs executable path.esnextnullIf not null, pass –esnext to jscs command.phpcsResult statusStatusDescriptionSUCCESSIf checker command exit status is 0ERRORIf checker command exit status is not 0Default configOptionDefaultDescriptionstandardnullIf not null, pass –standard=<value> to phpcs command.executablephpcsSet phpcs executable path.encodingutf-8If not null, pass –encoding=<value> to phpcs command.rst-lintResult statusStatusDescriptionSUCCESSIf checker command exit status is 0ERRORIf checker command exit status is not 0Default configOptionDefaultDescriptionexecutablerst-lintSet rst-lint executable path.encodingutf-8If not null, pass –encoding <value> to rst-lint command.