eslint-plugin-sonarjs
Version:
74 lines (73 loc) • 3.72 kB
TypeScript
import type { Rule } from 'eslint';
import { ComputedCache } from '../cache.js';
import { type NormalizedAbsolutePath } from '../files.js';
import { type DependenciesList, type ModuleType } from './resolvers/types.js';
/**
* Cache for the available dependencies by dirname. Exported for tests
*/
export declare const dependenciesCache: ComputedCache<NormalizedAbsolutePath, DependenciesList, NormalizedAbsolutePath>;
/**
* Cache for module type signal by dirname. Exported for tests.
*/
export declare const moduleTypeCache: ComputedCache<NormalizedAbsolutePath, ModuleType | undefined, NormalizedAbsolutePath>;
/**
* Retrieve the dependencies of all the dependency manifest files available for the given file.
*
* @param dir dirname of the context.filename
* @param topDir working dir, will search up to that root
* @returns Map of dependency names to their version strings
*/
export declare function getDependencies(dir: NormalizedAbsolutePath, topDir: NormalizedAbsolutePath): DependenciesList;
/**
* Retrieve the module type signal for a file.
*
* Extension-specific module kinds (.mjs/.mts and .cjs/.cts) are explicit and
* take precedence. Otherwise, package.json#type from the closest manifest only
* is used. If that closest manifest exists but omits "type", default to CommonJS.
*/
export declare function getModuleType(filePath: NormalizedAbsolutePath, topDir: NormalizedAbsolutePath): ModuleType | undefined;
export declare function setCurrentFileInlineDependencies(deps: DependenciesList | null): void;
/**
* Merges inline npm: imports with manifest dependencies, giving precedence to inline imports.
*/
export declare function withCurrentFileInlineDependencies(manifest: DependenciesList): DependenciesList;
export declare function getDependenciesSanitizePaths(context: Rule.RuleContext): DependenciesList;
/**
* Gets the React version from the closest package.json.
*
* @param context ESLint rule context
* @returns React version string (coerced from range) or null if not found
*/
export declare function getReactVersion(context: Rule.RuleContext): string | null;
/**
* Parses a React version string and returns a valid semver version.
* Exported for testing purposes.
*
* @param reactVersion Version string from package.json (e.g., "^18.0.0", "19.0", "catalog:frontend")
* @returns Valid semver version string or null if parsing fails
*/
export declare function parseReactVersion(reactVersion: string): string | null;
export declare function getTypeScriptSignalsFromPackageJsonFiles(packageJsonFiles: Iterable<{
fileContent: string;
}>): {
typeScriptVersionSignals: string[];
hasTypeScriptNativePreview: boolean;
};
/**
* Gets a Node.js version signal by walking up from `dir` toward `topDir`,
* picking the closest package.json with @types/node (preferred) or engines.node.
*
* @param dir directory to start the upward search from (e.g. tsconfig dir, file dir)
* @param topDir analysis base directory; walk stops here. Defaults to `dir` to
* preserve the legacy "manifest at exactly this dir" semantics for callers
* that don't yet provide a separate analysis root.
* @returns raw version string from @types/node or engines.node, or null if not found
*/
export declare function getNodeVersionSignal(dir: NormalizedAbsolutePath, topDir?: NormalizedAbsolutePath): string | null;
/**
* Gets a TypeScript version signal from the closest package.json walking up
* from `dir` to `topDir`. Defaults `topDir = dir` for backward compatibility.
*
* @returns raw version string from typescript dependency, or null if not found
*/
export declare function getTypeScriptVersionSignal(dir: NormalizedAbsolutePath, topDir?: NormalizedAbsolutePath): string | null;