11import { getFixes } from './fix.js' ;
2- import { SourceCode } from './source_code.js' ;
2+ import { SOURCE_CODE } from './source_code.js' ;
33
44import type { Fix , FixFn } from './fix.ts' ;
5+ import type { SourceCode } from './source_code.ts' ;
56import type { Node } from './types.ts' ;
67
78// Diagnostic in form passed by user to `Context#report()`
@@ -33,13 +34,11 @@ export const diagnostics: DiagnosticReport[] = [];
3334 * @param context - `Context` object
3435 * @param ruleIndex - Index of this rule within `ruleIds` passed from Rust
3536 * @param filePath - Absolute path of file being linted
36- * @param sourceText - Source text of file being linted
3737 */
3838export let setupContextForFile : (
3939 context : Context ,
4040 ruleIndex : number ,
4141 filePath : string ,
42- sourceText : string ,
4342) => void ;
4443
4544/**
@@ -68,10 +67,6 @@ export interface InternalContext {
6867 ruleIndex : number ;
6968 // Absolute path of file being linted
7069 filePath : string ;
71- // `SourceCode` class instance for this rule.
72- // Rule has single `SourceCode` instance that is updated for each file
73- // (NOT new `SourceCode` instance for each file).
74- sourceCode : SourceCode ;
7570 // Options
7671 options : unknown [ ] ;
7772 // `true` if rule can provide fixes (`meta.fixable` in `RuleMeta` is 'code' or 'whitespace')
@@ -96,7 +91,6 @@ export class Context {
9691 this . #internal = {
9792 id : fullRuleName ,
9893 filePath : '' ,
99- sourceCode : new SourceCode ( ) ,
10094 ruleIndex : - 1 ,
10195 options : [ ] ,
10296 isFixable,
@@ -125,8 +119,9 @@ export class Context {
125119 }
126120
127121 // Getter for `SourceCode` for file being linted.
128- get sourceCode ( ) {
129- return getInternal ( this , 'access `context.sourceCode`' ) . sourceCode ;
122+ get sourceCode ( ) : SourceCode {
123+ getInternal ( this , 'access `context.sourceCode`' ) ;
124+ return SOURCE_CODE ;
130125 }
131126
132127 /**
@@ -148,12 +143,11 @@ export class Context {
148143 }
149144
150145 static {
151- setupContextForFile = ( context , ruleIndex , filePath , sourceText ) => {
146+ setupContextForFile = ( context , ruleIndex , filePath ) => {
152147 // TODO: Support `options`
153148 const internal = context . #internal;
154149 internal . ruleIndex = ruleIndex ;
155150 internal . filePath = filePath ;
156- internal . sourceCode . text = sourceText ;
157151 } ;
158152
159153 getInternal = ( context , actionDescription ) => {
0 commit comments