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.
Python Linting
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
PHP Linting
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.
-
Run
composer global require slevomat/coding-standard
andcomposer global require "squizlabs/php_codesniffer=*"
inside your terminal. -
cd
to yoursite
directory in your Submitty repository and runcomposer update
. -
Now run
php vendor/bin/phpcs --extensions=php ./app
inside yoursite
directory. You can change./app
if 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
/usr/local/submitty/GIT_CHECKOUT/Submitty/site/
Then run:
# from root level of Submitty repository
php site/vendor/bin/phpstan analyze -c site/phpstan.neon site/app site/public/index.php site/socket/index.php
# or if in the site/ directory of the Submitty repository
php vendor/bin/phpstan analyze app public/index.php socket/index.php
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
JavaScript Linting
The frontend JavaScript code Submitty uses is linted using eslint.
You can run eslint on your host system or on vagrant by navigating into the site/
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>
See also: JavaScript Style Guide
CSS Linting
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 site/
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