@adguard/aglint
Version:
Universal adblock filter list linter.
59 lines (58 loc) • 2.54 kB
TypeScript
import { type LinterConfig } from '../common';
/**
* Callback for the config finder, called when a potential config file is found.
* If you want to stop the search, return `true` from the callback, otherwise
* return `false`.
*
* @param path Path to the config file
* @returns `true` if the search should be stopped, `false` otherwise
*/
export type ConfigFinderCallback = (path: string) => boolean | Promise<boolean>;
/**
* Result of the config finder
*/
export type ConfigFinderResult = {
/**
* Path to the config file
*/
path: string;
/**
* Parsed config object
*/
config: LinterConfig;
};
/**
* Discovers every AGLint config files in the current working directory and its parent directories.
* It only checks file names, not the contents of the files, so it doesn't validate the config files.
* If you didn't abort the search meanwhile, it will scan until it reaches the root directory.
*
* @param cwd Current working directory
* @param callback Callback function that will be called with the path to the config file
* if it is found
* @throws If multiple config files are found in the same directory
*/
export declare function configFinder(cwd: string, callback: ConfigFinderCallback): Promise<void>;
/**
* Finds the next config file in the current working directory and its parent directories.
* It just searches for the first config file and returns its path.
*
* @param cwd Current working directory
* @throws If multiple config files are found in the same directory
* @throws If a config file is found, but it is not valid
* @returns The path to the config file and the parsed config object or `null` if no config file was found
*/
export declare function findNextConfig(cwd: string): Promise<ConfigFinderResult | null>;
/**
* Finds the first root config file in the current working directory and its parent directories.
* It parses the config files and stops the search when it finds the root config file, which
* is the first config file that has the "root" property set to `true`.
*
* If it doesn't find a root config file, but it finds a config file, it will return the first
* config file.
*
* @param cwd Current working directory
* @throws If multiple config files are found in the same directory
* @throws If a config file is found, but it is not valid
* @returns The path to the config file and the parsed config object or `null` if no config file was found
*/
export declare function findNextRootConfig(cwd: string): Promise<ConfigFinderResult | null>;