@@ -11,10 +11,41 @@ as per the editor.
1111
1212### ` configuration `
1313
14- Path to a ` ruff.toml ` or ` pyproject.toml ` file to use for configuration.
14+ The ` configuration ` setting allows you to configure Ruff's behavior directly from an editor. This
15+ can be done in one of the following ways:
1516
16- By default, Ruff will discover configuration for each project from the filesystem, mirroring the
17- behavior of the Ruff CLI.
17+ 1 . ** Configuration file path:** Specify the path to a ` ruff.toml ` or ` pyproject.toml ` file that
18+ contains the configuration. User home directory and environment variables will be expanded.
19+ 2 . ** Inline JSON configuration:** Directly provide the configuration as a JSON object. This is
20+ similar to how the configuration is specified in the settings tab on the
21+ [ playground] ( https://play.ruff.sh/ ) .
22+
23+ !!! note "Added in Ruff ` 0.9.8 ` "
24+ The ** Inline JSON Configuration** option was introduced in Ruff ` 0.9.8 ` , allowing you to define
25+ settings directly in your editor without relying on an external file.
26+
27+ By default, if no ` configuration ` is specified, Ruff will automatically detect and load settings
28+ from a configuration file in the project's filesystem, consistent with the behavior of the Ruff CLI.
29+
30+ When both an editor-provided configuration and a local configuration file are present, you can
31+ control how Ruff resolves conflicts between them using the
32+ [ ` configurationPreference ` ] ( #configurationpreference ) setting.
33+
34+ #### Resolution order
35+
36+ In an editor, Ruff supports three sources of configuration, prioritized as follows (from highest to
37+ lowest):
38+
39+ 1 . ** Specific settings:** Individual settings like [ ` lineLength ` ] ( #linelength ) or
40+ [ ` lint.select ` ] ( #select ) defined in the editor
41+ 2 . [ ** ` ruff.configuration ` ** ] ( #configuration ) : Settings provided via the
42+ [ ` configuration ` ] ( #configuration ) field (either a path to a configuration file or an inline
43+ configuration object)
44+ 3 . ** Configuration file:** Settings defined in a ` ruff.toml ` or ` pyproject.toml ` file in the
45+ project's filesystem (if present)
46+
47+ For example, if the line length is specified in all three sources, Ruff will use the value from the
48+ specific settings in the editor i.e., the [ ` lineLength ` ] ( #linelength ) setting.
1849
1950** Default value** : ` null `
2051
@@ -24,39 +55,120 @@ behavior of the Ruff CLI.
2455
2556=== "VS Code"
2657
27- ```json
28- {
29- "ruff.configuration": "~/path/to/ruff.toml"
30- }
31- ```
58+ === "Using a configuration file"
59+
60+ ```json
61+ {
62+ "ruff.configuration": "~/path/to/ruff.toml"
63+ }
64+ ```
65+
66+ === "Using inline configuration"
67+
68+ ```json
69+ {
70+ "ruff.configuration": {
71+ "lint": {
72+ "unfixable": ["F401"],
73+ "extend-select": ["TID251"],
74+ "flake8-tidy-imports": {
75+ "banned-api": {
76+ "typing.TypedDict": {
77+ "msg": "Use `typing_extensions.TypedDict` instead",
78+ }
79+ }
80+ }
81+ },
82+ "format": {
83+ "quote-style": "single"
84+ }
85+ }
86+ }
87+ ```
88+
3289
3390=== "Neovim"
3491
35- ```lua
36- require('lspconfig').ruff.setup {
37- init_options = {
38- settings = {
39- configuration = "~/path/to/ruff.toml"
92+ === "Using a configuration file"
93+
94+ ```lua
95+ require('lspconfig').ruff.setup {
96+ init_options = {
97+ configuration = "~/path/to/ruff.toml"
98+ }
4099 }
41- }
42- }
43- ```
100+ ```
101+
102+ === "Using inline configuration"
103+
104+ ```lua
105+ require('lspconfig').ruff.setup {
106+ init_options = {
107+ configuration = {
108+ lint = {
109+ unfixable = {"F401"},
110+ ["extend-select"] = {"TID251"},
111+ ["flake8-tidy-imports"] = {
112+ ["banned-api"] = {
113+ ["typing.TypedDict"] = {
114+ msg = "Use `typing_extensions.TypedDict` instead"
115+ }
116+ }
117+ }
118+ },
119+ format = {
120+ ["quote-style"] = "single"
121+ }
122+ }
123+ }
124+ }
125+ ```
126+
44127
45128=== "Zed"
46129
47- ```json
48- {
49- "lsp": {
50- "ruff": {
51- "initialization_options": {
52- "settings": {
53- "configuration": "~/path/to/ruff.toml"
130+ === "Using a configuration file"
131+
132+ ```json
133+ {
134+ "lsp": {
135+ "ruff": {
136+ "initialization_options": {
137+ "configuration": "~/path/to/ruff.toml"
138+ }
54139 }
55140 }
56141 }
57- }
58- }
59- ```
142+ ```
143+
144+ === "Using inline configuration"
145+
146+ ```json
147+ {
148+ "lsp": {
149+ "ruff": {
150+ "initialization_options": {
151+ "configuration": {
152+ "lint": {
153+ "unfixable": ["F401"],
154+ "extend-select": ["TID251"],
155+ "flake8-tidy-imports": {
156+ "banned-api": {
157+ "typing.TypedDict": {
158+ "msg": "Use `typing_extensions.TypedDict` instead"
159+ }
160+ }
161+ }
162+ },
163+ "format": {
164+ "quote-style": "single"
165+ }
166+ }
167+ }
168+ }
169+ }
170+ }
171+ ```
60172
61173### ` configurationPreference `
62174
0 commit comments