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

Ignoring multiple error messages #11

Closed
pepelsbey opened this issue Sep 14, 2023 · 6 comments
Closed

Ignoring multiple error messages #11

pepelsbey opened this issue Sep 14, 2023 · 6 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@pepelsbey
Copy link

pepelsbey commented Sep 14, 2023

Hello! I’m glad I found your validator: it’s simple enough for my needs compared to the original vnu one. One of the reasons to start looking for another tool was the vnu’s problems with filtering out error messages. It’s just unreliable: some work fine, some just don’t. But in your case, it seems to be working exceptionally well :)

Unfortunately, I need to filter out multiple error messages, and it’s unclear from the readme how to achieve that or if it’s even possible. I tried using multiple --ignore keys or combining strings into a single one, no luck so far.

The best solution would be to support a simple config file with exceptions, like vnu does:

--filterfile FILENAME

Specifies a filename. Each line of the file contains either a regular
expression or starts with “#” to indicate the line is a comment. Any error
message or warning message that matches a regular expression in the file is
filtered out (dropped/suppressed).

I hope you can clarify this in the readme or consider supporting an ignore file. Thank you!

@dpilafian dpilafian added the enhancement New feature or request label Sep 15, 2023
@dpilafian dpilafian added the documentation Improvements or additions to documentation label Sep 16, 2023
@dpilafian
Copy link
Member

Multiple validation messages can be skipped using a regex with "or" operators in the --exclude flag.

For example, the command:

html-validator docs '--ignore=/^Duplicate ID|^Section lacks|^Element .blockquote. not allowed/'

will ignore the following 3 types of validation messages:

  1. Duplicate ID "[name]"
  2. Section lacks heading. Consider using “h2”-“h6” elements to add identifying headings to all sections, or else use a “div” element instead for any cases where no heading is needed.
  3. Element “blockquote” not allowed as child of element “span” in this context. (Suppressing further errors from this subtree.)

Because of the spaces in the search text, be sure to wrap the entire --ignore flag plus its value in quotes.

@pepelsbey
Copy link
Author

Oh, good to know! It's definitely something worth adding to the readme. But the convenience and readability/maintainability of that kind of filtering is questionable 😅 I hope you'd consider supporting an ignore file. Thanks!

@dpilafian
Copy link
Member

The proposed solution is to supplement the current --ignore flag with a new --ignore-config flag.

See documentation at:
https://github.com/center-key/w3c-html-validator#5-ignore-configuration-file

I named the flag --ignore-config because --ignore-file seemed a bit too easy to confuse with the --exclude flag for ignoring files.

I considered a few different JSON structures because JSON is safer than a raw text file, but I just couldn't figure out a JSON structure with comments that I liked more than raw text. The fact that you can't put real comments in JSON is really annoying.

Anyway, the code is not yet released, and if you have any suggestions for improvements please let me know. Otherwise, the feature works and is ready to release.

@pepelsbey
Copy link
Author

I like the --ignore-config name :) As for the file format, I think there might be a compromise: YAML. I find the JSON’s lack of comments and strict formatting rules quite annoying to write manually. YAML is much more relaxed and could be easily converted to JSON when needed.

# Comment
- Trailing slash on void elements
# Comment
- /^Duplicate ID/
# Comment
- /^Element .blockquote. not allowed/

@dpilafian
Copy link
Member

The config file has been updated to support both strings and regex, like in the above YAML example. Regex lines now have to be wrapped in slashes, but I think this actually makes the config file easier to read. Between text, JSON, and YAML for config, none are awesome, but text for a simple list of patterns seems the cleanest.

dpilafian added a commit that referenced this issue Sep 19, 2023
@pepelsbey
Copy link
Author

Oh, nice! That was super quick. Thank you for implementing this feature, I’m already using it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants