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, flake8-bugbear, and pylint. 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 using flake8
python3 -m flake8
# from root level of Submitty repository using pylint
python3 -m pylint --recursive=y .
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 using flake:
python3 -m flake8 bin/generate_repos.py
# from root level of Submitty repository... to lint a specific file using pylint:
python3 -m pylint bin/generate_repos.py
If you wish to automatically fix the basic linting problems, you can use black formatter:
# install black formatter
pip install git+https://github.com/psf/black
# formats all the files in that directory
# formats specified file
See also: Python Style Guide
The PHP code of Submitty is linted using phpcs. The following instructions were tested for Windows:
First, you will need PHP installed on your host system first. See Installing PHP*
Next, you will need Composer installed on your host system as well. During this install, you will need to change settings in a php.ini file. Change the settings the prompt recommends.
composer global require slevomat/coding-standardand
composer global require "squizlabs/php_codesniffer=*"inside your terminal.
sitedirectory in your Submitty repository and run
php vendor/bin/phpcs --extensions=php ./appinside your
sitedirectory. You can change
./appif you want to lint only a specific file.
See also: PHP Style Guide
PHP Static Analysis
The PHP code of Submitty is statically analyzed by phpstan.
We recommend running it inside the VM as it is already installed on it. Simply
vagrant ssh inside your Submitty
folder and navigate to
# from root level of Submitty repository
php site/vendor/bin/phpstan analyze -c site/phpstan.neon
# or if in the site/ directory of the Submitty repository
php vendor/bin/phpstan analyze
Unlike flake8 and phpcs, a path or file MUST be passed to phpstan.
phpstan maintains a list of known errors in the phpstan-baseline.neon file. If you fix one of these errors, you would need to regenerate this file which can be done by doing:
php vendor/bin/phpstan analyze app public/index.php socket/index.php --generate-baseline --memory-limit 2G
--memory_limit 2G is necessary when phpstan will otherwise not have enough memory
to generate a new baseline. You can see how much memory phpstan has been using with the
Submitty Test Script for PHP Linting
submitty_test script is an alias for the
SUBMITTY_TEST.sh script, similar to
This script streamlines the process of PHP linting by performing the following steps:
- Changes the directory to
- Installs Composer if not already installed (skips if Composer is already installed).
- Executes the specified PHP linting command.
- Returns to the original directory.
phpcs: Runs PHP CodeSniffer.
phpstan: Runs PHP static analysis.
php-lint: Runs both PHP CodeSniffer and PHPStan.
submitty_test script accepts additional arguments, such as
submitty_test php-lint --memory-limit 2G
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