[GH-ISSUE #510] Asynchronous Rule's params.config will be overrided by other sync rules. #2265

Closed
opened 2026-03-07 20:06:07 +03:00 by kerem · 10 comments
Owner

Originally created by @chriswong on GitHub (Mar 20, 2022).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/510

Source Code:

markdownlint.js#L505

    params.config = effectiveConfig[ruleName];

markdownlint.js#L600

        const invokeRuleFunction = () => rule.function(params, onError);

Reproduction

# markdownlint.yml
default: true
extends: null
MD002:
  level: 1

MD999:
  foobar: true
const custeomRule =  {
    names: ['MD999', '...'],

    description: '...',

    tags: ['...'],

    asynchronous: true,

    function: function MD999(params, onError) {
        // params.config maybe { level: 1 }
        console.log(params.config.foobar); // undefined
        // ...
    }
}

 markdownlint({
    config,
    customRules: customRule
}, (error, results) => {});

Originally created by @chriswong on GitHub (Mar 20, 2022). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/510 ## [Source Code](https://github.com/DavidAnson/markdownlint/blob/main/lib/markdownlint.js#L505-L600): [markdownlint.js#L505](https://github.com/DavidAnson/markdownlint/blob/main/lib/markdownlint.js#L505) ```js params.config = effectiveConfig[ruleName]; ``` [markdownlint.js#L600](https://github.com/DavidAnson/markdownlint/blob/main/lib/markdownlint.js#L600) ```js const invokeRuleFunction = () => rule.function(params, onError); ``` ## Reproduction ```yml # markdownlint.yml default: true extends: null MD002: level: 1 MD999: foobar: true ``` ```js const custeomRule = { names: ['MD999', '...'], description: '...', tags: ['...'], asynchronous: true, function: function MD999(params, onError) { // params.config maybe { level: 1 } console.log(params.config.foobar); // undefined // ... } } markdownlint({ config, customRules: customRule }, (error, results) => {}); ```
kerem 2026-03-07 20:06:07 +03:00
Author
Owner

@chriswong commented on GitHub (Mar 20, 2022):

Fixed Code

markdownlint.js#L505

    const config = effectiveConfig[ruleName];

markdownlint.js#L600

        const invokeRuleFunction = () => rule.function({ ...params, config }, onError);
<!-- gh-comment-id:1073192131 --> @chriswong commented on GitHub (Mar 20, 2022): ## Fixed Code markdownlint.js#L505 ```js const config = effectiveConfig[ruleName]; ``` markdownlint.js#L600 ```js const invokeRuleFunction = () => rule.function({ ...params, config }, onError); ```
Author
Owner

@DavidAnson commented on GitHub (Mar 20, 2022):

This is a good find, thank you! I started freezing the params object to prevent issues like this, but did not catch this scenario: github.com/DavidAnson/markdownlint@5f0040679d.

I'm curious why I never saw this during development - and whether that means it will be hard to test for.

<!-- gh-comment-id:1073290585 --> @DavidAnson commented on GitHub (Mar 20, 2022): This is a good find, thank you! I started freezing the `params` object to prevent issues like this, but did not catch this scenario: https://github.com/DavidAnson/markdownlint/commit/5f0040679d2f18afa977b64f16b0a50302eede48. I'm curious why I never saw this during development - and whether that means it will be hard to test for.
Author
Owner

@DavidAnson commented on GitHub (Mar 20, 2022):

(The synchronous part of custom rules is deliberately (supposed to be) deterministic, so I'm surprised by this.)

<!-- gh-comment-id:1073291292 --> @DavidAnson commented on GitHub (Mar 20, 2022): (The synchronous part of custom rules is deliberately (supposed to be) deterministic, so I'm surprised by this.)
Author
Owner

@DavidAnson commented on GitHub (Mar 20, 2022):

Nope, I see this affects even the "synchronous" path. I'm adding tests now and hope to fix this shortly. Sorry about the error, I don't see a good workaround at the moment! How urgent is this and are you using any dependent projects like CLI/CLI2, VS Code extension, etc.?

<!-- gh-comment-id:1073317787 --> @DavidAnson commented on GitHub (Mar 20, 2022): Nope, I see this affects even the "synchronous" path. I'm adding tests now and hope to fix this shortly. Sorry about the error, I don't see a good workaround at the moment! How urgent is this and are you using any dependent projects like CLI/CLI2, VS Code extension, etc.?
Author
Owner

@DavidAnson commented on GitHub (Mar 21, 2022):

I thought of a workaround: Also create a synchronous rule that does nothing and pass the parameter to it and then share that parameter value across the two rules either in the same file or via a shared import.

<!-- gh-comment-id:1073527881 --> @DavidAnson commented on GitHub (Mar 21, 2022): I thought of a workaround: Also create a synchronous rule that does nothing and pass the parameter to it and then share that parameter value across the two rules either in the same file or via a shared import.
Author
Owner

@chriswong commented on GitHub (Mar 29, 2022):

Nope, I see this affects even the "synchronous" path. I'm adding tests now and hope to fix this shortly. Sorry about the error, I don't see a good workaround at the moment! How urgent is this and are you using any dependent projects like CLI/CLI2, VS Code extension, etc.?

Yes, i'm working on my vscode extension, for linting html/style/script code in markdown:

image

So, we'd like to know when the next version could be published?

<!-- gh-comment-id:1081369634 --> @chriswong commented on GitHub (Mar 29, 2022): > Nope, I see this affects even the "synchronous" path. I'm adding tests now and hope to fix this shortly. Sorry about the error, I don't see a good workaround at the moment! How urgent is this and are you using any dependent projects like CLI/CLI2, VS Code extension, etc.? Yes, i'm working on my vscode extension, for linting html/style/script code in markdown: <img width="653" alt="image" src="https://user-images.githubusercontent.com/165639/159703465-b74e3ad8-bbc2-4997-8f86-bb03e09a5324.png"> So, we'd like to know when the next version could be published?
Author
Owner

@DavidAnson commented on GitHub (Mar 29, 2022):

Are you consuming the library directly or are you integrating with https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint

<!-- gh-comment-id:1081371984 --> @DavidAnson commented on GitHub (Mar 29, 2022): Are you consuming the library directly or are you integrating with https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint
Author
Owner

@chriswong commented on GitHub (Mar 29, 2022):

We're consuming the library directly.

<!-- gh-comment-id:1081375251 --> @chriswong commented on GitHub (Mar 29, 2022): We're consuming the library directly.
Author
Owner

@DavidAnson commented on GitHub (Mar 29, 2022):

Good, the library comes out first. Did you try the workaround I mention above? It should unblock you for now.

<!-- gh-comment-id:1081377923 --> @DavidAnson commented on GitHub (Mar 29, 2022): Good, the library comes out first. Did you try the workaround I mention above? It should unblock you for now.
Author
Owner

@chriswong commented on GitHub (Mar 29, 2022):

I thought of a workaround: Also create a synchronous rule that does nothing and pass the parameter to it and then share that parameter value across the two rules either in the same file or via a shared import.

Yes, it works.

<!-- gh-comment-id:1081767409 --> @chriswong commented on GitHub (Mar 29, 2022): > I thought of a workaround: Also create a synchronous rule that does nothing and pass the parameter to it and then share that parameter value across the two rules either in the same file or via a shared import. Yes, it works.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/markdownlint#2265
No description provided.