ESLint如何为VSCode折叠区域注释添加spaced-comment规则例外
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
alwayssetting preserves the default rule behavior (requiring a space after//for all regular comments). - The regex patterns in
line.exceptionsmatch 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 regionthe same way.
- For
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

