Skip to main content

pine_lint/
lib.rs

1//! Static analysis for Pine Script ASTs.
2//!
3//! `pine-lint` walks a parsed [`pine_ast::Program`] and reports likely bugs and
4//! non-idiomatic constructs as [`Diagnostic`]s. It is organized around three
5//! pieces:
6//!
7//! - [`Visitor`] + the `walk_*` functions — the reusable traversal core.
8//! - [`LintPass`] — one check; a visitor that collects diagnostics.
9//! - [`lint`] — the driver that runs every registered pass over a program.
10//!
11//! # Example
12//!
13//! ```
14//! use pine_ast::Program;
15//! use pine_lexer::Lexer;
16//! use pine_parser::Parser;
17//!
18//! let src = "x = close == na\n";
19//! let tokens = Lexer::new(src).tokenize().unwrap();
20//! let program = Program::new(Parser::new(tokens).parse().unwrap());
21//!
22//! let diagnostics = pine_lint::lint(&program);
23//! assert_eq!(diagnostics.len(), 1);
24//! assert_eq!(diagnostics[0].rule, "eq-na");
25//! ```
26
27mod pass;
28mod passes;
29
30#[cfg(test)]
31mod test_util;
32
33pub use pass::{lint, lint_with, LintPass};
34pub use pine_ast::visitor::{walk_block, walk_expr, walk_program, walk_stmt, Visitor};
35pub use pine_diagnostics::{Diagnostic, Severity};