retextjs / retext-syntax-mentions

plugin to classify @mentions as syntax, not natural language
https://unifiedjs.com
MIT License
10 stars 2 forks source link

Feature Request: debug option so i can check for false positives #9

Closed muescha closed 4 years ago

muescha commented 4 years ago

Subject of the feature

allow an option debug or similar, which prints a warning with the replaced positions. then i can check for false positives

Problem

sometimes the mentions are not twitter handles and should be more a code block

for example

you can use the @reac/router component

Expected behavior

i see a warning about the replaced snippets

Alternatives

wooorm commented 4 years ago

I’m sorry, I don’t understand the question? 🤔

muescha commented 4 years ago

for each replacement it makes here:

https://github.com/retextjs/retext-syntax-mentions/blob/66dc99aa0af3876429d69b6c181a0b0c8b26525e/index.js#L61-L68

Example:

.use(require("retext-syntax-mentions"), { warning: true})

for this text:

this is text which uses @react/router in the text.

an reporter can print this warning:

line 1:24-37
warning:  `@react/router` is identified as a mention
wooorm commented 4 years ago

I don’t think it’s wise to add debugging steps for the intended behavior of the 300+ packages in the unified ecosystem. It’ll take months, increase bundle size a lot, and impact performance negatively.

I suggest instead, to either:

  1. Add console.log statement to files in node_modules yourself: this is a very versatile way to debug packages
  2. A more generic solution, such as:
    
    .use(() => (tree, file) { file.data.treeBefore = JSON.parse(JSON.stringify(tree)) })
    .use(intendedPlugin)
    .use(() => (tree) { console.log(someJsonDiffPackage(file.data.treeBefore, tree)) })
muescha commented 4 years ago

yes - a general debug plugin would be the best solution.

muescha commented 4 years ago

just to see the json diff is also not hat easy, i would like to see the x-lines before and after.

muescha commented 4 years ago

maybe the debug-tool creates a vMessage for a position which is changed, and any reporter can later print the info...

muescha commented 4 years ago

is there some handy tree (+ node) compare util?

muescha commented 4 years ago

why there is this JSON.parse(JSON.stringify(tree)) - what info strip it down - or is it "just" a deep copy? yes deep copy

ChristianMurphy commented 4 years ago

is there some handy tree (+ node) compare util?

https://github.com/syntax-tree/unist-diff

wooorm commented 4 years ago

Hmm, unist-diff is WIP though, was never finished. So I’d suggest JSON diffing, or use unist-util-inspect and diff the text.

muescha commented 4 years ago

but in both cases i don't get a position?

muescha commented 4 years ago

unist-diff is WIP though, was never finished

at which place i can expect problems bc of unfinished

wooorm commented 4 years ago

but in both cases i don't get a position?

I don’t understand?

at which place i can expect problems bc of unfinished

It doesn’t work.

muescha commented 4 years ago

@wooorm it works well for my use case

what would be the best name for a debug plugin?

unist-tool-debug or unist-tool-trace or retext-tool-debug (i think vfile- wont fit)

wooorm commented 4 years ago

I’m going to close this because there is no change needed in this project.

what would be the best name for a debug plugin?

If your project deals with unist, the strongly suggested prefix is unist-util-, e.g., unist-util-trace-diff. If a project deals with remark, the suggested prefix is remark-, e.g., remark-trace-diff If a project deals with unified, the suggested prefix is unified-, e.g., unified-trace-diff

Thanks for working on this!

muescha commented 4 years ago

I’m going to close this because there is no change needed in this project.

👍

naming

it is mostly comparing the before tree and after tree saved in vfile and can used with unify as a .use plugin

muescha commented 4 years ago

i think the name to go is: unist-util-trace-diff since it shows diffs of unist nodes