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

False positive in no-unused-definitons rule when using mkdocs admonitions #307

Closed
4 tasks done
samjcombs opened this issue Feb 5, 2023 · 6 comments
Closed
4 tasks done
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on

Comments

@samjcombs
Copy link

Initial checklist

Affected packages and versions

no-unused-definitions

Link to runnable example

No response

Steps to reproduce

When using mkdoc admonitions, given this input:

1    !!! note
2    
3       Here is a note with a [reference].
4    
5    [reference]: http://is-properly-defined/

an warning is reported on L5

Expected behavior

No warning should be reported

Actual behavior

A warning is reported, possibly due to ast being wierd inside the note admonition block?

Runtime

No response

Package manager

No response

OS

No response

Build and bundle tools

No response

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Feb 5, 2023
@ChristianMurphy
Copy link
Member

Welcome @samjcombs!
Sorry you ran into a spot of trouble.
Could you share a minimal reproducible example of what you are seeing? (https://stackoverflow.com/help/minimal-reproducible-example)

I tried to re-create the issue in CodeSandbox using remark and remark-lint-no-unused-definitions programmatically, and displaying any error messages, and don't see an error being reported.
runnable example: https://codesandbox.io/s/lively-morning-qcis7e?file=/src/index.js

source from sandbox
// ⚠️ Important! Please make sure the dependencies are up to date.
// On code sandbox, you can refresh them in the Dependencies section (left-bottom)
// On stackblitz, you can open the package.json file, update the versions,
// then run npm install in the stackblitz terminal

import { remark } from "remark";
import noUnusedDefinitions from "remark-lint-no-unused-definitions";

const sourceMarkdown = `
!!! note

   Here is a note with a [reference].

[reference]: http://is-properly-defined/
`;

async function main() {
  document.querySelector("#source").textContent = sourceMarkdown;

  const file = await remark()
    .use(noUnusedDefinitions)
    // .use remark plugins here
    .process(sourceMarkdown);

  document.querySelector("#result").textContent = String(file);
  document.querySelector("#error").textContent = JSON.stringify(
    file.messages,
    null,
    4
  );
}

main().catch((error) => {
  document.querySelector("#error").textContent = error;
});

Without more detail I'm can only offer some general suggestions:

  1. make sure you are using the latest versions of remark and remark-lint-no-unused-definitions this may be a bug that was already fixed, or caused by mixing incompatible versions.
  2. if the line numbering shown above is part of the content, remove it, markdown definitions cannot have leading content on the same line
  3. it could be related to adminitions but in a way not shown in your example. If so you may need an admonition parser, there is one for remark https://github.com/elviswolcott/remark-admonitions but it is behind on versions and is not yet compatible with latest (see remark@next (13) elviswolcott/remark-admonitions#27 and Is this working with unified v10? elviswolcott/remark-admonitions#49, the repo could use some help if you want to look into supporting latest remark)

@ChristianMurphy ChristianMurphy added the 🙊 open/needs-repro This needs a reproduction label Feb 5, 2023
@github-actions

This comment has been minimized.

@samjcombs
Copy link
Author

thanks for the reply. In response to your questions:

  1. Yes Im using the latest versions
  2. Line numbering was added just for that example to illustrate where the error is being reported
  3. Yes likely a gap when using admonitions.. for now ill just ignore these but yeah good idea to look into supporting that library.

ill try to recreate this error state in a codesandbox for reference.

@ChristianMurphy
Copy link
Member

Thanks for the confirmation.
That isn't something which can't necessarily be fixed here.

remark-lint works off of what is parsed.

remark itself parses commonmark.
And plugins layer features on top of that, like the remark-gfm or remark-admonitions parser extensions.

If the markdown flavor you tell remark to parse is different from the flavor the content actually is, the linter won't be able to make sense of the content.

Happy to answer further questions in the discussion forum https://github.com/orgs/remarkjs/discussions
And if you can replicate the issue in plain and valid commonmark, feel free to add details.

In the meantime closing this out as something which requires admonition fixes rather than linter changes.

@ChristianMurphy ChristianMurphy closed this as not planned Won't fix, can't repro, duplicate, stale Feb 6, 2023
@ChristianMurphy ChristianMurphy added 👀 no/external This makes more sense somewhere else and removed 🙊 open/needs-repro This needs a reproduction labels Feb 6, 2023
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Feb 6, 2023
@github-actions

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants