File tree 1 file changed +12
-2
lines changed
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,8 @@ function defineTemplateBodyVisitor(
14
14
templateVisitor : TemplateListener ,
15
15
scriptVisitor ?: Rule . RuleListener
16
16
) {
17
- if ( ! context . parserServices . defineTemplateBodyVisitor ) {
17
+ const parserServices = getParserServices ( context ) ;
18
+ if ( ! parserServices . defineTemplateBodyVisitor ) {
18
19
if ( path . extname ( context . getFilename ( ) ) === ".vue" ) {
19
20
context . report ( {
20
21
loc : { line : 1 , column : 0 } ,
@@ -26,10 +27,19 @@ function defineTemplateBodyVisitor(
26
27
return { } ;
27
28
}
28
29
29
- return context . parserServices . defineTemplateBodyVisitor (
30
+ return parserServices . defineTemplateBodyVisitor (
30
31
templateVisitor ,
31
32
scriptVisitor
32
33
) ;
33
34
}
34
35
36
+ /**
37
+ * This function is API compatible with eslint v8.x and eslint v9 or later.
38
+ * @see https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#from-context-to-sourcecode
39
+ */
40
+ function getParserServices ( context : Rule . RuleContext ) {
41
+ // @ts -expect-error TODO: remove this when eslint v8 support is dropped
42
+ return context . sourceCode ? context . sourceCode . parserServices : context . parserServices
43
+ }
44
+
35
45
export default defineTemplateBodyVisitor ;
You can’t perform that action at this time.
0 commit comments