Skip to content

omnilib/vscode-ufmt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

µfmt: safe, atomic formatting and import sorting

µfmt is a code formatter and import sorter for Python and Visual Studio Code, built on top of black and µsort, with experimental support for ruff-api:

Black makes code review faster by producing the smallest diffs possible. Blackened code looks the same regardless of the project you’re reading.

μsort is a safe, minimal import sorter. Its primary goal is to make no “dangerous” changes to code, and to make no changes on code style.

µfmt formats files in-memory, first with µsort and then with black, before writing any changes back to disk. This enables a combined, atomic formatting steps in VS Code, without any chance of conflict or intermediate changes between the import sorter and the code formatter.

Note:

  • This extension requires Python version 3.9 or newer.
  • The extension comes bundled with the latest version of µfmt 2.x, as well as black, µsort, and ruff-api.

Usage

Once installed, "µfmt" will be available as a formatter for Python files (extension id: omnilib.ufmt). µfmt can be set as the default formatter by adding the following to your settings:

"[python]": {
    "editor.defaultFormatter": "omnilib.ufmt"
}

or through the command pallete option "Format Document With...":

Command pallete 'format document with'

Follow-up option 'Configure default formatter'

Be sure to disable the legacy Python formatter, if enabled:

"python.formatting.provider": "none"

Format on Save

VS Code can automatically format your Python files when saving by adding the following to your settings:

"[python]": {
    "editor.defaultFormatter": "omnilib.ufmt",
    "editor.formatOnSave": true
}

Resources