Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: (Exception occurs in markdown/no-missing-label-refs when links from the second onwards have undefined labels) #289

Open
1 task
Ymmy833y opened this issue Oct 10, 2024 · 0 comments
Labels
bug repro:needed This issue should include a reproducible example

Comments

@Ymmy833y
Copy link

Environment

ESLint version: 9.12.0
@eslint/markdown version: 9.12.0
Node version: 20.9.0
npm version: 10.8.3
Operating System: Windows 11

Which language are you using?

commonmark

What did you do?

Configuration
import markdown from "@eslint/markdown";

export default [
    {
        files: ["**/*.md"],
        plugins: {
            markdown
        },
        language: "markdown/commonmark",
        rules: {
            "markdown/no-missing-label-refs": "error",
        },
    }
];
  1. Create a Markdown file with the following content:
    [Foo][foo]
    [Bar][]
  2. Enable the @eslint/markdown plugin and the markdown/no-missing-label-refs rule in your ESLint configuration.
  3. Run ESLint on the Markdown file.

What did you expect to happen?

  1:7  error  Label reference 'foo' not found  markdown/no-missing-label-refs
  2:2  error  Label reference 'Bar' not found  markdown/no-missing-label-refs

What actually happened?

ESLint throws the following exception and stops execution:

Oops! Something went wrong! :(

ESLint: 9.12.0

TypeError: Cannot read properties of undefined (reading 'length')
Occurred while linting ...\eslint-markdown-sample\docs\sample.md:1
Rule: "markdown/no-missing-label-refs"
    at findMissingReferences (.../eslint-markdown-sample/node_modules/@eslint/markdown/dist/esm/index.js:1509:25)
    at text (.../eslint-markdown-sample/node_modules/@eslint/markdown/dist/esm/index.js:1580:9)
    at ruleErrorHandler (...\eslint-markdown-sample\node_modules\eslint\lib\linter\linter.js:1084:48)
    at ...\eslint-markdown-sample\node_modules\eslint\lib\linter\safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (...\eslint-markdown-sample\node_modules\eslint\lib\linter\safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (...\eslint-markdown-sample\node_modules\eslint\lib\linter\node-event-generator.js:297:26)     
    at NodeEventGenerator.applySelectors (...\eslint-markdown-sample\node_modules\eslint\lib\linter\node-event-generator.js:326:22)    
    at NodeEventGenerator.enterNode (...\eslint-markdown-sample\node_modules\eslint\lib\linter\node-event-generator.js:337:14)
    at runRules (...\eslint-markdown-sample\node_modules\eslint\lib\linter\linter.js:1128:40)

Link to Minimal Reproducible Example

https://stackblitz.com/edit/stackblitz-starters-bhmkmm?file=package.json

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

Failing Test Case

The following test case results in the exception being thrown:

// tests/rules/no-missing-label-refs.test.js

invalid: [
    {
        code: "[Foo][foo]\n[Bar][]",
        errors: [
            {
                messageId: "notFound",
                data: { label: "foo" },
                line: 1,
                column: 6,
                endLine: 1,
                endColumn: 9,
            },
            {
                messageId: "notFound",
                data: { label: "Bar" },
                line: 2,
                column: 2,
                endLine: 2,
                endColumn: 5,
            },
        ],
    },
],

Other Cases Where the Error Occurs

  1. Case 1
    [Foo][]
    [Bar][]
  2. Case 2
    [Foo][foo]
    [Bar][bar]
    [Hoge][]
  3. Case 3
    [Foo][foo]
    [Bar][]
    [Hoge][hoge]

Cases Where No Error Occurs

  1. Case 1
    [Foo][]
    [Bar][bar]
  2. Case 2
    [Foo][foo]
    [Bar][bar]
  3. Case 3
    [Foo][]
    [Bar][bar]
    [Hoge][hoge]
@Ymmy833y Ymmy833y added bug repro:needed This issue should include a reproducible example labels Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug repro:needed This issue should include a reproducible example
Projects
Status: Needs Triage
Development

No branches or pull requests

1 participant