Home / Class/ AstroCheck Class — astro Architecture

AstroCheck Class — astro Architecture

Architecture documentation for the AstroCheck class in check.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  97a48377_0e57_a94f_8ce7_cd934868bb42["AstroCheck"]
  cc9095c8_1b43_06ff_72e4_ee83e980957f["check.ts"]
  97a48377_0e57_a94f_8ce7_cd934868bb42 -->|defined in| cc9095c8_1b43_06ff_72e4_ee83e980957f
  b1b7a70f_131e_f0a4_b6f7_7c5e60f6d363["constructor()"]
  97a48377_0e57_a94f_8ce7_cd934868bb42 -->|method| b1b7a70f_131e_f0a4_b6f7_7c5e60f6d363
  408ef090_33c2_8dd2_356f_d3ded1591f4b["lint()"]
  97a48377_0e57_a94f_8ce7_cd934868bb42 -->|method| 408ef090_33c2_8dd2_356f_d3ded1591f4b
  eadf2b20_d224_261e_a1fd_53fce5489201["initialize()"]
  97a48377_0e57_a94f_8ce7_cd934868bb42 -->|method| eadf2b20_d224_261e_a1fd_53fce5489201
  055b217e_dcda_35ec_58e0_9733f092ce96["getTsconfig()"]
  97a48377_0e57_a94f_8ce7_cd934868bb42 -->|method| 055b217e_dcda_35ec_58e0_9733f092ce96

Relationship Graph

Source Code

packages/language-tools/language-server/src/check.ts lines 33–209

export class AstroCheck {
	private ts!: typeof import('typescript');
	public linter!: ReturnType<(typeof kit)['createTypeScriptChecker']>;

	constructor(
		private readonly workspacePath: string,
		private readonly typescriptPath: string | undefined,
		private readonly tsconfigPath: string | undefined,
	) {
		this.initialize();
	}

	/**
	 * Lint a list of files or the entire project and optionally log the errors found
	 * @param fileNames List of files to lint, if undefined, all files included in the project will be linted
	 * @param logErrors Whether to log errors by itself. This is disabled by default.
	 * @return {CheckResult} The result of the lint, including a list of errors, the file's content and its file path.
	 */
	public async lint({
		fileNames = undefined,
		cancel = () => false,
		logErrors = undefined,
	}: {
		fileNames?: string[] | undefined;
		cancel?: () => boolean;
		logErrors?:
			| {
					level: 'error' | 'warning' | 'hint';
			  }
			| undefined;
	}): Promise<CheckResult> {
		let files = (fileNames !== undefined ? fileNames : this.linter.getRootFileNames()).filter(
			(file) => {
				// We don't have the same understanding of Svelte and Vue files as their own respective tools (vue-tsc, svelte-check)
				// So we don't want to check them here
				return !file.endsWith('.vue') && !file.endsWith('.svelte');
			},
		);

		const result: CheckResult = {
			status: undefined,
			fileChecked: 0,
			errors: 0,
			warnings: 0,
			hints: 0,
			fileResult: [],
		};
		for (const file of files) {
			if (cancel()) {
				result.status = 'cancelled';
				return result;
			}
			const fileDiagnostics = await this.linter.check(file);

			// Filter diagnostics based on the logErrors level
			const fileDiagnosticsToPrint = fileDiagnostics.filter((diag) => {
				const severity = diag.severity ?? DiagnosticSeverity.Error;
				switch (logErrors?.level ?? 'hint') {
					case 'error':
						return severity <= DiagnosticSeverity.Error;
					case 'warning':
						return severity <= DiagnosticSeverity.Warning;
					case 'hint':
						return severity <= DiagnosticSeverity.Hint;
				}
			});

			if (fileDiagnostics.length > 0) {
				const errorText = this.linter.printErrors(file, fileDiagnosticsToPrint);

				if (logErrors !== undefined && errorText) {
					console.info(errorText);
				}

				const fileSnapshot = this.linter.language.scripts.get(URI.file(file))?.snapshot;
				const fileContent = fileSnapshot?.getText(0, fileSnapshot.getLength());

				result.fileResult.push({
					errors: fileDiagnostics,
					fileContent: fileContent ?? '',
					fileUrl: pathToFileURL(file),

Domain

Frequently Asked Questions

What is the AstroCheck class?
AstroCheck is a class in the astro codebase, defined in packages/language-tools/language-server/src/check.ts.
Where is AstroCheck defined?
AstroCheck is defined in packages/language-tools/language-server/src/check.ts at line 33.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free