You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-18Lines changed: 37 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -167,8 +167,6 @@ To temporarily disable linting of Markdown documents, run the `markdownlint.togg
167
167
168
168
## Configure
169
169
170
-
### markdownlint.config
171
-
172
170
By default (i.e., without customizing anything), all rules are enabled *except*[`MD013`/`line-length`](https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md013.md) because many files include lines longer than the conventional 80 character limit:
173
171
174
172
```json
@@ -178,22 +176,22 @@ By default (i.e., without customizing anything), all rules are enabled *except*
178
176
```
179
177
180
178
Rules can be enabled, disabled, and customized by creating a [JSON](https://en.wikipedia.org/wiki/JSON) file named `.markdownlint.jsonc`/`.markdownlint.json` or a [YAML](https://en.wikipedia.org/wiki/YAML) file named `.markdownlint.yaml`/`.markdownlint.yml` or a [JavaScript](https://en.wikipedia.org/wiki/JavaScript) file named `.markdownlint.cjs` in any directory of a project.
181
-
Additionally, options (which include rules and things like [`markdown-it` plugins](https://www.npmjs.com/search?q=keywords:markdown-it-plugin) and other settings) can be configured by creating a JSON file named `.markdownlint-cli2.jsonc` or a YAML file named `.markdownlint-cli2.yaml` or a JavaScript file named `.markdownlint-cli2.cjs` in any directory of a project.
179
+
Additionally, options (which include rules and other settings) can be configured by creating a JSON file named `.markdownlint-cli2.jsonc` or a YAML file named `.markdownlint-cli2.yaml` or a JavaScript file named `.markdownlint-cli2.cjs` in any directory of a project.
180
+
Rules can also be configured using VS Code's support for [user and workspace settings](https://code.visualstudio.com/docs/customization/userandworkspace).
182
181
183
182
> For more information about configuration file precedence and complete examples, see the [Configuration section of the markdownlint-cli2 README.md](https://github.com/DavidAnson/markdownlint-cli2#configuration).
184
183
185
-
A custom configuration is often defined by a `.markdownlint.json` file in the root of the project:
184
+
A custom rule configuration is often defined by a `.markdownlint.json` file in the root of the project:
186
185
187
186
```json
188
187
{
189
-
"default": true,
190
188
"MD003": { "style": "atx_closed" },
191
189
"MD007": { "indent": 4 },
192
190
"no-hard-tabs": false
193
191
}
194
192
```
195
193
196
-
To extend another configuration file, such a file can use the `extends` property to provide a relative path:
194
+
To extend another configuration file, use the `extends` property to provide a relative path:
197
195
198
196
```json
199
197
{
@@ -204,42 +202,63 @@ To extend another configuration file, such a file can use the `extends` property
204
202
205
203
Files referenced via `extends` do not need to be part of the current project (but usually are).
206
204
207
-
Rules can also be configured using VS Code's support for [user and workspace settings](https://code.visualstudio.com/docs/customization/userandworkspace).
205
+
Configuration sources have the following precedence (in decreasing order):
206
+
207
+
*`.markdownlint-cli2.{jsonc,yaml,cjs}` file in the same or parent directory
208
+
*`.markdownlint.{jsonc,json,yaml,yml,cjs}` file in the same or parent directory
209
+
* Visual Studio Code user/workspace settings (see [markdownlint.config](#markdownlintconfig) and [markdownlint.configFile](#markdownlintconfigfile) below)
210
+
* Default configuration (see above)
211
+
212
+
Configuration changes saved to any location take effect immediately.
213
+
Files referenced via `extends` are not monitored for changes.
214
+
Inherited configuration can be explicitly disabled (or re-enabled) in any configuration file.
215
+
216
+
When a workspace is open, running the `markdownlint.openConfigFile` command (from the Command Palette or by binding it to a keyboard shortcut) will open an editor for the `.markdownlint-cli2.{jsonc,yaml,cjs}` or `.markdownlint.{jsonc,json,yaml,yml,cjs}` configuration file in the root of the workspace.
217
+
If none of these files exist, a new `.markdownlint.json` containing the default rule configuration will be opened in the editor in the "pending save" state.
218
+
219
+
> **Note**: Because JavaScript is cached by VS Code after being loaded, edits to `.markdownlint.cjs`/`.markdownlint-cli2.cjs` require a restart of VS Code.
208
220
209
-
The above configuration might look like the following in VS Code's user settings file:
221
+
### markdownlint.config
222
+
223
+
> **Note**: Using a project-local configuration file is preferred because doing so works with command-line tools and is easier for collaboration.
224
+
225
+
The configuration above might look like the following in VS Code's user settings file:
210
226
211
227
```json
212
228
{
213
229
"editor.someSetting": true,
214
230
"markdownlint.config": {
215
-
"default": true,
216
231
"MD003": { "style": "atx_closed" },
217
232
"MD007": { "indent": 4 },
218
233
"no-hard-tabs": false
219
234
}
220
235
}
221
236
```
222
237
223
-
When using `extends`:
238
+
When using `extends` in this context:
224
239
225
240
* File paths referenced by `extends` from configuration files within a workspace are resolved relative to that configuration file.
226
241
* When running VS Code locally:
227
242
* File paths referenced by `extends` from user settings are resolved relative to the user's home directory (e.g., `%USERPROFILE%` on Windows or `$HOME` on macOS/Linux).
228
243
* File paths referenced by `extends` from workspace settings are resolved relative to the workspace folder.
229
244
* VS Code's [predefined variables](https://code.visualstudio.com/docs/editor/variables-reference)`${userHome}` and `${workspaceFolder}` can be used within an `extends` path from user or workspace settings to override the default behavior.
230
245
231
-
Configuration sources have the following precedence (in decreasing order):
246
+
### markdownlint.configFile
232
247
233
-
*`.markdownlint-cli2.{jsonc,yaml,cjs}` file in the same or parent directory
234
-
*`.markdownlint.{jsonc,json,yaml,yml,cjs}` file in the same or parent directory
235
-
* Visual Studio Code user/workspace settings
236
-
* Default configuration (see above)
248
+
The default behavior of storing configuration files in the root of a project works well most of the time.
249
+
However, projects that need to store configuration files in a different location can set `configFile` to the project-relative path of that file.
250
+
All [`markdownlint-cli2` configuration files used with `--config`](https://github.com/DavidAnson/markdownlint-cli2?tab=readme-ov-file#command-line) are supported.
237
251
238
-
Configuration changes saved to any location take effect immediately. Files referenced via `extends` are not monitored for changes. Inherited configuration can be explicitly disabled (or re-enabled) in any configuration file.
252
+
This looks like the following in VS Code's user settings:
239
253
240
-
When a workspace is open, running the `markdownlint.openConfigFile` command (from the Command Palette or by binding it to a keyboard shortcut) will open an editor for the `.markdownlint-cli2.{jsonc,yaml,cjs}` or `.markdownlint.{jsonc,json,yaml,yml,cjs}` configuration file in the root of the workspace. If none of these files exist, a new `.markdownlint.json` containing the default rule configuration will be opened in the editor in the "pending save" state.
> **Note**: Because JavaScript is cached by VS Code after being loaded, edits to `.markdownlint.cjs`/`.markdownlint-cli2.cjs` require a restart of VS Code.
261
+
If [markdownlint.config](#markdownlintconfig)is also set, the settings from `configFile` take precedence.
0 commit comments