@@ -26,6 +26,7 @@ import type { ValidateError, Validator } from "../utils/validator-factory";
2626import { compile } from "../utils/validator-factory" ;
2727import type { SchemaObject } from "../utils/types" ;
2828import fs from "fs" ;
29+ import { getCwd , getFilename , getSourceCode } from "../utils/compat" ;
2930
3031const CATALOG_URL = "https://www.schemastore.org/api/json/catalog.json" ;
3132
@@ -161,6 +162,7 @@ export default createRule("no-invalid", {
161162 type : "suggestion" ,
162163 } ,
163164 create ( context , { filename } ) {
165+ const sourceCode = getSourceCode ( context ) ;
164166 const cwd = getCwd ( context ) ;
165167 const relativeFilename = filename . startsWith ( cwd )
166168 ? path . relative ( cwd , filename )
@@ -172,7 +174,6 @@ export default createRule("no-invalid", {
172174 }
173175
174176 let existsExports = false ;
175- const sourceCode = context . getSourceCode ( ) ;
176177
177178 /**
178179 * Validate JSON Schema
@@ -254,17 +255,17 @@ export default createRule("no-invalid", {
254255
255256 return {
256257 Program ( node ) {
257- if ( context . parserServices . isJSON ) {
258+ if ( sourceCode . parserServices . isJSON ) {
258259 const program = node as JSONAST . JSONProgram ;
259260 validateData ( getStaticJSONValue ( program ) , ( error ) => {
260261 return errorDataToLoc ( getJSONNodeFromPath ( program , error . path ) ) ;
261262 } ) ;
262- } else if ( context . parserServices . isYAML ) {
263+ } else if ( sourceCode . parserServices . isYAML ) {
263264 const program = node as YAML . YAMLProgram ;
264265 validateData ( getStaticYAMLValue ( program ) , ( error ) => {
265266 return errorDataToLoc ( getYAMLNodeFromPath ( program , error . path ) ) ;
266267 } ) ;
267- } else if ( context . parserServices . isTOML ) {
268+ } else if ( sourceCode . parserServices . isTOML ) {
268269 const program = node as TOML . TOMLProgram ;
269270 validateData ( getStaticTOMLValue ( program ) , ( error ) => {
270271 return errorDataToLoc ( getTOMLNodeFromPath ( program , error . path ) ) ;
@@ -358,13 +359,13 @@ export default createRule("no-invalid", {
358359 /** Find schema path from program */
359360 function findSchemaPath ( node : unknown ) {
360361 let $schema = null ;
361- if ( context . parserServices . isJSON ) {
362+ if ( sourceCode . parserServices . isJSON ) {
362363 const program = node as JSONAST . JSONProgram ;
363364 $schema = findSchemaPathFromJSON ( program ) ;
364- } else if ( context . parserServices . isYAML ) {
365+ } else if ( sourceCode . parserServices . isYAML ) {
365366 const program = node as YAML . YAMLProgram ;
366367 $schema = findSchemaPathFromYAML ( program ) ;
367- } else if ( context . parserServices . isTOML ) {
368+ } else if ( sourceCode . parserServices . isTOML ) {
368369 const program = node as TOML . TOMLProgram ;
369370 $schema = findSchemaPathFromTOML ( program ) ;
370371 }
@@ -374,7 +375,7 @@ export default createRule("no-invalid", {
374375 path . dirname (
375376 typeof context . getPhysicalFilename === "function"
376377 ? context . getPhysicalFilename ( )
377- : getPhysicalFilename ( context . getFilename ( ) ) ,
378+ : getPhysicalFilename ( getFilename ( context ) ) ,
378379 ) ,
379380 $schema ,
380381 )
@@ -384,7 +385,7 @@ export default createRule("no-invalid", {
384385
385386 /** Validator from $schema */
386387 function get$SchemaValidators ( context : RuleContext ) : Validator [ ] | null {
387- const $schemaPath = findSchemaPath ( context . getSourceCode ( ) . ast ) ;
388+ const $schemaPath = findSchemaPath ( sourceCode . ast ) ;
388389 if ( ! $schemaPath ) return null ;
389390
390391 const validator = schemaPathToValidator ( $schemaPath , context ) ;
@@ -560,16 +561,6 @@ export default createRule("no-invalid", {
560561 } ,
561562} ) ;
562563
563- /**
564- * Get cwd
565- */
566- function getCwd ( context : RuleContext ) {
567- if ( context . getCwd ) {
568- return context . getCwd ( ) ;
569- }
570- return path . resolve ( "" ) ;
571- }
572-
573564/**
574565 * ! copied from https://github.com/mdx-js/eslint-mdx/blob/b97db2e912a416d5d40ddb78ab6c9fa1ab150c17/packages/eslint-mdx/src/helpers.ts#L28-L50
575566 *
0 commit comments