@@ -11,8 +11,8 @@ import {
1111 restoreToSurfaceFromKey ,
1212 is括弧Token ,
1313} 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" ;
1616import { StringSource } from "textlint-util-to-string" ;
1717
1818/**
@@ -107,31 +107,6 @@ export interface Options {
107107 commaCharacters ?: string [ ] ;
108108}
109109
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- }
135110/*
136111 1. Paragraph Node -> text
137112 2. text -> sentences
@@ -159,16 +134,27 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
159134 const isSentenceNode = ( node : TxtNode ) : node is SentenceNode => {
160135 return node . type === SentenceSyntax . Sentence ;
161136 } ;
162- const txtParentNode = splitSentences ( node , {
137+ const txtParentNode = splitSentences ( node as TxtParentNode , {
163138 SeparatorParser : {
164139 separatorCharacters,
165140 } ,
166141 } ) ;
167142 const sentences = txtParentNode . children . filter ( isSentenceNode ) ;
168143 const checkSentence = async ( sentence : SentenceNode ) => {
169144 // コードの中身は無視するため、無意味な文字列に置き換える
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+ } ) ;
172158 const text = sentenceSource . toString ( ) ;
173159 const tokens = await tokenize ( text ) ;
174160 // 助詞 + 助詞は 一つの助詞として扱う
@@ -238,6 +224,7 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
238224 // padding positionを計算する
239225 const originalIndex = sentenceSource . originalIndexFromIndex ( current . word_position - 1 ) ;
240226 report (
227+ // @ts -expect-error: SentenceNodeは独自であるため
241228 sentence ,
242229 new RuleError (
243230 `一文に二回以上利用されている助詞 "${ joshiName } " がみつかりました。` ,
0 commit comments