Native rules API
Rust facade: lintrs::native. JavaScript facade: @lintrs/cli/native. Guide:
Writing Rust rules.
Rust facade (lintrs::native)
Node ranges and fix ranges use tsrs UTF-8 byte offsets, converted to ESLint
UTF-16 offsets. Explicit Position columns use UTF-16 code units.
report_with_id preserves ESLint message ids and ESTree node type names in
JSON output. Its returned diagnostic can also carry a fix or suggestions.
Suggestion message ids and data are optional and are preserved when supplied.
An empty replacement string deletes the selected range, for both fixes and
suggestions. Native plugins must be rebuilt with ABI native-4.
Set the returned diagnostic's fix_utf16 to a Utf16Fix when replacement text
contains JavaScript code units that Rust strings cannot represent, such as an
unpaired surrogate. Leave its ordinary fix unset. The host preserves these code
units through result finalization and JSON output.
report_at_location preserves explicit ESLint source locations, including line
zero for configuration errors and zero-width ranges with an explicit end. Lines
are one-based (zero is allowed), and columns are zero-based UTF-16 code units;
the JSON formatter adds one to columns. A column of -1 preserves ESLint’s
column-zero diagnostics used to report disabled directives. Set end: None for a start-only report.
The returned diagnostic supports the same message id, node type, fixes and
suggestions as other reports. Fix and suggestion offsets remain UTF-8 bytes,
independent of the diagnostic location.
symbol_has_jsdoc_tag(symbol: P<Symbol>, name: &str) -> bool checks a symbol's
JSDoc tags using the same symbol documentation lookup as the typed adapter.
cache shares state across files for the same library, rule id, options and
cache type. It is isolated per snapshot, project and checker, cleared when a
checker is replaced, and released with its snapshot. Use it for symbol or
type analysis that is valid across files. Keep the returned handle within
the rule execution; retaining it globally can outlive its source program.
Constructors and the export macro
export_rules! emits #[unsafe(no_mangle)] pub extern "C" fn lintrs_rules_v0() -> &'static RulesBundle: the ABI fingerprint (checked before
any rule runs) and the rule table.
Re-exports
lintrs::native::serde_json,lintrs::native::Value— boundary JSON types.lintrs::ts::{ast, checker, compiler, core, scanner}— the tsrs crates.
Constants
ABI_FINGERPRINT—lintrs/<version>/native-<api>/tsrs-<rev>/rustc-<version>/<build-id>.LINTRS_PROBE/probe_address()— single-copy check: a rule library resolves this static in the already-loaded image.
JavaScript facade (@lintrs/cli/native)
Platform keys: `${process.platform}-${process.arch}`, plus -gnu on
Linux (darwin-arm64, linux-x64-gnu).
prepareOptions maps exported rule names to synchronous functions that return
the JSON options passed to Rust. It runs after ESLint validates user options,
once per distinct configuration in each lint worker. A single option is passed
as its object; zero or multiple options are passed as an array. Use it to supply
runtime data such as available built-in methods. Keep the function deterministic
for a configuration and process, and return JSON-serializable data. The prepared
options also identify the native program cache, so differing runtime data or
settings cannot share that rule's cached results.
Also exported: NativeRuleTester, buildCrate, packageCrate,
cacheRoot, platformKey, nativeAbi, nativeHome.
