@@ -11,8 +11,8 @@ import {
11
11
restoreToSurfaceFromKey ,
12
12
is括弧Token ,
13
13
} from "./token-utils" ;
14
- import { TxtNode , TxtParentNode } from "@textlint/ast-node-types" ;
15
- import { TextlintRuleModule } from "@textlint/types" ;
14
+ import type { TxtNode , TxtParentNode } from "@textlint/ast-node-types" ;
15
+ import type { TextlintRuleModule } from "@textlint/types" ;
16
16
import { StringSource } from "textlint-util-to-string" ;
17
17
18
18
/**
@@ -107,31 +107,6 @@ export interface Options {
107
107
commaCharacters ?: string [ ] ;
108
108
}
109
109
110
- /**
111
- * `obj.method` のCode Nodeのように、区切り文字として意味をもつノードがある場合に、
112
- * このルールでは単純に無視したいので、同じ文字数で意味のない文字列に置き換える
113
- * @param sentenceNode
114
- * @param maskedType
115
- */
116
- const maskNode = ( sentenceNode : TxtParentNode , maskedType : string [ ] ) : TxtParentNode => {
117
- // recursive mask
118
- return {
119
- ...sentenceNode ,
120
- children : sentenceNode . children . map ( ( node ) => {
121
- if ( maskedType . includes ( node . type ) ) {
122
- return {
123
- ...node ,
124
- type : node . type ,
125
- value : "_" . repeat ( node . value . length ) ,
126
- } ;
127
- }
128
- if ( node . children ) {
129
- return maskNode ( node as TxtParentNode , maskedType ) ;
130
- }
131
- return node ;
132
- } )
133
- }
134
- }
135
110
/*
136
111
1. Paragraph Node -> text
137
112
2. text -> sentences
@@ -159,16 +134,27 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
159
134
const isSentenceNode = ( node : TxtNode ) : node is SentenceNode => {
160
135
return node . type === SentenceSyntax . Sentence ;
161
136
} ;
162
- const txtParentNode = splitSentences ( node , {
137
+ const txtParentNode = splitSentences ( node as TxtParentNode , {
163
138
SeparatorParser : {
164
139
separatorCharacters,
165
140
} ,
166
141
} ) ;
167
142
const sentences = txtParentNode . children . filter ( isSentenceNode ) ;
168
143
const checkSentence = async ( sentence : SentenceNode ) => {
169
144
// コードの中身は無視するため、無意味な文字列に置き換える
170
- const maskedSentence = maskNode ( sentence , [ Syntax . Code ] ) ;
171
- const sentenceSource = new StringSource ( maskedSentence ) ;
145
+ // @ts -expect-error: sentence-splitterが古いので
146
+ const sentenceSource = new StringSource ( sentence , {
147
+ replacer ( { node, maskValue } ) {
148
+ /*
149
+ * `obj.method` のCode Nodeのように、区切り文字として意味をもつノードがある場合に、
150
+ * このルールでは単純に無視したいので、同じ文字数で意味のない文字列に置き換える
151
+ */
152
+ if ( node . type === Syntax . Code ) {
153
+ return maskValue ( "_" ) ;
154
+ }
155
+ return ;
156
+ }
157
+ } ) ;
172
158
const text = sentenceSource . toString ( ) ;
173
159
const tokens = await tokenize ( text ) ;
174
160
// 助詞 + 助詞は 一つの助詞として扱う
@@ -238,6 +224,7 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
238
224
// padding positionを計算する
239
225
const originalIndex = sentenceSource . originalIndexFromIndex ( current . word_position - 1 ) ;
240
226
report (
227
+ // @ts -expect-error: SentenceNodeは独自であるため
241
228
sentence ,
242
229
new RuleError (
243
230
`一文に二回以上利用されている助詞 "${ joshiName } " がみつかりました。` ,
0 commit comments