Skip to content

feat: Add ignorePattern to no-v-html #2857

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

Merged
merged 12 commits into from
Aug 1, 2025

Conversation

lucaswerkmeister
Copy link
Contributor

This allows configuring the rule such that certain variables are allowed in v-html=. For instance, we would like to allowlist variables named “*Html” (as in the test), where the name already marks them as containing safe HTML that’s expected to be used with v-html=.


I tried to follow existing code style in here, but still, this is my first time contributing to any eslint plugin (I think), so let me know if anything needs to be changed or improved :) the option name mimics e.g. no-unused-vars but could of course be changed. (Also, I’m not completely sure if it’s correct that the option value seems to require slashes around it in order to not be interpreted as a literal string.)

Copy link

changeset-bot bot commented Jul 29, 2025

🦋 Changeset detected

Latest commit: 18fc869

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-vue Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This allows configuring the rule such that certain variables are allowed
in v-html=. For instance, we would like to allowlist variables named
“*Html” (as in the test), where the name already marks them as
containing safe HTML that’s expected to be used with v-html=.
@lucaswerkmeister lucaswerkmeister force-pushed the no-v-html-ignorePattern branch from 522c93a to c98c01e Compare July 29, 2025 15:26
@lucaswerkmeister
Copy link
Contributor Author

(Also, I’m not completely sure if it’s correct that the option value seems to require slashes around it in order to not be interpreted as a literal string.)

Huh, apparently vue/no-unused-vars just uses new RegExp(ignorePattern, 'u') rather than the toRegExp helper. (I found the toRegExp helper in some other rule, don’t remember which one.)

wmfgerrit pushed a commit to wikimedia/mediawiki-extensions that referenced this pull request Jul 29, 2025
* Update Wikibase from branch 'master'
  to 47afac06a696e77eac205da4c5df7ce3fdd07e87
  - Disable vue/no-v-html rule in wbui2025 directory
    
    The v-html directive is part of our expected workflow for reusing
    server-rendered HTML (property links, snak values; see the upcoming ADR
    of T399832). As such, this eslint rule is not currently useful for us.
    If eslint adds the ignorePattern (or similar) option suggested in [1],
    then we may later use it again (but note that this will require us to
    upgrade to the latest version of eslint-plugin-vue first).
    
    [1]: vuejs/eslint-plugin-vue#2857
    
    Change-Id: I8926d09a67927dc36b0bd5cfdb3e5c6a7256842e
wmfgerrit pushed a commit to wikimedia/mediawiki-extensions-Wikibase that referenced this pull request Jul 29, 2025
The v-html directive is part of our expected workflow for reusing
server-rendered HTML (property links, snak values; see the upcoming ADR
of T399832). As such, this eslint rule is not currently useful for us.
If eslint adds the ignorePattern (or similar) option suggested in [1],
then we may later use it again (but note that this will require us to
upgrade to the latest version of eslint-plugin-vue first).

[1]: vuejs/eslint-plugin-vue#2857

Change-Id: I8926d09a67927dc36b0bd5cfdb3e5c6a7256842e
Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! I have some suggestions / requested changes.

@lucaswerkmeister
Copy link
Contributor Author

lucaswerkmeister commented Jul 30, 2025

(I’ve been adding commits under the assumption that you’ll squash them on merge and throw away the intermediate commit messages – let me know if you’d like the Git history cleaned up into a version that would be suitable for a merge commit ^^)

@FloEdelmann FloEdelmann requested a review from Copilot July 31, 2025 15:08
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds an ignorePattern configuration option to the no-v-html ESLint rule, allowing developers to allowlist variables with names matching a specific pattern for use with the v-html directive. This enables safer use of v-html when variables are intentionally named to indicate they contain safe HTML content.

  • Adds ignorePattern option to rule schema that accepts a regex pattern string
  • Implements logic to skip reporting violations when variable names match the configured pattern
  • Updates documentation with configuration examples and usage guidelines

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/rules/no-v-html.js Implements the ignorePattern option with regex matching logic
tests/lib/rules/no-v-html.js Adds test cases for valid and invalid usage with ignorePattern option
docs/rules/no-v-html.md Documents the new ignorePattern option with configuration examples
docs/rules/no-v-text.md Adds related rules section for cross-referencing
docs/rules/no-v-text-v-html-on-component.md Adds related rules section for cross-referencing
.changeset/purple-lights-invite.md Documents the feature addition for changelog

Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

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

Thank you for patiently implementing my feedback! 🙂
Looks good to me now 🙂

@FloEdelmann FloEdelmann requested review from ota-meshi and waynzh July 31, 2025 15:10
Copy link
Member

@waynzh waynzh left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks you!

@waynzh waynzh merged commit a198b52 into vuejs:master Aug 1, 2025
4 checks passed
@github-actions github-actions bot mentioned this pull request Aug 1, 2025
@lucaswerkmeister lucaswerkmeister deleted the no-v-html-ignorePattern branch August 1, 2025 09:59
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.

3 participants