Essential rules for Qwik framework patterns including dollar functions, hooks, and serialization validation.
Uses the TypeScript compiler to detect capture of unserializable data in dollar ($) scopes.
/**
* Detects capture of unserializable data in dollar ($) scopes using TypeScript type checking
* @param options Configuration for the rule
* @param options.allowAny Whether to allow 'any' type captures (default: true)
*/
validLexicalScope: Rule<[{ allowAny?: boolean }]>;
interface DetectorOptions {
allowAny: boolean;
}Rule Configuration:
Options Schema:
{
type: 'object',
properties: {
allowAny: {
type: 'boolean',
default: true
}
},
additionalProperties: false
}Error Messages:
referencesOutside: When referencing variables inside different scopes requiring serializationinvalidJsxDollar: When using functions as event handlers without proper wrappingmutableIdentifier: When capturing mutable identifiers that can't be serializedUsage Example:
// ❌ Invalid: capturing non-serializable closure
function component() {
const callback = () => console.log('hello');
return <button onClick$={callback} />; // Error: functions not serializable
}
// ✅ Valid: proper dollar wrapping
function component() {
const callback = $(() => console.log('hello'));
return <button onClick$={callback} />;
}Detects invalid use of use hooks in Qwik components.
/**
* Detects invalid use of use hooks
* Targets CallExpression with callee.name matching /^use[A-Z]/
*/
useMethodUsage: Rule;Rule Configuration:
Usage Example:
// ❌ Invalid: incorrect hook usage
function component() {
const state = useState(); // Error: improper hook call
return <div>{state}</div>;
}
// ✅ Valid: proper hook usage
export default component$(() => {
const state = useSignal(0);
return <div>{state.value}</div>;
});Detects unused server$() functions in the codebase.
/**
* Detects unused server$() functions
*/
unusedServer: Rule;Rule Configuration:
Usage Example:
// ❌ Invalid: unused server function
const unusedServerFunction = server$(() => {
return { data: 'unused' };
}); // Error: server function defined but never used
// ✅ Valid: used server function
const getServerData = server$(() => {
return { data: 'server data' };
});
export default component$(() => {
const serverData = useResource$(getServerData);
return <div>{serverData.value?.data}</div>;
});Lexical Scope Violations:
Hook Usage Errors:
Server Function Issues:
The valid-lexical-scope rule requires TypeScript compiler integration:
Required Setup:
// ESLint configuration must include TypeScript parser options
parserOptions: {
projectService: true, // or project: ['./tsconfig.json']
tsconfigRootDir: import.meta.dirname,
}Type Checking Process:
// Rule type definitions (standardized to TSESLint)
type Rule<TOptions = any> = TSESLint.RuleModule<string, TOptions>;
// TypeScript integration types
interface DetectorOptions {
allowAny: boolean;
}
// ESLint rule context
interface RuleContext {
report(descriptor: ReportDescriptor): void;
getSourceCode(): SourceCode;
parserServices?: {
program: ts.Program;
esTreeNodeToTSNodeMap: WeakMap<any, ts.Node>;
};
}
// Error reporting
interface ReportDescriptor {
node: any;
messageId: string;
data?: Record<string, any>;
fix?: (fixer: RuleFixer) => Fix | Fix[];
}