Skip to main content

DirectiveExt

Trait DirectiveExt 

Source
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:

§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§

Source

fn is(&self, name: &str) -> bool

Check if the directive has the given name.

Source

fn first_arg(&self) -> Option<&str>

Get the first argument’s string value, if any.

Source

fn first_arg_is(&self, value: &str) -> bool

Check if the first argument equals the given value.

Source

fn arg_at(&self, index: usize) -> Option<&str>

Get the argument at the given index.

Source

fn last_arg(&self) -> Option<&str>

Get the last argument’s string value, if any.

Source

fn has_arg(&self, value: &str) -> bool

Check if any argument equals the given value.

Source

fn arg_count(&self) -> usize

Return the number of arguments.

Source

fn line(&self) -> usize

Get the start line number (1-based).

Source

fn column(&self) -> usize

Get the start column number (1-based).

Source

fn full_start_offset(&self) -> usize

Get the byte offset including leading whitespace.

Source

fn replace_with(&self, new_text: &str) -> Fix

Create a Fix that replaces this directive with new text, preserving indentation.

Source

fn delete_line(&self) -> Fix

Create a Fix that deletes this directive’s line.

Source

fn insert_after(&self, new_text: &str) -> Fix

Create a Fix that inserts a new line after this directive, matching indentation.

Source

fn insert_after_many(&self, lines: &[&str]) -> Fix

Create a Fix that inserts multiple new lines after this directive.

Source

fn insert_before(&self, new_text: &str) -> Fix

Create a Fix that inserts a new line before this directive, matching indentation.

Source

fn insert_before_many(&self, lines: &[&str]) -> Fix

Create a Fix that inserts multiple new lines before this directive.

Implementations on Foreign Types§

Source§

impl DirectiveExt for Box<Directive>

Source§

fn is(&self, name: &str) -> bool

Source§

fn first_arg(&self) -> Option<&str>

Source§

fn first_arg_is(&self, value: &str) -> bool

Source§

fn arg_at(&self, index: usize) -> Option<&str>

Source§

fn last_arg(&self) -> Option<&str>

Source§

fn has_arg(&self, value: &str) -> bool

Source§

fn arg_count(&self) -> usize

Source§

fn line(&self) -> usize

Source§

fn column(&self) -> usize

Source§

fn full_start_offset(&self) -> usize

Source§

fn replace_with(&self, new_text: &str) -> Fix

Source§

fn delete_line(&self) -> Fix

Source§

fn insert_after(&self, new_text: &str) -> Fix

Source§

fn insert_after_many(&self, lines: &[&str]) -> Fix

Source§

fn insert_before(&self, new_text: &str) -> Fix

Source§

fn insert_before_many(&self, lines: &[&str]) -> Fix

Source§

impl<T: DirectiveExt + ?Sized> DirectiveExt for &T

Source§

fn is(&self, name: &str) -> bool

Source§

fn first_arg(&self) -> Option<&str>

Source§

fn first_arg_is(&self, value: &str) -> bool

Source§

fn arg_at(&self, index: usize) -> Option<&str>

Source§

fn last_arg(&self) -> Option<&str>

Source§

fn has_arg(&self, value: &str) -> bool

Source§

fn arg_count(&self) -> usize

Source§

fn line(&self) -> usize

Source§

fn column(&self) -> usize

Source§

fn full_start_offset(&self) -> usize

Source§

fn replace_with(&self, new_text: &str) -> Fix

Source§

fn delete_line(&self) -> Fix

Source§

fn insert_after(&self, new_text: &str) -> Fix

Source§

fn insert_after_many(&self, lines: &[&str]) -> Fix

Source§

fn insert_before(&self, new_text: &str) -> Fix

Source§

fn insert_before_many(&self, lines: &[&str]) -> Fix

Implementors§