22"use strict" ;
33import { RuleHelper } from "textlint-rule-helper" ;
44import { splitAST as splitSentences , Syntax as SentenceSyntax , SentenceNode } from "sentence-splitter" ;
5- const StringSource = require ( "textlint-util-to-string" ) ;
6- const { getTokenizer} = require ( "kuromojin" ) ;
5+ import { getTokenizer , KuromojiToken } from "kuromojin" ;
76import {
87 is助詞Token , is読点Token ,
98 concatJoishiTokens ,
109 createKeyFromKey ,
11- restoreToSurfaceFromKey , Token
10+ restoreToSurfaceFromKey
1211} from "./token-utils" ;
1312import { TextlintRuleModule } from "@textlint/types" ;
1413import { TxtNode } from "@textlint/types/lib/ast-node-types/src" ;
1514
15+ const StringSource = require ( "textlint-util-to-string" ) ;
16+
1617/**
1718 * Create token map object
1819 * {
@@ -21,7 +22,7 @@ import {TxtNode} from "@textlint/types/lib/ast-node-types/src";
2122 * @param tokens
2223 * @returns {* }
2324 */
24- function createSurfaceKeyMap ( tokens : Token [ ] ) {
25+ function createSurfaceKeyMap ( tokens : KuromojiToken [ ] ) : { [ index : string ] : KuromojiToken [ ] } {
2526 // 助詞のみを対象とする
2627 return tokens . filter ( is助詞Token ) . reduce ( ( keyMap , token ) => {
2728 // "は:助詞.係助詞" : [token]
@@ -31,10 +32,10 @@ function createSurfaceKeyMap(tokens: Token[]) {
3132 }
3233 keyMap [ tokenKey ] . push ( token ) ;
3334 return keyMap ;
34- } , { } ) ;
35+ } , { } as { [ index : string ] : KuromojiToken [ ] } ) ;
3536}
3637
37- function matchExceptionRule ( tokens : Token [ ] ) {
38+ function matchExceptionRule ( tokens : KuromojiToken [ ] ) {
3839 let token = tokens [ 0 ] ;
3940 // "の" の重なりは例外
4041 if ( token . pos_detail_1 === "連体化" ) {
@@ -69,7 +70,7 @@ const defaultOptions = {
6970
7071 TODO: need abstraction
7172 */
72- module . exports = function ( context , options = { } ) {
73+ const report : TextlintRuleModule = function ( context , options = { } ) {
7374 const helper = new RuleHelper ( context ) ;
7475 // 最低間隔値
7576 const minInterval = options . min_interval || defaultOptions . min_interval ;
@@ -116,7 +117,7 @@ module.exports = function (context, options = {}) {
116117 }
117118 */
118119 Object . keys ( joshiTokenSurfaceKeyMap ) . forEach ( key => {
119- const tokens : Token [ ] = joshiTokenSurfaceKeyMap [ key ] ;
120+ const tokens : KuromojiToken [ ] = joshiTokenSurfaceKeyMap [ key ] ;
120121 const joshiName = restoreToSurfaceFromKey ( key ) ;
121122 // check allow
122123 if ( allow . indexOf ( joshiName ) >= 0 ) {
@@ -153,4 +154,5 @@ module.exports = function (context, options = {}) {
153154 } ) ;
154155 }
155156 }
156- } as TextlintRuleModule ;
157+ } ;
158+ export default report ;
0 commit comments