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

Create a more flexible HTML comment parser and raise warning #516

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

yluobb
Copy link

@yluobb yluobb commented Dec 8, 2024

Towards: #501

This PR builds on top of the work from here. Create a more flexible HTML comment parser so we don't rely on spaces to exist to succesfully parse HTML comments. Also, raise warnings when there are missing spaces.

@yluobb yluobb requested a review from a team as a code owner December 8, 2024 08:58
Copy link

linux-foundation-easycla bot commented Dec 8, 2024

CLA Signed


The committers listed above are authorized under a signed CLA.

let (input, result) = take_until("-->")(input)?;

// Check for spacing issues and warn if found
if result.starts_with("semconv") && !input.trim().starts_with("semconv ") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three things:

  1. I don't think we need to force spaces here.

  2. For the purpose of separation of concerns, the validation logic should go in parse_semconv_snippet_directive. Ideally this function JUST parses HTML headers, which have no restrictions on whitespaces.

  3. We're not using eprintln! for warnings, instead you'll want to find a way to return a Diagnostic, e.g. using weaver's result WResult. This might require some wiring to make sure non-fatal-errors (NFE) can make it out of the parser. I haven't tried to sort out NFE w/ the nom parsers bits yet. Let me know if you have issues I'll see if I can put a scaffold up for you there.

@jsuereth
Copy link
Contributor

A quick thought on warnings here:

  1. You can update the update_markdown_contents function to use weaver result.
  2. You can update the logic to something like:
  if parser::is_markdown_snippet_directive(line) {
    ... existing ...
  } else if parser::is_possible_markdown_snippet_directive(line) {
     ... issue warnings ...
 }

Where is_possible_markdown_snippet_directive is a function you can write re-using the HTML comment parser with some kind of very flexible mispelling finding parser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants