Skip to content

vue/no-v-html ignorePattern regex escaping causes different behavior in VS Code vs CLI #2949

@kzhrk

Description

@kzhrk

Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have read the FAQ and my problem is not listed.

Tell us about your environment

  • ESLint version: 9.39.1
  • eslint-plugin-vue version: 10.5.1
  • Vue version: 3.5.22
  • Node version: 24.3.0
  • Operating System: macOS

Please show your full configuration:

import js from "@eslint/js";
import ts from "typescript-eslint";
import prettierConfig from "eslint-plugin-prettier/recommended";
import globals from "globals";
import vue from "eslint-plugin-vue";
import vueA11y from "eslint-plugin-vuejs-accessibility";
import storybook from "eslint-plugin-storybook";

const ignoredFiles = [];

export default [
  { ignores: ignoredFiles },
  js.configs.recommended,
  ...ts.configs.recommendedTypeChecked,
  ...vue.configs["flat/recommended"],
  ...vueA11y.configs["flat/recommended"],
  ...storybook.configs["flat/recommended"],
  prettierConfig,
  {
    languageOptions: {
      parserOptions: {
        ecmaVersion: 2020,
        parser: ts.parser,
        sourceType: "module",
        project: ["./tsconfig.json"],
        extraFileExtensions: [".vue"],
      },
      globals: {
        ...globals.browser,
        ...globals.node,
      },
    },
  },
  {
    rules: {
      "prettier/prettier": "error",
      "no-console": "error",
      eqeqeq: "error",
      "@typescript-eslint/consistent-type-imports": "error",
      "@typescript-eslint/no-import-type-side-effects": "error",
      "@typescript-eslint/no-unused-vars": [
        "error",
        {
          argsIgnorePattern: "^_",
          varsIgnorePattern: "^_",
          caughtErrorsIgnorePattern: "^_",
        },
      ],
      "vue/no-v-html": [
        "error",
        {
          ignorePattern: "/^\$sanitize\(/",
        },
      ],
    },
  },
];

What did you do?

<template>
  <div v-html="$sanitize(contentHtml)"></div>
</template>

I configured the vue/no-v-html rule with an ignorePattern option to ignore v-html usage when the content is sanitized using $sanitize() function.

What did you expect to happen?

The ignorePattern option should work consistently both in VS Code and when running ESLint via CLI. When using the pattern /^\\$sanitize\\(/, it should properly ignore the v-html usage for expressions starting with $sanitize( without causing syntax errors.

What actually happened?

There are two different behaviors depending on how the regular expression is written:

  1. With pattern /^\$sanitize\(/:

    • VS Code shows no lint errors (works correctly in IDE)
    • CLI execution fails with syntax error: SyntaxError: Error while loading rule 'vue/no-v-html': Invalid regular expression: //^$sanitize(//u: Unterminated group
  2. With pattern /^\\$sanitize\\(/:

    • CLI execution works without errors
    • VS Code still shows lint errors for the ignored pattern (ignorePattern not working in IDE)

The ignorePattern option behaves inconsistently between VS Code extension and CLI execution, and proper escaping of the regular expression seems to cause different issues in different environments.

Repository to reproduce this issue

https://github.com/kzhrk/eslint-plugin-vue-2949

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions