@@ -427,25 +427,25 @@ export class YAMLSourceCode extends TextSourceCodeBase<{
427427 if ( node ?. type !== "Program" ) {
428428 return null ;
429429 }
430- const fakeGlobalScope : Scope . Scope = {
431- type : "global" ,
432- block : node as never ,
433- set : new Map ( ) ,
434- through : [ ] ,
435- childScopes : [ ] ,
436- variableScope : null as never ,
437- variables : [ ] ,
438- references : [ ] ,
439- functionExpressionScope : false ,
440- isStrict : false ,
441- upper : null ,
442- implicit : {
443- variables : [ ] ,
444- set : new Map ( ) ,
430+ return createFakeGlobalScope ( this . ast ) ;
431+ }
432+
433+ /**
434+ * Compatibility for ESLint's SourceCode API
435+ * @deprecated YAML does not have scopes
436+ */
437+ public get scopeManager ( ) : Scope . ScopeManager | null {
438+ return {
439+ scopes : [ ] ,
440+ globalScope : createFakeGlobalScope ( this . ast ) ,
441+ acquire : ( node ) => {
442+ if ( node . type === "Program" ) {
443+ return createFakeGlobalScope ( this . ast ) ;
444+ }
445+ return null ;
445446 } ,
447+ getDeclaredVariables : ( ) => [ ] ,
446448 } ;
447- fakeGlobalScope . variableScope = fakeGlobalScope ;
448- return fakeGlobalScope ;
449449 }
450450
451451 /**
@@ -495,3 +495,29 @@ function isNode(value: unknown): value is AST.YAMLNode {
495495function nodesOrTokensOverlap ( first : YAMLToken , second : YAMLToken ) : boolean {
496496 return first . range [ 0 ] < second . range [ 1 ] && second . range [ 0 ] < first . range [ 1 ] ;
497497}
498+
499+ /**
500+ * Creates a fake global scope for YAML files.
501+ * @deprecated YAML does not have scopes
502+ */
503+ function createFakeGlobalScope ( node : AST . YAMLProgram ) : Scope . Scope {
504+ const fakeGlobalScope : Scope . Scope = {
505+ type : "global" ,
506+ block : node as never ,
507+ set : new Map ( ) ,
508+ through : [ ] ,
509+ childScopes : [ ] ,
510+ variableScope : null as never ,
511+ variables : [ ] ,
512+ references : [ ] ,
513+ functionExpressionScope : false ,
514+ isStrict : false ,
515+ upper : null ,
516+ implicit : {
517+ variables : [ ] ,
518+ set : new Map ( ) ,
519+ } ,
520+ } ;
521+ fakeGlobalScope . variableScope = fakeGlobalScope ;
522+ return fakeGlobalScope ;
523+ }
0 commit comments