How to Integrate TSL Rules into TSSLint Using fromTSLRules for Functional Linting

The fromTSLRules helper exported from @tsslint/config converts TSL rules into TSSLint-compatible implementations by dynamically resolving the tsl package, loading its visitor entries, and wrapping each rule with a TypeScript server-compatible context.

TSSLint, the TypeScript-server based linter developed by johnsoncodehk/tsslint, provides a seamless migration path for existing TSL rule sets through the fromTSLRules utility. This bridge allows you to integrate TSL rules into TSSLint using fromTSLRules without rewriting logic, leveraging zero-lag diagnostics inside the TypeScript language server. The conversion preserves original visitor logic while adapting report calls and AST traversal for TSSLint's architecture.

How fromTSLRules Bridges TSL and TSSLint

The fromTSLRules function in packages/config/lib/tsl.ts performs three critical operations to ensure functional parity between the original TSL linter and TSSLint.

Package Discovery and Resolution

According to the source code in packages/config/lib/tsl.ts (lines 7-22), the helper walks up the directory tree from its own location to locate a node_modules/tsl folder. If the package cannot be resolved, it throws an error immediately, ensuring clear failure signals during configuration loading.

Visitor Entry Loading

Once discovered, the function loads TSL's internal visitor mappings. It specifically searches for files matching visitorEntries-*.js within the tsl package (lines 24-28), extracting getContextUtils and the visitorEntries array that maps TypeScript SyntaxKind values to TSL visitor method names.

Rule Conversion Logic

The core conversion happens in convertTSLRule (lines 35-70). This wrapper creates a compatible RuleContext containing typescript, file, program, and report references. During AST traversal, it looks up visitor names via visitorEntries and invokes the original TSL rule's visitor methods, translating TSL report descriptors into TSSLint report calls while preserving stack-trace information for traceability.

Step-by-Step Integration Guide

Follow these steps to integrate TSL rules into your TSSLint configuration:

  1. Install the TSL package in your workspace:

    npm install -D tsl

    The fromTSLRules helper requires the package to exist under node_modules for dynamic resolution.

  2. Import the configuration utilities from @tsslint/config and your desired TSL rule set.

  3. Convert the rules using fromTSLRules(), passing either core.all() for all built-in rules or a selective array of specific rules.

  4. Export the configuration using defineConfig(), spreading the converted rules into the rules property.

Configuration Examples

Here are practical implementations taken directly from the johnsoncodehk/tsslint repository.

Converting All TSL Rules

The test fixture at fixtures/compat-tsl/tsslint.config.ts demonstrates the standard approach:

// tsslint.config.ts
import { defineConfig, fromTSLRules } from '@tsslint/config';
import { core } from 'tsl';

export default defineConfig({
  rules: fromTSLRules(core.all()),
});

Selective Rule Integration

For targeted linting, pass specific rule instances instead of the entire core collection:

import { defineConfig, fromTSLRules } from '@tsslint/config';
import { noConsole } from 'tsl/rules';

export default defineConfig({
  rules: fromTSLRules([noConsole]),
});

Summary

  • The fromTSLRules helper in packages/config/lib/tsl.ts provides automatic conversion of TSL rules to TSSLint format.
  • It resolves the tsl package dynamically, loads visitor entries from visitorEntries-*.js, and wraps rules with convertTSLRule (lines 35-70).
  • The conversion preserves original rule logic while adapting report calls and context for TypeScript server compatibility.
  • Reference implementation exists in fixtures/compat-tsl/tsslint.config.ts.

Frequently Asked Questions

What happens if the tsl package is not installed?

If fromTSLRules cannot locate node_modules/tsl while traversing up the directory tree (lines 7-22), it throws a descriptive error indicating that the TSL package is required but missing from the workspace dependencies.

Does fromTSLRules support custom TSL rules or only the core set?

The function accepts any array of TSL.Rule objects. You can pass custom rules alongside or instead of core.all(), as long as they conform to the TSL rule interface with visitor methods and report descriptors.

How does the conversion affect linting performance?

The conversion introduces minimal overhead. The wrapper created by convertTSLRule executes the original visitor logic directly while adapting the context object. Since TSSLint runs inside the TypeScript language server, you gain zero-lag diagnostics compared to traditional file-watching linting approaches.

Can I mix native TSSLint rules with converted TSL rules?

Yes. fromTSLRules returns a plain object mapping rule names to TSSLint Rule functions, which can be merged with native TSSLint rules using standard object spreading in the rules configuration property.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →