Prettier
The nf-core community aims for a normalized code style. To do so multiple code linting tests are checked and one of them is made with Prettier. It checks that the code style is correctly formatted, it supports many languages (thus many different files) and can be integrated with most editors.
You may have stumbled into Prettier for the first time when seeing errors like this, when attempting a Pull Request:
Prefer seeing this in action? There is a bytesize talk on this topic that you can watch: Bytesize 41: Code linting tools
Running with an editor plugin
You can install prettier as an extension of your favorite code editor and it will fix formatting issues every time you hit save.
For VSCode there is a Prettier extension on the VSCode Marketplace. It’s also included in the nf-core VSCode extension pack.
Running with pre-commit
Another solution is to make sure that every time you commit code on a repository, prettier is run on the updated files.
To do this, you can use pre-commit.
Most nf-core repositories should already come with a .pre-commit-config.yaml
config file that instructs pre-commit to run prettier:
To use this, make sure that the pre-commit tool is installed:
and then install the pre-commit hook in the repository working directory:
After this, every time you run git commit
the pre-commit tests will run and fix your formatting.
If any changes are made, the commit is aborted.
To continue, git add
the new changes and try again.
Running manually
If you prefer to be old-school, you can just install prettier in your shell environment. To do so, you can use the following command with conda:
Once installed, you can run prettier manually:
This will overwrite files with formatting fixes
To just check without auto-fixing, use prettier -c .
Running during your pull request
If you already created your pull request, you can add a comment with @nf-core-bot fix linting
and the kind @nf-core-bot
will run prettier for you and apply the required fixes to your code.
Ruff
Ruff is a tool for formatting Python code in a quick and efficient way. It is designed to be opinionated and enforce consistent standards in whitespace and style.
Several nf-core repositories come with a pyproject.toml
configuration file that sets the formatting defaults.
Command line
As with Prettier above, Ruff can be installed on the command line:
Then run Ruff and it will search recursively:
You can provide a file path if you prefer, or use ruff check
to test without editing files.
In Visual Studio Code
As with Prettier, there is a Ruff VSCode plugin that will run Ruff for you whenever you save a file.