Agent skill
prh-hyphen-regex-escape
Use when adding hyphenated terms to prh spelling dictionaries on Node.js 20+. Unicode regex flag incompatibility.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/prh-hyphen-regex-escape
Metadata
Additional technical details for this skill
- author
- shimo4228
- version
- 1.0
- extracted
- 2026-02-12
SKILL.md
prh ハイフン含むパターンの正規表現エラー
Extracted: 2026-02-12 Context: textlint-rule-prh を Node.js 20+ 環境で使用し、ハイフン含む用語を表記ゆれ辞書に登録する場合
Problem
prh.yml にハイフンを含むパターン(例: Claude-first, cli-first, pdf-to-anki)を記載すると、textlint 実行時に以下のエラーが発生する:
SyntaxError: Invalid regular expression: /Claude\-first/gmu: Invalid escape
根本原因:
- prh は文字列パターンを内部的に正規表現に変換する際、ハイフン
-を\-にエスケープする - prh は正規表現に
gmuフラグを自動付加する - Node.js 20+ の unicode フラグ (
u) では、キャラクタークラス ([...]) 外の\-は無効なエスケープシーケンスとして扱われる - 結果、
SyntaxErrorが発生する
追加の罠: specs 検証エラー
ハイフン問題を regex リテラル (/pattern/) で回避しても、specs の from にハイフン含む文字列を書くと別のエラーが発生する:
Error: spec failed. "claude-native", expected "Claude-Native", but got "claude-native"
パターンがハイフン部分にマッチしないため、置換が行われず検証が失敗する。
Solution
ハイフンを含むパターンは prh に登録しない。 ハイフンなしのバリエーションのみを対象にする。
# BAD: ハイフン含むパターン → SyntaxError
- expected: Claude-Native
patterns:
- Claude-first # ← \- エスケープでクラッシュ
- cli-first # ← 同上
# GOOD: ハイフンなしのバリエーションのみ
- expected: Claude-Native
patterns:
- Claude based
- claude native
- expected: CLI-First
patterns:
- CLI first
理由: Claude-first → Claude-Native のようなハイフン付き誤表記の検出は、prh では技術的に困難。editor エージェントや手動レビューで補完する。
When to Use
textlint-rule-prhの辞書(prh.yml)を作成・編集するとき- 特にハイフン含む正式表記(
Claude-Native,CLI-First等)の表記ゆれを登録しようとするとき - Node.js 20+ 環境(unicode regex が厳密化された環境)
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?