To ensure the Coding Standards of Submitty, we use a mixture of linting and static analysis for each specific programming language. Wikipedia defines linting as a “tool that analyzes source code to flag programming errors, bugs, stylistic errors, and suspicious constructs.” Static analysis constructs an abstract syntax tree of the program and is able to validate specific details such as the right number of types of parameters, functions return what they say they do, etc.
Be sure to start with the Initial Set Up installation instructions.
The Python code of Submitty is linted using flake8 and flake8-bugbear. You can run the Python linter locally (on your host operating system) by running the following command from the root level of Submitty source tree:
# from root level of Submitty repository python3 -m flake8
NOTE: Our Travis CI testing currently excludes a number of legacy source code files. from Python linting, though there is effort to bring more and more of them under flake8.
Optionally, you can pass in a specific file or directory to only lint that file or directory, e.g.:
# from root level of Submitty repository... to lint a specific file: python3 -m flake8 bin/generate_repos.py
See also: Python Style Guide
You will need PHP installed on your host system first, see Installing PHP
The PHP code of Submitty is linted using phpcs.
You can run the PHP Linter locally (from your host operating system):
If you are running on WSL and are seeing errors, remove “
php” from the following commands.
# from root level of Submitty repository php site/vendor/bin/phpcs --standard=site/tests/ruleset.xml # or if in the site/ directory of the Submitty php vendor/bin/phpcs --standard=tests/ruleset.xml
Similarly, you can pass a specific file or directory to
# from root level of Submitty repository... run phpcs against all files in this subdirectory php site/vendor/bin/phpcs --standard=site/tests/ruleset.xml site/app/controllers/student/
See also: PHP Style Guide
PHP Static Analysis
The PHP code of Submitty is statically analyzed by phpstan. To run it locally (from your host operating system), you can do the following:
# from root level of Submitty repository php site/vendor/bin/phpstan analyze -c site/phpstan.neon site/app # or if in the site/ directory of the Submitty repository php vendor/bin/phpstan analyze app
Unlike flake8 and phpcs, a path or file MUST be passed to phpstan.
You can run eslint on your host system or on vagrant by navigating into the
directory and running:
npm run eslint
To have eslint attempt to automatically fix any detected problems:
npm run eslint:fix
If you wish to lint or fix a specific file, you will need to run the eslint executable directly, by doing:
node_modules/.bin/eslint [--fix] <file>
CSS is linted using stylelint in Submitty to enforce a consistent code style.
You can run stylelint on your host system or on vagrant by navigating into the
directory and running:
npm run css-stylelint
Stylelint can fix many CSS problems automatically by running:
npm run css-stylelint:fix
See also: CSS Style Guide