Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ redirect_from:

__Minimum Version__: 3.8

For Python, we use [flake8](http://flake8.pycqa.org/en/latest/) and [pylint](https://pylint.readthedocs.io/en/stable/)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plzzwork this is an example of a comment corresponding to a line

For Python, we use [ruff](https://docs.astral.sh/ruff/)
to check Python code such that it follows things laid out in [PEP-8](https://www.python.org/dev/peps/pep-0008/),
[PEP-257](https://www.python.org/dev/peps/pep-0257/), etc. The code is linted as part of our automated Travis-CI
testsuite to ensure compliance. To locally lint the code, you will need to install four modules:
[PEP-257](https://www.python.org/dev/peps/pep-0257/), etc. The code is linted as part of our automated GitHub CI
testsuite to ensure compliance. To locally lint the code, you will need to install ruff:
```bash
pip3 install flake8 flake8-bugbear pylint
pip install ruff
```
and then you can just run `flake8` at the root to check all files or pass it an individual file to check just that.
To see all files that are currently checked as part of Travis-CI, please look at the `.flake8` config file.
and then you can just run `ruff check` at the root to check all files or pass it an individual file to check just that.
To see all files that are currently checked as part of GitHub CI, please look at the `pyproject.toml` config file.

For pylint, you can just run `pylint --recursive=y .` at the root to check all files or pass it an individual file.
For formatting, you can run `ruff format --check` to see formatting fixes, and `ruff format` to automatically apply them.
96 changes: 66 additions & 30 deletions _docs/developer/testing/linting_static_analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,24 @@ Be sure to start with the [Initial Set Up](/developer/testing/#initial-set-up) i

## Python Linting

The Python code of Submitty is linted using [flake8](https://flake8.pycqa.org/en/latest/),
[flake8-bugbear](https://github.com/PyCQA/flake8-bugbear), and [pylint](https://pylint.readthedocs.io/en/stable/).
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:
The Python code of Submitty is linted using [ruff](https://docs.astral.sh/ruff/) with the command `ruff check`.
Assuming you have it installed, you can run Ruff locally (on your host machine) by running the following commands from the root of your Submitty repository:

```bash
# from root level of Submitty repository using flake8
python3 -m flake8

# from root level of Submitty repository using pylint
python3 -m pylint --recursive=y .
ruff check
```

Optionally, you can pass in a specific file or directory to only lint that file or directory, e.g.:

```bash
# 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
ruff check /path/to/specific_file.py
```

If you wish to automatically fix the basic linting problems, you can use [black formatter](https://github.com/psf/black):
If you wish to automatically fix the basic linting problems, you can use `ruff format`:
```bash
# install black formatter
pip install git+https://github.com/psf/black

# formats all the files in that directory
black ./files/location/

# formats specified file
black ./location/file.py
ruff format
ruff format --check
ruff format /path/to/specific_file.py
```

See also: [Python Style Guide](/developer/coding_style_guide/python)
Expand Down Expand Up @@ -133,13 +118,15 @@ bash .setup/SUBMITTY_TEST.sh <command> [options]
- `phpcs`: Runs PHP CodeSniffer. [option: `--fix`]
- `phpstan`: Runs PHP static analysis. [option: `--memory-limit <#>G`, `--generate-baseline`]
- `php-lint`: Runs both PHP CodeSniffer and PHPStan (default options only).
- `twig-lint`: Lints all Twig templates. [option: `--format FORMAT`, `--show-deprecations`, `/path/to/file`]
- `php-unit`: Runs PHP unit tests. [option: `--filter testFunctionName`, `--debug`]
- `js-lint`: Runs eslint. [option: `--fix`]
- `js-unit`: Runs the jest test suite. [option: `--api`]
- `css-lint`: Runs stylelint. [option: `--fix`]
- `py-flake8`: Runs flake8. [option: `/path/to/specific_file.py`]
- `py-pylint`: Runs pylint. [option: `/path/to/specific_file.py`]
- `py-lint`: Runs pylint & flake8. [option: `/path/to/specific_file.py`]
- `shell-lint`: Runs ShellCheck.
- `yaml-lint`: Runs yamllint.
- `py-lint`: Runs ruff check. [option: `--fix`, `/path/to/specific_file.py`]
- `py-format`: Runs ruff format. [option: `--fix`, `/path/to/specific_file.py`]
- `py-unit`: Runs all Python unit tests except `migration`.
- `py-unit-utils` / `py-unit-migration` / `py-unit-autograder` / `py-unit-daemon`: Runs the respective Python unit test suite. [option: module, class, function ...]

Expand All @@ -155,6 +142,13 @@ submitty_test phpcs --fix
submitty_test phpstan
```

## Twig Linting:
```bash
submitty_test twig-lint
submitty_test twig-lint --show-deprecations
submitty_test twig-lint app/templates/File.twig # or any valid path to a (real) Twig file
```

## PHP Unit Testing:

```bash
Expand Down Expand Up @@ -231,14 +225,56 @@ npm run css-stylelint:fix

See also: [CSS Style Guide](/developer/coding_style_guide/css)

## Shell Linting

Code in Submitty's `filename.sh` files is linted using [ShellCheck](https://github.com/koalaman/shellcheck/wiki). As with other languages, `submitty_test` can be used as an alias for the `SUBMITTY_TEST.sh` script.

```bash
submitty_test shell-lint
```

Alternatively, you can run ShellCheck on your host system or on vagrant by running:

```bash
python3 run_shellcheck.py
```

***NOTE:** To run the `run_shellcheck.py` wrapper script for shellcheck, you must be in the project root on your host system or in `/usr/local/submitty/GIT_CHECKOUT/Submitty` on the VM.*

## YAML Linting

YAML and YML are linted using [yamllint](https://yamllint.readthedocs.io/en/stable/). As with other languages, `submitty_test` can be used as an alias for the `SUBMITTY_TEST.sh` script.

```bash
submitty_test yaml-lint
```

Alternatively, you can run yamllint on your host system (yamllint is not installed on the VM) by running:

```bash
yamllint .
```

***NOTE:** For yamllint to see the .yamllint baseline file, you must be in the project root on your host system.*

## Python Linting

Python is linted using [flake8](https://flake8.pycqa.org/en/latest/) and [pylint](https://pylint.readthedocs.io/en/stable/) in Submitty. As with other languages, `submitty_test` can be used as an alias for the `SUBMITTY_TEST.sh` script.
Python is linted using [ruff](https://docs.astral.sh/ruff/) with `ruff check`. As with other languages, `submitty_test` can be used as an alias for the `SUBMITTY_TEST.sh` script.

```bash
submitty_test py-lint
submitty_test py-lint --fix
submitty_test py-lint /path/to/specific_file.py
```

## Python Formatting

Python is formatted using [ruff](https://docs.astral.sh/ruff/) with `ruff format`. By default, this will be check only, eg `ruff format --check`. As with other languages, `submitty_test` can be used as an alias for the `SUBMITTY_TEST.sh` script.

```bash
submitty_test py-lint # option: /path/to/specific_file.py
submitty_test py-flake8 # option: /path/to/specific_file.py
submitty_test py-pylint # option: /path/to/specific_file.py
submitty_test py-format
submitty_test py-format --fix
submitty_test py-format /path/to/specific_file.py
```

See also: [Python Style Guide](/developer/coding_style_guide/python)
Expand Down
Loading