DavidAnson / vscode-markdownlint

Markdown linting and style checking for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint
MIT License
897 stars 166 forks source link

configuration does not apply in VS code? #244

Closed sandrock closed 2 years ago

sandrock commented 2 years ago

Hello, I'm trying to use the VS Code extension and cannot get the configuration file to work.

I have this log information from VS code:

INFO: Loading user/workspace configuration for "c:\Users\me\dd\project-xyz\things\X.md" (not in a workspace folder). INFO: Linting for "c:\Users\me\dd\project-xyz\things\X.md" will be run "onType". INFO: Loading user/workspace configuration for "c:\Users\me\dd\project-abc\docs\X.md" (not in a workspace folder). INFO: Linting for "c:\Users\me\dd\project-abc\docs\X.md" will be run "onType"

I have configuration files at location c:\Users\me\dd\project-xyz and c:\Users\me\dd\project-abc. I tried many formats:

.markdownlint.cjs

// @ts-check

"use strict";

module.exports = {
  "default": true,
  "MD003": "setext_with_atx",
  "MD009": false,
  "MD012": false
}

.markdownlint.json

{
  "MD003": "setext_with_atx",
  "MD009": false,
  "MD012": false
}

.markdownlint.yaml

MD003: setext_with_atx
MD009: false
MD012: false

VS code still shows me the warnings that I want to disable.

What am I doing wrong?

DavidAnson commented 2 years ago

Configuration files are read from directories in a project when that folder is open in VS Code. It seems like maybe you do not have a project open and are just opening loose Markdown files, in which case it uses only the user-level configuration you might have set in VS Code's Settings.

DavidAnson commented 2 years ago

Also, the configuration for MD003's style parameter is incorrect; it should be: https://github.com/DavidAnson/markdownlint/blob/f87f9d080002281d96ac32f119d8c99c028a6ddb/test/headings_good_setext_with_atx.json

DavidAnson commented 2 years ago

You also seem to be running an old version of the extension. One of the INFO messages you show was removed from the code in March of 2021.

sandrock commented 2 years ago

Using:
Visual Studio Code 1.52.1
with extension markdownlint v0.40.3 (fresh install)
on Window 10.


It seems like maybe you do not have a project open and are just opening loose Markdown files,

Yes.

in which case it uses only the user-level configuration you might have set in VS Code's Settings.

Oh.

So I created a user-levle configuration and it works. Thanks.

Is there any possibility to make the extension work when a folder is not open in Code?

DavidAnson commented 2 years ago

Great! Without a directory open in Code, the extension doesn't know how far up the tree to look for configuration files. If it looked only in the current directory, it would apply the wrong settings sometimes. Opening a directory is a clear indication to this extension and others what the extent of a project is. Code itself stores workspace settings in ./.vscode of a project and only knows where that is when a directory is open.

sandrock commented 2 years ago

I understand the settings lookup process is done when a workspace is open. I would like to know what could go wrong if a similar process was implemented for when no workspace is open.

Code could look at each parent folder until it finds one of the known configuration file?

Why can't it look far up the tree to look for configuration files?

DavidAnson commented 2 years ago
sandrock commented 2 years ago

Okay. Thanks!

stefan-toubia commented 1 year ago

I'd like to point out that the current behavior is potentially problematic for multi-root workspaces, and that ideally tools like markdownlint should also include parent directories of a workspace folder when attempting to resolve config files.

Take this simplified example of a monorepo:

/repo
  .markdownlint.jsonc
  /project-a
  /project-b
  ..
  /project-z

It's feasible to configure a multi-root workspace where only some of the subprojects are configured as workspace folders:

// repo.code-workspace
{
  "folders": ["/.../repo", "/.../repo/project-b", "/.../repo/project-x"]
}

This means that currently in the above example, linting is broken in project-b and project-x workspace folders because the repo root config file is in a parent of the workspace folder root.

DavidAnson commented 1 year ago

Configuration files are able to reference things above the folder, root directory. That should be adequate for the scenario described here.