pub trait DirectiveExt {
Show 16 methods
// Required methods
fn is(&self, name: &str) -> bool;
fn first_arg(&self) -> Option<&str>;
fn first_arg_is(&self, value: &str) -> bool;
fn arg_at(&self, index: usize) -> Option<&str>;
fn last_arg(&self) -> Option<&str>;
fn has_arg(&self, value: &str) -> bool;
fn arg_count(&self) -> usize;
fn line(&self) -> usize;
fn column(&self) -> usize;
fn full_start_offset(&self) -> usize;
fn replace_with(&self, new_text: &str) -> Fix;
fn delete_line(&self) -> Fix;
fn insert_after(&self, new_text: &str) -> Fix;
fn insert_after_many(&self, lines: &[&str]) -> Fix;
fn insert_before(&self, new_text: &str) -> Fix;
fn insert_before_many(&self, lines: &[&str]) -> Fix;
}Expand description
Extension trait for Directive providing inspection and fix-generation helpers.
This trait adds convenience methods to Directive for:
- Inspection:
is(),first_arg(),has_arg(), etc. - Fix generation:
replace_with(),delete_line(),insert_after(), etc.
§Example
use nginx_lint_plugin::prelude::*;
let config = nginx_lint_plugin::parse_string(
"proxy_pass http://backend;"
).unwrap();
let directive = config.all_directives().next().unwrap();
assert!(directive.is("proxy_pass"));
assert_eq!(directive.first_arg(), Some("http://backend"));
assert_eq!(directive.arg_count(), 1);
// Generate a fix to replace the directive
let fix = directive.replace_with("proxy_pass http://new-backend;");
assert!(fix.is_range_based());Required Methods§
Sourcefn first_arg_is(&self, value: &str) -> bool
fn first_arg_is(&self, value: &str) -> bool
Check if the first argument equals the given value.
Sourcefn full_start_offset(&self) -> usize
fn full_start_offset(&self) -> usize
Get the byte offset including leading whitespace.
Sourcefn replace_with(&self, new_text: &str) -> Fix
fn replace_with(&self, new_text: &str) -> Fix
Create a Fix that replaces this directive with new text, preserving indentation.
Sourcefn delete_line(&self) -> Fix
fn delete_line(&self) -> Fix
Create a Fix that deletes this directive’s line.
Sourcefn insert_after(&self, new_text: &str) -> Fix
fn insert_after(&self, new_text: &str) -> Fix
Create a Fix that inserts a new line after this directive, matching indentation.
Sourcefn insert_after_many(&self, lines: &[&str]) -> Fix
fn insert_after_many(&self, lines: &[&str]) -> Fix
Create a Fix that inserts multiple new lines after this directive.
Sourcefn insert_before(&self, new_text: &str) -> Fix
fn insert_before(&self, new_text: &str) -> Fix
Create a Fix that inserts a new line before this directive, matching indentation.
Sourcefn insert_before_many(&self, lines: &[&str]) -> Fix
fn insert_before_many(&self, lines: &[&str]) -> Fix
Create a Fix that inserts multiple new lines before this directive.