You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ESLint如何为VSCode折叠区域注释添加spaced-comment规则例外

Fix ESLint spaced-comment Rule for VSCode Region Comments

I’ve run into this exact clash between VSCode’s folding comments and ESLint’s spaced-comment rule before. The issue with your current configuration is that using plain string values in line.exceptions doesn’t reliably work for multi-character patterns (especially in older ESLint versions), where the rule expects either single-character exceptions or regex patterns to target comment prefixes.

Here’s the corrected configuration that will let ESLint skip the space requirement for your VSCode folding region comments:

"spaced-comment": [
  "error",
  "always",
  {
    "line": {
      "exceptions": [/^#region/, /^#endregion/, /^region/, /^endregion/]
    }
  }
]

Why this works:

  • The always setting preserves the default rule behavior (requiring a space after // for all regular comments).
  • The regex patterns in line.exceptions match the start of the content immediately following //:
    • For //#region My region, the content after // is #region My region — the regex /^#region/ matches this opening, so ESLint skips the space check.
    • /^region/ handles un-prefixed variants like //region My region the same way.

After updating your config, comments like //#region My region or //endregion My region won’t trigger the Expected exception block, space or tab after '//' in comment error anymore, while the rule still enforces proper spacing for all other line comments.

内容的提问来源于stack exchange,提问作者namgold

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 08:42:35