@cffnpwr/textlint-rule-no-single-child-heading 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 cffnpwr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,170 @@
1
- # Temporary Holding Version
1
+ # @cffnpwr/textlint-rule-no-single-child-heading
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![GitHub License](https://img.shields.io/github/license/cffnpwr/textlint-rule-preset-ja-writing-extras?style=flat)](./LICENSE)
4
+ [![npm Version](https://img.shields.io/npm/v/%40cffnpwr%2Ftextlint-rule-no-single-child-heading?style=flat)](https://www.npmjs.com/package/@cffnpwr/textlint-rule-no-single-child-heading)
5
+ [![JSR Version](https://jsr.io/badges/@cffnpwr/textlint-rule-no-single-child-heading)](https://jsr.io/@cffnpwr/textlint-rule-no-single-child-heading)
6
+
7
+ A textlint rule that detects a heading level that contains only one subheading.
8
+
9
+ [日本語のREADMEはこちら](./README-ja.md)
10
+
11
+ When a heading has only one subheading, that subheading does not divide the content.
12
+ This rule encourages writing the content as the body of the parent heading without adding the
13
+ subheading.
14
+
15
+ ```markdown
16
+ <!-- NG -->
17
+ # レート制限
18
+
19
+ ## 設計
20
+
21
+ 本文
22
+
23
+ ## 検討した代替案
24
+
25
+ ### スライディングウィンドウ方式
26
+
27
+ 本文
28
+
29
+ <!-- OK -->
30
+ # レート制限
31
+
32
+ ## 設計
33
+
34
+ 本文
35
+
36
+ ## 検討した代替案
37
+
38
+ ### スライディングウィンドウ方式
39
+
40
+ 本文
41
+
42
+ ### 固定ウィンドウ方式
43
+
44
+ 本文
45
+ ```
46
+
47
+ In the NG example, 「検討した代替案」 has only one subheading, 「スライディングウィンドウ方式」, so
48
+ `### スライディングウィンドウ方式` is reported. A heading with no subheadings is not reported
49
+ either.
50
+
51
+ The subheadings of a heading are determined as follows.
52
+
53
+ 1. The scope is from just after the heading to the next heading of the same or a shallower level
54
+ 2. Among the headings in the scope, those of the shallowest level are the subheadings
55
+
56
+ A heading that skips levels is also treated as a subheading. When the scope of an H2 contains only
57
+ a single H4, that H4 is reported.
58
+
59
+ When a heading has exactly one subheading, the whole subheading is reported. At most one error is
60
+ reported per parent heading.
61
+
62
+ The top level of the document (the scope that is not under any heading) is not checked. Therefore,
63
+ a document with a single H1 is not reported. When an H1 has only one subheading (H2), it is
64
+ reported.
65
+
66
+ Setext headings (headings written with an underline) are also counted in the hierarchy.
67
+
68
+ ## How to Install
69
+
70
+ ### npm
71
+
72
+ ```sh
73
+ npm install --save-dev @cffnpwr/textlint-rule-no-single-child-heading
74
+ ```
75
+
76
+ or
77
+
78
+ ```sh
79
+ npx jsr add -D @cffnpwr/textlint-rule-no-single-child-heading
80
+ ```
81
+
82
+ ### yarn
83
+
84
+ ```sh
85
+ yarn add --dev @cffnpwr/textlint-rule-no-single-child-heading
86
+ ```
87
+
88
+ or
89
+
90
+ ```sh
91
+ yarn dlx jsr add -D @cffnpwr/textlint-rule-no-single-child-heading
92
+ ```
93
+
94
+ ### pnpm
95
+
96
+ ```sh
97
+ pnpm add --save-dev @cffnpwr/textlint-rule-no-single-child-heading
98
+ ```
99
+
100
+ or
101
+
102
+ ```sh
103
+ pnpm dlx jsr add -D @cffnpwr/textlint-rule-no-single-child-heading
104
+ ```
105
+
106
+ ### Bun
107
+
108
+ ```sh
109
+ bun add --dev @cffnpwr/textlint-rule-no-single-child-heading
110
+ ```
111
+
112
+ or
113
+
114
+ ```sh
115
+ bunx jsr add -D @cffnpwr/textlint-rule-no-single-child-heading
116
+ ```
117
+
118
+ ### Deno
119
+
120
+ ```sh
121
+ deno add --dev npm:@cffnpwr/textlint-rule-no-single-child-heading
122
+ ```
123
+
124
+ or
125
+
126
+ ```sh
127
+ deno add --dev jsr:@cffnpwr/textlint-rule-no-single-child-heading
128
+ ```
129
+
130
+ ## How to Use
131
+
132
+ Add it to `.textlintrc.json`.
133
+
134
+ ```json
135
+ {
136
+ "rules": {
137
+ "@cffnpwr/textlint-rule-no-single-child-heading": true
138
+ }
139
+ }
140
+ ```
141
+
142
+ ## Options
143
+
144
+ ```ts
145
+ interface Options {
146
+ checkTopLevelHeading?: boolean;
147
+ skipBlockQuote?: boolean;
148
+ }
149
+ ```
150
+
151
+ | Option | Default | Description |
152
+ | --- | --- | --- |
153
+ | `checkTopLevelHeading` | `true` | Checks the number of subheadings of the headings of the shallowest level in the document. With `false`, the headings directly under the headings of the shallowest level in the document (H1 in a document that starts with H1) are not checked |
154
+ | `skipBlockQuote` | `true` | Excludes headings under quotes (BlockQuote) from the hierarchy |
155
+
156
+ Specifying an unknown option key or an invalid value results in an error.
157
+
158
+ ```json
159
+ {
160
+ "rules": {
161
+ "@cffnpwr/textlint-rule-no-single-child-heading": {
162
+ "checkTopLevelHeading": false
163
+ }
164
+ }
165
+ }
166
+ ```
167
+
168
+ ## License
169
+
170
+ [MIT](./LICENSE)
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ let e=require("@cffnpwr/textlint-rule-preset-ja-writing-extras-shared");const t=(0,require("arktype").type)({"+":`reject`,"checkTopLevelHeading?":`boolean`,"skipBlockQuote?":`boolean`,"severity?":`unknown`}),n=(e,t)=>{let n=e[t];if(n===void 0)return[];let r=e.slice(t+1),i=r.findIndex(e=>e.depth<=n.depth),a=i===-1?r:r.slice(0,i),o=Math.min(...a.map(e=>e.depth));return a.filter(e=>e.depth===o)},r=(r,i={})=>{(0,e.validateOptions)(t,i);let{Syntax:a,RuleError:o,report:s,locator:c}=r,l=i.checkTopLevelHeading??!0,u=i.skipBlockQuote??!0,d=(0,e.createBlockQuoteDepth)(),f=[],p=e=>{u&&d.isInside()||f.push(e)},m=()=>{let e=Math.min(...f.map(e=>e.depth));f.forEach((t,r)=>{if(!l&&t.depth===e)return;let[i,...a]=n(f,r);i===void 0||a.length>0||s(i,new o(`${t.loc.start.line}行目の見出しの下位の見出しが、この見出しの1つだけです。下位の見出しを立てずに、上位の見出しの本文として書いてください。`,{padding:c.range([0,i.range[1]-i.range[0]])}))})};return{[a.BlockQuote]:d.enter,[a.BlockQuoteExit]:d.exit,[a.Header]:p,[a.DocumentExit]:m}};module.exports=r;