mirror of
https://github.com/denoland/deno.git
synced 2025-02-23 13:43:31 -05:00

This commit adds an unstable lint plugin API. Plugins are specified in the `deno.json` file under `lint.plugins` option like so: ``` { "lint": { "plugins": [ "./plugins/my-plugin.ts", "jsr:@deno/lint-plugin1", "npm:@deno/lint-plugin2" ] } } ``` The API is considered unstable and might be subject to changes in the future. Plugin API was modelled after ESLint API for the most part, but there are no guarantees for compatibility. The AST format exposed to plugins is closely modelled after the AST that `typescript-eslint` uses. Lint plugins use the visitor pattern and can add diagnostics like so: ``` export default { name: "lint-plugin", rules: { "plugin-rule": { create(context) { return { Identifier(node) { if (node.name === "a") { context.report({ node, message: "should be b", fix(fixer) { return fixer.replaceText(node, "_b"); }, }); } }, }; }, }, }, } satisfies Deno.lint.Plugin; ``` Besides reporting errors (diagnostics) plugins can provide automatic fixes that use text replacement to apply changes. --------- Co-authored-by: Marvin Hagemeister <marvin@deno.com> Co-authored-by: David Sherret <dsherret@gmail.com>
18 lines
407 B
Rust
18 lines
407 B
Rust
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
|
|
use deno_ast::ParsedSource;
|
|
use swc::serialize_swc_to_buffer;
|
|
|
|
use crate::util::text_encoding::Utf16Map;
|
|
|
|
mod buffer;
|
|
mod swc;
|
|
mod ts_estree;
|
|
|
|
pub fn serialize_ast_to_buffer(
|
|
parsed_source: &ParsedSource,
|
|
utf16_map: &Utf16Map,
|
|
) -> Vec<u8> {
|
|
// TODO: We could support multiple languages here
|
|
serialize_swc_to_buffer(parsed_source, utf16_map)
|
|
}
|