-
Notifications
You must be signed in to change notification settings - Fork 21
feat: 見出し冒頭で連番を使うパターンの検知 #31
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このパターンの例外として、たまに
## 1. 方法A
## 2. 方法Bみたいな比較を並べる時に使いたいケースはありそうかなとは思いました。
全てのHeaderに1, 2, 3 となっている場合は機械的に目次としてつけてると思うのでエラーにして良いと思います。
特定の 1 2みたいな選択肢をセクションで表現したい場合にfalse positiveとなるのをどうするかちょっと悩ましいですね。
## A. 方法A
## B. 方法B
とすれば大体は回避できるのでそこまでは問題ないですが。
false positiveを避ける場合は、それぞれのヘッダに連番がついてるかをみてエラーにするですが、つけてないヘッダがあるとfalse negativeになるので、実際に問題が起きてから考えるでもいいのかなーとは思いました。
多分、ヘッダのレベルを連番で表現しているケースはエラーとするが一番ルールとしては正しい感じなんだとは思います(1, 1.1 みたいなケース。同じヘッダのレベルで1と2とするケースは、このルールの例外なんだとは思います)
| return { | ||
| [Syntax.Header](node) { | ||
| // Use raw text which includes the heading marker (#) | ||
| const text = node.raw || getSource(node); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Header nodeの時点でHeaderなのでrawを見る必要はないと思います。
具体的な問題として # を使わない書き方だと動かなくなる( ==== やMarkdown以外など)ので、getSourceだけで良いような気がします。
AIは ==== の方はあんまり使わない感じはするので、意図的に除外する場合は意図的な動作を実装したいですね
|
|
||
| // For raw text, we need to skip the heading marker first | ||
| // Extract just the heading content (after # and space) | ||
| const headingContentMatch = text.match(/^#{1,6}\s+(.+)$/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここはtextをtrim or \s{0,10}\d のようなスペースを許容して、先頭が数字から始まるか? な気がしています。
| report( | ||
| node, | ||
| new RuleError( | ||
| "見出しに連番を含めるパターンは機械的な印象を与える可能性があります。連番の必要性を検討してみてください。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
具体的には、見出しのレベルを見直することで、見出しを番号として含める必要がないので、見出しのレベルを1や2のようなテキストで表現しないでください ということが伝わると何をするといいかわかるかもしれないです。
HTML的にはこの辺だと思いますが、ここまで詳細にはいらないですが、
> Heading information can be used by user agents to construct a table of contents for a document automatically.
> Do not use heading elements to resize text. Instead, use the CSS font-size property.
> Do not skip heading levels: always start from <h1>, followed by <h2> and so on.
> https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/Heading_Elements
まだちょっと手つけられてないですが、エラーメッセージの明確性/正確性/修正可能性/文脈適合性を評価して、人間もAIもエラーを直しやすくできるような基準を作ろうとしています。
textlint-ja/textlint-rule-no-doubled-joshi#73
この場合、どうやって修正したらいいかがちょっと伝わりにくいかなと思いました
概要
見出しに連番を含めるパターンを検出する新しいルール
no-ai-heading-numbersを追加しました。AIが生成した文章では、見出しに
# 1. タイトルや## 2. セクションのような連番が機械的に付与されることがよくあります。この書き方自体は適切な場合もありますが、AIが生成しがちな文章ということで検知ルール追加を提案します。
変更内容
src/rules/no-ai-heading-numbers.ts- ルール実装test/rules/no-ai-heading-numbers.test.ts- テストコード(18テストケース)src/index.ts- プリセットへのルール登録README.md- ルールの説明とオプションの追加検出パターン
エラーメッセージ
テスト
allowオプションのテストBreaking Changes
特になし。機能追加のみ。