11import { setupFileContext , resetFileContext } from "./context.js" ;
22import { registeredRules } from "./load.js" ;
3- import { allOptions , DEFAULT_OPTIONS_ID } from "./options.js" ;
3+ import { allOptions , areOptionsInitialized , DEFAULT_OPTIONS_ID , setOptions } from "./options.js" ;
44import { diagnostics } from "./report.js" ;
55import { setSettingsForFile , resetSettings } from "./settings.js" ;
66import { ast , initAst , resetSourceAndAst , setupSourceForFile } from "./source_code.js" ;
@@ -12,6 +12,7 @@ import {
1212 finalizeCompiledVisitor ,
1313 initCompiledVisitor ,
1414} from "./visitor.js" ;
15+ import { getExternalRuleOptions } from "../bindings.js" ;
1516
1617// Lazy implementation
1718/*
@@ -46,6 +47,7 @@ const PARSER_SERVICES_DEFAULT: Record<string, unknown> = Object.freeze({});
4647 * @param bufferId - ID of buffer containing file data
4748 * @param buffer - Buffer containing file data, or `null` if buffer with this ID was previously sent to JS
4849 * @param ruleIds - IDs of rules to run on this file
50+ * @param optionsIds - IDs of options to use for rules on this file
4951 * @param settingsJSON - Settings for file, as JSON
5052 * @returns Diagnostics or error serialized to JSON string
5153 */
@@ -54,11 +56,9 @@ export function lintFile(
5456 bufferId : number ,
5557 buffer : Uint8Array | null ,
5658 ruleIds : number [ ] ,
59+ optionsIds : number [ ] ,
5760 settingsJSON : string ,
5861) : string {
59- // TODO: Get `optionsIds` from Rust side
60- const optionsIds = ruleIds . map ( ( _ ) => DEFAULT_OPTIONS_ID ) ;
61-
6262 try {
6363 lintFileImpl ( filePath , bufferId , buffer , ruleIds , optionsIds , settingsJSON ) ;
6464 return JSON . stringify ( { Success : diagnostics } ) ;
@@ -145,6 +145,14 @@ function lintFileImpl(
145145 "Rule IDs and options IDs arrays must be the same length" ,
146146 ) ;
147147
148+ // Initialize external rule options if not already initialized
149+ if ( ! areOptionsInitialized ( ) ) {
150+ const optionsJson = getExternalRuleOptions ( ) ;
151+ if ( optionsJson !== null && optionsJson . length > 0 ) {
152+ setOptions ( optionsJson ) ;
153+ }
154+ }
155+
148156 for ( let i = 0 , len = ruleIds . length ; i < len ; i ++ ) {
149157 const ruleId = ruleIds [ i ] ;
150158 debugAssert ( ruleId < registeredRules . length , "Rule ID out of bounds" ) ;
0 commit comments