2
2
* @author kazuya kawaguchi (a.k.a. kazupon)
3
3
*/
4
4
import { extname } from 'path'
5
- import parse5 from 'parse5'
5
+ import * as parse5 from 'parse5'
6
6
import { defineCustomBlocksVisitor , getLocaleMessages } from '../utils/index'
7
7
import debugBuilder from 'debug'
8
8
import type { AST as JSONAST } from 'jsonc-eslint-parser'
9
9
import type { AST as YAMLAST } from 'yaml-eslint-parser'
10
10
import type { RuleContext , RuleListener } from '../types'
11
11
import { createRule } from '../utils/rule'
12
+ import type { DefaultTreeAdapterMap } from 'parse5'
12
13
13
14
const debug = debugBuilder ( 'eslint-plugin-vue-i18n:no-html-messages' )
14
15
15
- function findHTMLNode (
16
- node : parse5 . DocumentFragment
17
- ) : parse5 . Element | undefined {
18
- return node . childNodes . find ( ( child ) : child is parse5 . Element => {
19
- if ( child . nodeName !== '#text' && ( child as parse5 . Element ) . tagName ) {
16
+ type DocumentFragment = DefaultTreeAdapterMap [ 'documentFragment' ]
17
+ type Element = DefaultTreeAdapterMap [ 'element' ]
18
+ function findHTMLNode ( node : DocumentFragment ) : Element | undefined {
19
+ return node . childNodes . find ( ( child ) : child is Element => {
20
+ if ( child . nodeName !== '#text' && ( child as Element ) . tagName ) {
20
21
return true
21
22
}
22
23
return false
@@ -36,7 +37,7 @@ function create(context: RuleContext): RuleListener {
36
37
}
37
38
const htmlNode = parse5 . parseFragment ( `${ node . value } ` , {
38
39
sourceCodeLocationInfo : true
39
- } ) as parse5 . DocumentFragment
40
+ } )
40
41
const foundNode = findHTMLNode ( htmlNode )
41
42
if ( ! foundNode ) {
42
43
return
@@ -64,7 +65,7 @@ function create(context: RuleContext): RuleListener {
64
65
}
65
66
const htmlNode = parse5 . parseFragment ( `${ node . value } ` , {
66
67
sourceCodeLocationInfo : true
67
- } ) as parse5 . DocumentFragment
68
+ } )
68
69
const foundNode = findHTMLNode ( htmlNode )
69
70
if ( ! foundNode ) {
70
71
return
0 commit comments