How can one measure "code quality"?
Well... close!
Fortunately for use, there are tools that can help us locate code smells (remember those) and measure code quality. These tools are called linters. Though there are many linters out there, we will focus on pylint.
After this lesson you should:
- Know how to install and set up the Pylint code linter,
- Know the pros and cons of
pylint.
For the assignment, you may need to configure pylint to ignore some errors. Pylint is highly configurable. There are a lot of options to follow the needs of various projects and a lot of checks to activate if they suit your style.
You can generate a sample configuration file with --generate-toml-config or --generate-rcfile. Every option present on the command line before this will be included in the file. In practice, it is often better to use a minimal configuration file which only contains configuration overrides. For all other options, Pylint will use its default values.
Because the assignment already uses the pyproject.toml file, you will use that to configure pylint. A suggestion on how to configure that is as follows:
-
Generate a sample configuration file with
pylint --generate-toml-config > delete_this.toml. If you get the errorpylint: error: no such option: --generate-toml-config, ensure you have the latest version ofpylintinstalled. -
This configuration file contains a lot of options. Everything that's not commented is currently active. Imagine, for example, that you want to disable the
missing-module-docstringcheck. This is done by thedisableoption. So that's the option you need to add to thepyproject.tomlfile. -
Besides the option itself, you also need to know the option header. In this case it's
[tool.pylint."messages control"]. The header is the part between[and]before each group of options. -
So, in the
pyproject.tomlfile, add the following lines:[tool.pylint."messages control"] disable = [ "missing-module-docstring", # Add any other checks you want to disable here ]
-
Finally, you can delete the
delete_this.tomlfile andpylintwill use the configuration in thepyproject.tomlfile.
Remember you can always refer to Pylint user guide so see all the checks that are available.

