Skip to content

Commit fdd9c19

Browse files
committed
docs: explain rule traceability and .at() magic
1 parent a781512 commit fdd9c19

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ TSSLint solves this by running directly as a `tsserver` plugin. By sharing the e
2828
* **Zero Rules**: Comes with no built-in rules, giving full control to the developer.
2929
* **Direct AST Access**: Rule authoring uses native TypeScript APIs directly.
3030
* **Low Noise**: Violations are reported as "Message" diagnostics, avoiding interference with compiler errors.
31+
* **Built-in Rule Traceability**: Diagnostics automatically carry a source trace. In your editor, you can jump from a reported error directly to the exact line in your **rule's source code** that generated it.
3132

3233
## How It Works
3334

@@ -107,6 +108,7 @@ export default defineRule(({ typescript: ts, file, report }) => {
107108

108109
### Rule Caching Mechanism
109110

111+
110112
TSSLint's high performance comes from its intelligent caching strategy, which automatically distinguishes between **Syntax-Aware** and **Type-Aware** rules.
111113

112114
All rule diagnostics are cached by default. The cache is automatically disabled for a rule in two scenarios:
@@ -116,6 +118,21 @@ All rule diagnostics are cached by default. The cache is automatically disabled
116118

117119
This automatic differentiation maximizes performance for simple syntax rules while maintaining correctness for complex type-aware rules.
118120

121+
### Rule Debugging & Traceability (The `.at()` Magic)
122+
123+
TSSLint is designed to make rule debugging trivial. Every time you call `report()`, TSSLint automatically captures the current JavaScript stack trace and attaches it to the diagnostic as **Related Information**.
124+
125+
This means: **You can click on the diagnostic in your editor and jump directly to the line in your rule's source code that triggered the report.**
126+
127+
The `.at()` method is generally not needed, but is provided for advanced scenarios where you wrap `report()` in a helper function and need to adjust the stack depth to point to the correct logic:
128+
129+
```ts
130+
// Example of advanced usage to adjust stack depth
131+
report('message', start, end)
132+
.at(new Error(), 2) // Adjusts the stack index to skip the helper function's frame
133+
.withFix(...);
134+
```
135+
119136
## CLI Usage
120137

121138
The `@tsslint/cli` package provides a command-line tool for CI/CD and build processes.

0 commit comments

Comments
 (0)