Exercise 2: formatting and linting tools - rnousia/example-plugin-for-quc2026 GitHub Wiki

Formatting and linting

VS Code

Using workspace files

During this workshop, open the project using the provided .code-workspace file instead of opening the folder directly.

Workspace files allow VS Code to store project-specific settings, recommended extensions, debugging configurations, and tasks. This helps to make sure everyone uses a consistent development environment and reduces the amount of manual setup required.

For more information about VS Code workspaces, check the Microsoft documentation.

PyCharm

[!NOTE] Although PyCharm can be used in this workshop and is the main editor of choise for Joona, only basics are covered since this workshop focuses on using VsCode

With PyCharm, just open the folder. Virtual environment will be found automatically.


Step 1: Open VS Code workspace and install the recommended extensions

From terminal/command line:

code painter-plugin.code-workspace

Or, you can open the folder in VS Code, select workspace file and click button Open Workspace.

[!NOTE] Newer VS Code versions might start the project in restricted mode

In this case, just click on the Restricted Mode button and confirm with "Trust"

After the workspace has been loaded, VS Code should prompt you to install the recommended extensions. If the prompt dissappears, extensions can be installed via Extensions Panel by typing @recommended into the search bar and clicking Install Workspace Recommended Extensions button. Extensions are needed for the code formatting and linting to work in the next step.

If a warning dialog displays invalid Python Interpreter, just select one from the list:


Step 2: Install dependencies if needed

Linting and formatting tools need to be installed in the virtual environment for VS Code extensions to be able to use them.

If uv sync command was not run during exercise 1, do it now:

uv sync

Step 3: Verify linting and formatting works

Try making changes for example to plugin.py file. Formatting will happen after file is saved manually (autosave will not format files) so try Ctrl+S to see what happens.

Troubleshoot

If formatting does not work

  1. Make sure the Python interpreter is selected (there should be python version shown in the lower right corner)
  1. Check that all the necessary extensions are installed and running without error (again, hover on {} icon next to "Python" text in the lower right corner):
  1. Sometimes it might help to reload the window or restart extensions
  • Ctrl + Shift + P opens the Command Palette where all the VS Code commands can be run
    • Developer: Reload Window
    • Ruff: Restart Server

You may also try to make changes having linting errors (e.g. use single quote on strings) without Ctrl+S to check how pre-commit hooks work.

Stage your changes:

git add --all

Make a commmit (prek should install hooks which will take some time on the first time):

git commit -m "wip: message shall not pass"

[!Note] Prek checks will modify the files a bit, so run last previous commands again to get to the gitlint part of the checks.

Then try with a correct conventional commit message (see the suggestion provided by gitlint).