Static analysis configuration¶
Static analysis performed by the check code and check fmt commands is (by default) backed entirely by Ruff.
Hatch provides default settings that user configuration can extend.
Note
The fmt command is being deprecated. Use hatch check code for linting and hatch check fmt for formatting instead.
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 check code or check fmt command once with the --sync flag e.g.:
hatch check code --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 environments used by the check code and check fmt commands. See the how-to for a detailed example.
The check code command uses the hatch-check-code environment, and the check fmt command uses the hatch-check-fmt environment. The legacy fmt command continues to use the hatch-static-analysis environment.
Dependencies¶
Pin the particular version of Ruff by explicitly defining the environment dependencies:
[tool.hatch.envs.hatch-check-code]
dependencies = ["ruff==X.Y.Z"]
[tool.hatch.envs.hatch-check-fmt]
dependencies = ["ruff==X.Y.Z"]
[envs.hatch-check-code]
dependencies = ["ruff==X.Y.Z"]
[envs.hatch-check-fmt]
dependencies = ["ruff==X.Y.Z"]
Scripts¶
If you want to change the default commands that are executed, you can override the scripts.
For the hatch-check-code environment:
[tool.hatch.envs.hatch-check-code.scripts]
lint-check = "..."
lint-fix = "..."
[envs.hatch-check-code.scripts]
lint-check = "..."
lint-fix = "..."
For the hatch-check-fmt environment:
[tool.hatch.envs.hatch-check-fmt.scripts]
format-check = "..."
format-fix = "..."
[envs.hatch-check-fmt.scripts]
format-check = "..."
format-fix = "..."
The *-fix scripts run by default while the *-check scripts run when the --fix flag is not passed.
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-check-code]
installer = "pip"
[tool.hatch.envs.hatch-check-fmt]
installer = "pip"
[envs.hatch-check-code]
installer = "pip"
[envs.hatch-check-fmt]
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.13.2 of Ruff. Rules with a P are only selected when preview mode is enabled.
There are 631 selected stable rules and 112 selected preview rules.
Selected rules
- A001, A002, A003, A004, A005, A006
- ARG001, ARG002, ARG003, ARG004, ARG005
- ASYNC100, ASYNC105, ASYNC109, ASYNC110, ASYNC115, ASYNC116, ASYNC210, ASYNC220, ASYNC221, ASYNC222, ASYNC230, ASYNC251, ASYNC212P, ASYNC240P, ASYNC250P
- 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, B039, B904, B905, B911, B901P, B903P, B909P, B912P
- BLE001
- C400, C401, C402, C403, C404, C405, C406, C408, C409, C410, C411, C413, C414, C415, C416, C417, C418, C419, C420
- COM818
- DOC201P, DOC202P, DOC402P, DOC403P, DOC501P, DOC502P
- DTZ001, DTZ002, DTZ003, DTZ004, DTZ005, DTZ006, DTZ007, DTZ011, DTZ012, DTZ901
- E101, E112P, E113P, E115P, E116P, E201P, E202P, E203P, E204P, 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
- 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
- FAST001, FAST002, FAST003
- FBT001, FBT002
- FLY002
- FURB105, FURB116, FURB122, FURB129, FURB132, FURB136, FURB157, FURB161, FURB162, FURB163, FURB166, FURB167, FURB168, FURB169, FURB177, FURB181, FURB187, FURB188, FURB110P, FURB113P, FURB118P, FURB131P, FURB142P, FURB145P, FURB148P, FURB152P, FURB154P, FURB156P, FURB164P, FURB171P, FURB180P, FURB189P, FURB192P
- G001, G002, G003, G004, G010, G101, G201, G202
- I001, I002
- ICN001, ICN002, ICN003
- INP001
- INT001, INT002, INT003
- ISC003
- LOG001, LOG002, LOG007, LOG009, LOG014, LOG015, LOG004P
- N801, N802, N803, N804, N805, N806, N807, N811, N812, N813, N814, N815, N816, N817, N818, N999
- PERF101, PERF102, PERF401, PERF402, PERF403
- PGH005
- PIE790, PIE794, PIE796, PIE800, PIE804, PIE807, PIE808, PIE810
- PLC0105, PLC0131, PLC0132, PLC0205, PLC0206, PLC0208, PLC0414, PLC0415, PLC0207P, PLC1802, PLC1901P, PLC2401, PLC2403, PLC2701P, PLC2801P, PLC3002
- PLE0100, PLE0101, PLE0115, PLE0116, PLE0117, PLE0118, PLE0237, PLE0241, PLE0302, PLE0303, PLE0305, PLE0307, PLE0308, PLE0309, PLE0604, PLE0605, PLE0643, PLE0704, PLE0304P, PLE1132, PLE1142, PLE1205, PLE1206, PLE1300, PLE1307, PLE1310, PLE1507, PLE1519, PLE1520, PLE1700, PLE1141P, PLE2502, PLE2510, PLE2512, PLE2513, PLE2514, PLE2515, PLE4703P
- PLR0124, PLR0133, PLR0206, PLR0402, PLR0202P, PLR0203P, PLR1704, PLR1711, PLR1714, PLR1716, PLR1722, PLR1730, PLR1733, PLR1736, PLR2004, PLR2044, PLR5501, PLR6104P, PLR6201P, PLR6301P
- PLW0120, PLW0127, PLW0128, PLW0129, PLW0131, PLW0133, PLW0177, PLW0211, PLW0245, PLW0406, PLW0602, PLW0603, PLW0604, PLW0642, PLW0711, PLW0108P, PLW0244P, PLW1501, PLW1507, PLW1508, PLW1509, PLW1510, PLW1641, PLW1514P, PLW2101, PLW2901, PLW3301, PLW3201P
- 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, PT028, PT030, PT031, PT029P
- 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, PYI057, PYI058, PYI059, PYI061, PYI062, PYI063, PYI064, PYI066
- RET503, RET504, RET505, RET506, RET507, RET508
- RSE102
- RUF001, RUF002, RUF003, RUF005, RUF006, RUF007, RUF008, RUF009, RUF010, RUF012, RUF013, RUF015, RUF016, RUF017, RUF018, RUF019, RUF020, RUF021, RUF022, RUF023, RUF024, RUF026, RUF028, RUF030, RUF032, RUF033, RUF034, RUF040, RUF041, RUF043, RUF046, RUF048, RUF049, RUF051, RUF053, RUF057, RUF058, RUF059, RUF027P, RUF029P, RUF031P, RUF036P, RUF037P, RUF038P, RUF039P, RUF045P, RUF047P, RUF052P, RUF054P, RUF055P, RUF056P, RUF060P, RUF061P, RUF063P, RUF064P, RUF065P, RUF100, RUF101, RUF102P
- 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, 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, S610, S611, S612, S701, S702, S704
- 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, SIM905, SIM910, SIM911
- SLF001
- SLOT000, SLOT001, SLOT002
- T100, T201, T203
- TC001, TC002, TC003, TC004, TC005, TC006, TC007, TC010, TC008P
- TD004, TD005, TD006, TD007
- TID251, TID252, TID253
- TRY002, TRY003, TRY004, TRY201, TRY203, TRY300, TRY301, 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, UP028, UP029, UP030, UP031, UP032, UP033, UP034, UP035, UP036, UP037, UP039, UP040, UP041, UP043, UP044, UP045, UP046, UP047, UP049, UP050, UP042P
- W291, W292, W293, W391P, W505, W605
- YTT101, YTT102, YTT103, YTT201, YTT202, YTT203, YTT204, YTT301, YTT302, YTT303
Unselected¶
There are 189 unselected rules.
Unselected rules
- AIR001, AIR002, AIR301, AIR302, AIR311, AIR312
- ANN001, ANN002, ANN003, ANN101, ANN102, ANN201, ANN202, ANN204, ANN205, ANN206, ANN401
- B027
- C901
- COM812, COM819
- CPY001
- D100, D101, D102, D103, D104, D105, D106, D107, D200, D201, D202, D203, D204, D205, D206, D207, D208, D209, D210, D211, D212, D213, D214, D215, D300, D301, D400, D401, D402, D403, D404, D405, D406, D407, D408, D409, D410, D411, D412, D413, D414, D415, D416, D417, D418, D419
- DJ001, DJ003, DJ006, DJ007, DJ008, DJ012, DJ013
- E111, E114, E117, E301, E302, E303, E304, E305, E306, E501, E999
- ERA001
- FBT003
- FIX001, FIX002, FIX003, FIX004
- FURB101, FURB103, FURB140
- ISC001, ISC002
- NPY001, NPY002, NPY003, NPY201
- PD002, PD003, PD004, PD007, PD008, PD009, PD010, PD011, PD012, PD013, PD015, PD101, PD901
- PERF203
- PGH001, PGH002, PGH003, PGH004
- PLR0904, PLR0911, PLR0912, PLR0913, PLR0914, PLR0915, PLR0916, PLR0917, PLR1701, PLR1702, PLR1706
- PT004, PT005
- PTH100, PTH101, PTH102, PTH103, PTH104, PTH105, PTH106, PTH107, PTH108, PTH109, PTH110, PTH111, PTH112, PTH113, PTH114, PTH115, PTH116, PTH117, PTH118, PTH119, PTH120, PTH121, PTH122, PTH123, PTH124, PTH201, PTH202, PTH203, PTH204, PTH205, PTH206, PTH207, PTH208, PTH210, PTH211
- Q000, Q001, Q002, Q003, Q004
- RET501, RET502
- RUF011, RUF035, RUF200
- S320, S404, S410, S603
- SIM401
- TD001, TD002, TD003
- TRY200
- UP027, UP038
- W191