HTMLHint icon indicating copy to clipboard operation
HTMLHint copied to clipboard

Adding the location of the parsed file in the start-event

Open commodis opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe.

Introducing HTMLHint to legacy code is quite tricky. You can either disable all failing rules or ignore the file for all HTMLHint rules. It is impossible to implement a ratcheting system where I can prevent new commits from having faults while systematically ignoring the existing faults.

This is especially the case for custom rules, where very specific problems can be detected at a very late stage and require huge amounts of labor to fix.

Describe the solution you'd like

There must be some way to retrieve the currently parsed source code location. With that one can add an ignored source code location list to each of the rules and ignore the specific pages.

Currently the start-event looks like this:

{
  pos: 0,
  line: 1,
  col: 1,
  type: 'start'
}

Adding the source code location would allow that implementation:

{
  pos: 0,
  line: 1,
  col: 1,
  type: 'start',
  url: '/home/text.html'
}

Describe alternatives you've considered

I tried checking every event if they contain such information but nothing was found. I am unaware of any Node.js specific function or object to retrieve that information, which file HTMLHint is currently working on.

commodis avatar Apr 25 '23 10:04 commodis

I just read through the source code and noticed a potential path:

  1. https://github.com/htmlhint/HTMLHint/blob/a5816446571c2e6d2e3ccc231700a76938304f04/src/cli/htmlhint.ts#L462 is where the filepath is parsed and passed to verification system.
  2. https://github.com/htmlhint/HTMLHint/blob/a5816446571c2e6d2e3ccc231700a76938304f04/src/core/htmlparser.ts#L81 adding this to the event

Is that a feasible solution? I do not see any problems with that. I could submit a PR if it is wished.

commodis avatar Jan 16 '25 17:01 commodis