1
1
// LICENSE : MIT
2
2
"use strict" ;
3
- import filter from "unist-util-filter" ;
4
- import { splitAST , Syntax as SentenceSyntax } from "sentence-splitter" ;
3
+ import { splitAST , SentenceSplitterSyntax } from "sentence-splitter" ;
5
4
import { StringSource } from "textlint-util-to-string"
6
5
7
6
function countOfComma ( text ) {
@@ -18,20 +17,18 @@ export default function (context, options = defaultOptions) {
18
17
return {
19
18
[ Syntax . Paragraph ] ( node ) {
20
19
const paragraphSentence = splitAST ( node )
21
- // Remove Code node for avoiding false-positive in `CODE`
22
- const paragraphSentenceWithoutNode = filter ( paragraphSentence , ( node ) => {
23
- return node . type !== Syntax . Code ;
24
- } ) ;
25
- if ( ! paragraphSentenceWithoutNode ) {
26
- return ;
27
- }
28
- // This `sum(0,1,2,3,4,5,6,7,8,9,10)` is ok
29
- // → This is ok
30
- const sentencesWithoutCode = paragraphSentenceWithoutNode
31
- ?. children
32
- ?. filter ( node => node . type === SentenceSyntax . Sentence ) ?? [ ] ;
33
- sentencesWithoutCode . forEach ( sentence => {
34
- const source = new StringSource ( sentence ) ;
20
+ const sentences = paragraphSentence . children . filter ( node => node . type === SentenceSplitterSyntax . Sentence ) ?? [ ] ;
21
+ sentences . forEach ( sentence => {
22
+ // Remove Code node for avoiding false-positive in `CODE`
23
+ // This `sum(0,1,2,3,4,5,6,7,8,9,10)` is ok
24
+ // → This is ok
25
+ const source = new StringSource ( sentence , {
26
+ replacer : ( { node, maskValue } ) => {
27
+ if ( node . type === Syntax . Code ) {
28
+ return maskValue ( "_" ) ;
29
+ }
30
+ }
31
+ } ) ;
35
32
const sentenceValue = source . toString ( ) ;
36
33
const count = countOfComma ( sentenceValue ) ;
37
34
if ( count > maxComma ) {
0 commit comments