CLI that type checks bindings in lit-html templates
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
The context system manages TypeScript integration, analysis state, and component stores for comprehensive template analysis. It provides the bridge between the TypeScript compiler API and the Lit analyzer.
Core interface defining the analyzer context with TypeScript integration and analysis state management.
/**
* Core analyzer context interface
* Manages TypeScript integration, configuration, and analysis state
*/
interface LitAnalyzerContext {
/** TypeScript module reference for compiler API access */
readonly ts: typeof import("typescript");
/** TypeScript program instance containing source files */
readonly program: Program;
/** Optional TypeScript server project for IDE integration */
readonly project: tsServer.server.Project | undefined;
/** Analyzer configuration settings */
readonly config: LitAnalyzerConfig;
/** HTML store for managing template documents */
readonly htmlStore: AnalyzerHtmlStore;
/** Dependency store for tracking component dependencies */
readonly dependencyStore: AnalyzerDependencyStore;
/** Document store for managing text documents within templates */
readonly documentStore: AnalyzerDocumentStore;
/** Definition store for component and element definitions */
readonly definitionStore: AnalyzerDefinitionStore;
/** Logger for analyzer output */
readonly logger: LitAnalyzerLogger;
/** Collection of validation rules */
readonly rules: RuleCollection;
/** Currently analyzed source file */
readonly currentFile: SourceFile;
/** Current operation running time for timeout management */
readonly currentRunningTime: number;
/** Flag indicating if cancellation has been requested */
readonly isCancellationRequested: boolean;
/**
* Update analyzer configuration
* @param config - New configuration to apply
*/
updateConfig(config: LitAnalyzerConfig): void;
/**
* Update component dependencies for a source file
* Refreshes dependency information for accurate analysis
* @param file - Source file to update dependencies for
*/
updateDependencies(file: SourceFile): void;
/**
* Update component definitions for a source file
* Refreshes component information for accurate analysis
* @param file - Source file to update components for
*/
updateComponents(file: SourceFile): void;
/**
* Set the base context for analysis operations
* @param options - Context base options including file and timeout
*/
setContextBase(options: LitAnalyzerContextBaseOptions): void;
}Default implementation of the LitAnalyzerContext interface with complete functionality.
/**
* Default implementation of LitAnalyzerContext
* Provides complete context functionality with TypeScript integration
*/
class DefaultLitAnalyzerContext implements LitAnalyzerContext {
/**
* Create a new analyzer context
* @param handler - Plugin context handler providing TypeScript integration
*/
constructor(handler: LitPluginContextHandler);
/** TypeScript module reference */
readonly ts: typeof import("typescript");
/** TypeScript program instance */
readonly program: Program;
/** Optional TypeScript server project */
readonly project: tsServer.server.Project | undefined;
/** Analyzer configuration */
readonly config: LitAnalyzerConfig;
/** HTML store for template documents */
readonly htmlStore: AnalyzerHtmlStore;
/** Dependency store for component dependencies */
readonly dependencyStore: AnalyzerDependencyStore;
/** Document store for text documents */
readonly documentStore: AnalyzerDocumentStore;
/** Definition store for component definitions */
readonly definitionStore: AnalyzerDefinitionStore;
/** Logger instance */
readonly logger: LitAnalyzerLogger;
/** Rule collection */
readonly rules: RuleCollection;
/** Current source file being analyzed */
readonly currentFile: SourceFile;
/** Current operation running time */
readonly currentRunningTime: number;
/** Cancellation request flag */
readonly isCancellationRequested: boolean;
/**
* Update the analyzer configuration
* @param config - New configuration to apply
*/
updateConfig(config: LitAnalyzerConfig): void;
/**
* Update dependencies for a source file
* @param file - Source file to update
*/
updateDependencies(file: SourceFile): void;
/**
* Update components for a source file
* @param file - Source file to update
*/
updateComponents(file: SourceFile): void;
/**
* Set the context base for analysis operations
* @param options - Context options
*/
setContextBase(options: LitAnalyzerContextBaseOptions): void;
}Configuration options for setting the analysis context base.
interface LitAnalyzerContextBaseOptions {
/** Source file to analyze (undefined for global operations) */
file: SourceFile | undefined;
/** Timeout in milliseconds for the operation */
timeout?: number;
/** Whether to throw an exception on cancellation */
throwOnCancellation?: boolean;
}Interface for integrating with TypeScript Language Service plugins.
/**
* Handler interface for TypeScript plugin integration
* Provides access to TypeScript program and project information
*/
interface LitPluginContextHandler {
/** Optional TypeScript module reference */
ts?: typeof import("typescript");
/**
* Get the current TypeScript program
* @returns TypeScript program instance
*/
getProgram(): Program;
/**
* Get the current TypeScript server project (optional)
* @returns TypeScript server project or undefined
*/
getProject?(): tsServer.server.Project;
}Logger interface for controlling analyzer output and debugging.
/**
* Logger interface for analyzer output
* Provides different levels of logging for debugging and monitoring
*/
interface LitAnalyzerLogger {
/** Current logging level */
level: LitAnalyzerLoggerLevel;
/**
* Log debug messages
* @param args - Arguments to log
*/
debug(...args: any[]): void;
/**
* Log error messages
* @param args - Arguments to log
*/
error(...args: any[]): void;
/**
* Log warning messages
* @param args - Arguments to log
*/
warn(...args: any[]): void;
/**
* Log verbose messages
* @param args - Arguments to log
*/
verbose(...args: any[]): void;
}enum LitAnalyzerLoggerLevel {
/** No logging output */
OFF = 0,
/** Error messages only */
ERROR = 1,
/** Warning and error messages */
WARN = 2,
/** Debug, warning, and error messages */
DEBUG = 3,
/** All messages including verbose output */
VERBOSE = 4
}/**
* Default logger implementation with colored console output
* Provides colored output for different log levels
*/
class DefaultLitAnalyzerLogger implements LitAnalyzerLogger {
/**
* Create a new default logger
* @param level - Initial logging level
*/
constructor(level?: LitAnalyzerLoggerLevel);
/** Current logging level */
level: LitAnalyzerLoggerLevel;
/** Log debug messages with blue color */
debug(...args: any[]): void;
/** Log error messages with red color */
error(...args: any[]): void;
/** Log warning messages with yellow color */
warn(...args: any[]): void;
/** Log verbose messages with gray color */
verbose(...args: any[]): void;
}/** Property binding modifier for lit-html templates */
const LIT_HTML_PROP_ATTRIBUTE_MODIFIER: "." = ".";
/** Boolean attribute modifier for lit-html templates */
const LIT_HTML_BOOLEAN_ATTRIBUTE_MODIFIER: "?" = "?";
/** Event listener modifier for lit-html templates */
const LIT_HTML_EVENT_LISTENER_ATTRIBUTE_MODIFIER: "@" = "@";
/** Array of all attribute modifiers */
const LIT_HTML_ATTRIBUTE_MODIFIERS: readonly LitHtmlAttributeModifier[];
/** Union type of all attribute modifiers */
type LitHtmlAttributeModifier = "." | "?" | "@";/** Diagnostic source identifier for lit-plugin */
const DIAGNOSTIC_SOURCE: "lit-plugin" = "lit-plugin";
/** TypeScript ignore comment flag */
const TS_IGNORE_FLAG: "@ts-ignore" = "@ts-ignore";
/** Package version */
const VERSION: "2.0.3" = "2.0.3";
/** Default timeout for analysis operations in milliseconds */
const MAX_RUNNING_TIME_PER_OPERATION: 150 = 150;import { DefaultLitAnalyzerContext, makeConfig, type LitPluginContextHandler } from "lit-analyzer";
import * as ts from "typescript";
// Create TypeScript program
const program = ts.createProgram(["src/my-component.ts"], {
target: ts.ScriptTarget.ES2018,
module: ts.ModuleKind.ESNext
});
// Create plugin context handler
const handler: LitPluginContextHandler = {
ts: ts,
getProgram: () => program
};
// Create context
const context = new DefaultLitAnalyzerContext(handler);
// Create and apply configuration
const config = makeConfig({
strict: true,
rules: {
"no-unknown-tag-name": "error"
}
});
context.updateConfig(config);import { DefaultLitAnalyzerContext, makeConfig, type LitPluginContextHandler } from "lit-analyzer";
// Create context
const context = new DefaultLitAnalyzerContext(handler);
// Configure logging through config
const config = makeConfig({
logging: "debug" // This will set the logger level internally
});
context.updateConfig(config);
// Access the logger if needed
console.log("Current logger level:", context.logger.level);import { LitPluginContextHandler } from "lit-analyzer";
const pluginHandler: LitPluginContextHandler = {
ts: ts,
getProgram: () => languageServiceHost.getProgram(),
getProject: () => project
};