Static analysis configuration¶
Static analysis performed by the fmt
command is (by default) backed entirely by Ruff.
Hatch provides default settings that user configuration can extend.
Extending config¶
When defining your configuration, be sure to use options that are prefixed by extend-
such as extend-select
, for example:
[tool.ruff.format]
preview = true
quote-style = "single"
[tool.ruff.lint]
preview = true
extend-select = ["C901"]
[tool.ruff.lint.extend-per-file-ignores]
"docs/.hooks/*" = ["INP001", "T201"]
[tool.ruff.lint.isort]
known-first-party = ["foo", "bar"]
[format]
preview = true
quote-style = "single"
[lint]
preview = true
extend-select = ["C901"]
[lint.extend-per-file-ignores]
"docs/.hooks/*" = ["INP001", "T201"]
[lint.isort]
known-first-party = ["foo", "bar"]
Note
When not persisting config, there is no need to explicitly extend the defaults as Hatch automatically handles that.
Persistent config¶
If you want to store the default configuration in the project, set an explicit path like so:
[tool.hatch.envs.hatch-static-analysis]
config-path = "ruff_defaults.toml"
[envs.hatch-static-analysis]
config-path = "ruff_defaults.toml"
Then instruct Ruff to consider your configuration as an extension of the default file:
[tool.ruff]
extend = "ruff_defaults.toml"
extend = "ruff_defaults.toml"
Anytime you wish to update the defaults (such as when upgrading Hatch), you must run the fmt
command once with the --sync
flag e.g.:
hatch fmt --check --sync
Tip
This is the recommended approach since it allows other tools like IDEs to use the default configuration.
No config¶
If you don't want Hatch to use any of its default configuration and rely entirely on yours, set the path to anything and then simply don't extend
in your Ruff config:
[tool.hatch.envs.hatch-static-analysis]
config-path = "none"
[envs.hatch-static-analysis]
config-path = "none"
Customize behavior¶
You can fully alter the behavior of the environment used by the fmt
command. See the how-to for a detailed example.
Dependencies¶
Pin the particular version of Ruff by explicitly defining the environment dependencies:
[tool.hatch.envs.hatch-static-analysis]
dependencies = ["ruff==X.Y.Z"]
[envs.hatch-static-analysis]
dependencies = ["ruff==X.Y.Z"]
Scripts¶
If you want to change the default commands that are executed, you can override the scripts. The following four scripts must be defined:
[tool.hatch.envs.hatch-static-analysis.scripts]
format-check = "..."
format-fix = "..."
lint-check = "..."
lint-fix = "..."
[envs.hatch-static-analysis.scripts]
format-check = "..."
format-fix = "..."
lint-check = "..."
lint-fix = "..."
The format-*
scripts correspond to the --formatter
/-f
flag while the lint-*
scripts correspond to the --linter
/-l
flag. The *-fix
scripts run by default while the *-check
scripts correspond to the --check
flag.
Reminder
If you choose to use different tools for static analysis, be sure to update the required dependencies.
Installer¶
By default, UV is enabled. You may disable that behavior as follows:
[tool.hatch.envs.hatch-static-analysis]
installer = "pip"
[envs.hatch-static-analysis]
installer = "pip"
Default settings¶
Non-rule settings¶
- Line length set to 120
- Docstring formatting enabled with line length set to 80
- Only absolute imports are allowed, except for tests
- The normalized project name is a known first party import
Per-file ignored rules¶
Selected rules¶
The following rules are based on version 0.4.2 of Ruff. Rules with a P are only selected when preview mode is enabled.
- A001, A002, A003
- ARG001, ARG002, ARG003, ARG004, ARG005
- ASYNC100, ASYNC101, ASYNC102
- B002, B003, B004, B005, B006, B007, B008, B009, B010, B011, B012, B013, B014, B015, B016, B017, B018, B019, B020, B021, B022, B023, B024, B025, B026, B028, B029, B030, B031, B032, B033, B034, B035, B904, B905, B909P
- BLE001
- C400, C401, C402, C403, C404, C405, C406, C408, C409, C410, C411, C413, C414, C415, C416, C417, C418, C419
- COM818
- DTZ001, DTZ002, DTZ003, DTZ004, DTZ005, DTZ006, DTZ007, DTZ011, DTZ012
- E101, E112P, E113P, E115P, E116P, E201P, E202P, E203P, E211P, E221P, E222P, E223P, E224P, E225P, E226P, E227P, E228P, E231P, E241P, E242P, E251P, E252P, E261P, E262P, E265P, E266P, E271P, E272P, E273P, E274P, E275P, E401, E402, E502P, E701, E702, E703, E711, E712, E713, E714, E721, E722, E731, E741, E742, E743, E902, E999
- EM101, EM102, EM103
- EXE001, EXE002, EXE003, EXE004, EXE005
- F401, F402, F403, F404, F405, F406, F407, F501, F502, F503, F504, F505, F506, F507, F508, F509, F521, F522, F523, F524, F525, F541, F601, F602, F621, F622, F631, F632, F633, F634, F701, F702, F704, F706, F707, F722, F811, F821, F822, F823, F841, F842, F901
- FA100, FA102
- FBT001, FBT002
- FLY002
- FURB105P, FURB110P, FURB113P, FURB118P, FURB129P, FURB131P, FURB132P, FURB136P, FURB142P, FURB145P, FURB148P, FURB152P, FURB157P, FURB161P, FURB163P, FURB164P, FURB166P, FURB167P, FURB168P, FURB169P, FURB171P, FURB177P, FURB180P, FURB181P, FURB187P, FURB192P
- G001, G002, G003, G004, G010, G101, G201, G202
- I001, I002
- ICN001, ICN002, ICN003
- INP001
- INT001, INT002, INT003
- ISC003
- LOG001, LOG002, LOG007, LOG009
- N801, N802, N803, N804, N805, N806, N807, N811, N812, N813, N814, N815, N816, N817, N818, N999
- PERF101, PERF102, PERF401, PERF402, PERF403P
- PGH005
- PIE790, PIE794, PIE796, PIE800, PIE804, PIE807, PIE808, PIE810
- PLC0105, PLC0131, PLC0132, PLC0205, PLC0208, PLC0414, PLC0415P, PLC1901P, PLC2401P, PLC2403P, PLC2701P, PLC2801P, PLC3002
- PLE0100, PLE0101, PLE0115P, PLE0116, PLE0117, PLE0118, PLE0237, PLE0241, PLE0302, PLE0303P, PLE0304P, PLE0305P, PLE0307, PLE0308P, PLE0309P, PLE0604, PLE0605, PLE0643P, PLE0704P, PLE1132P, PLE1141P, PLE1142, PLE1205, PLE1206, PLE1300, PLE1307, PLE1310, PLE1507, PLE1519P, PLE1520P, PLE1700, PLE2502, PLE2510, PLE2512, PLE2513, PLE2514, PLE2515, PLE4703P
- PLR0124, PLR0133, PLR0202P, PLR0203P, PLR0206, PLR0402, PLR1701, PLR1704P, PLR1711, PLR1714, PLR1722, PLR1730P, PLR1733P, PLR1736P, PLR2004, PLR2044P, PLR5501, PLR6104P, PLR6201P, PLR6301P
- PLW0108P, PLW0120, PLW0127, PLW0128P, PLW0129, PLW0131, PLW0133P, PLW0177P, PLW0211P, PLW0245P, PLW0406, PLW0602, PLW0603, PLW0604P, PLW0642P, PLW0711, PLW1501P, PLW1508, PLW1509, PLW1510, PLW1514P, PLW1641P, PLW2101P, PLW2901, PLW3201P, PLW3301
- PT001, PT002, PT003, PT006, PT007, PT008, PT009, PT010, PT011, PT012, PT013, PT014, PT015, PT016, PT017, PT018, PT019, PT020, PT021, PT022, PT023, PT024, PT025, PT026, PT027
- PYI001, PYI002, PYI003, PYI004, PYI005, PYI006, PYI007, PYI008, PYI009, PYI010, PYI011, PYI012, PYI013, PYI014, PYI015, PYI016, PYI017, PYI018, PYI019, PYI020, PYI021, PYI024, PYI025, PYI026, PYI029, PYI030, PYI032, PYI033, PYI034, PYI035, PYI036, PYI041, PYI042, PYI043, PYI044, PYI045, PYI046, PYI047, PYI048, PYI049, PYI050, PYI051, PYI052, PYI053, PYI054, PYI055, PYI056, PYI058
- RET503, RET504, RET505, RET506, RET507, RET508
- RSE102
- RUF001, RUF002, RUF003, RUF005, RUF006, RUF007, RUF008, RUF009, RUF010, RUF012, RUF013, RUF015, RUF016, RUF017, RUF018, RUF019, RUF020, RUF021P, RUF022P, RUF023P, RUF024P, RUF025P, RUF026P, RUF027P, RUF028P, RUF029P, RUF100
- S101, S102, S103, S104, S105, S106, S107, S108, S110, S112, S113, S201, S202, S301, S302, S303, S304, S305, S306, S307, S308, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S323, S324, S401P, S402P, S403P, S405P, S406P, S407P, S408P, S409P, S411P, S412P, S413P, S415P, S501, S502, S503, S504, S505, S506, S507, S508, S509, S601, S602, S604, S605, S606, S607, S608, S609, S610P, S611, S612, S701, S702
- SIM101, SIM102, SIM103, SIM105, SIM107, SIM108, SIM109, SIM110, SIM112, SIM113, SIM114, SIM115, SIM116, SIM117, SIM118, SIM201, SIM202, SIM208, SIM210, SIM211, SIM212, SIM220, SIM221, SIM222, SIM223, SIM300, SIM910, SIM911
- SLF001
- SLOT000, SLOT001, SLOT002
- T100, T201, T203
- TCH001, TCH002, TCH003, TCH004, TCH005, TCH010
- TD004, TD005, TD006, TD007
- TID251, TID252, TID253
- TRIO100, TRIO105, TRIO109, TRIO110, TRIO115
- TRY002, TRY003, TRY004, TRY201, TRY300, TRY301, TRY302, TRY400, TRY401
- UP001, UP003, UP004, UP005, UP006, UP007, UP008, UP009, UP010, UP011, UP012, UP013, UP014, UP015, UP017, UP018, UP019, UP020, UP021, UP022, UP023, UP024, UP025, UP026, UP027, UP028, UP029, UP030, UP031, UP032, UP033, UP034, UP035, UP036, UP037, UP038, UP039, UP040, UP041, UP042P
- W291, W292, W293, W391P, W505, W605
- YTT101, YTT102, YTT103, YTT201, YTT202, YTT203, YTT204, YTT301, YTT302, YTT303