pub struct Fix {
pub line: usize,
pub old_text: Option<String>,
pub new_text: String,
pub delete_line: bool,
pub insert_after: bool,
pub start_offset: Option<usize>,
pub end_offset: Option<usize>,
}Expand description
Represents a fix that can be applied to automatically resolve a lint error.
Fixes can operate in two modes:
- Line-based: Operate on entire lines (delete, insert after, replace text on a line)
- Range-based: Operate on byte offsets for precise edits (multiple fixes per line)
Use the convenience methods on DirectiveExt to create fixes from directives:
use nginx_lint_plugin::prelude::*;
let config = nginx_lint_plugin::parse_string("server_tokens on;").unwrap();
let directive = config.all_directives().next().unwrap();
// Replace the entire directive
let fix = directive.replace_with("server_tokens off;");
assert!(fix.is_range_based());
// Delete the directive's line
let fix = directive.delete_line();
assert!(fix.is_range_based());
// Insert a new line after the directive
let fix = directive.insert_after("add_header X-Frame-Options DENY;");
assert!(fix.is_range_based());
// Insert before the directive
let fix = directive.insert_before("# Security headers");
assert!(fix.is_range_based());Fields§
§line: usizeLine number where the fix should be applied (1-indexed)
old_text: Option<String>The original text to replace (if None and new_text is empty, delete the line)
new_text: StringThe new text to insert (empty string with old_text=None means delete)
delete_line: boolWhether to delete the entire line
insert_after: boolWhether to insert new_text as a new line after the specified line
start_offset: Option<usize>Start byte offset for range-based fix (0-indexed, inclusive)
end_offset: Option<usize>End byte offset for range-based fix (0-indexed, exclusive)
Implementations§
Source§impl Fix
impl Fix
Sourcepub fn delete(line: usize) -> Self
👎Deprecated: Use Fix::replace_range() for offset-based fixes instead
pub fn delete(line: usize) -> Self
Use Fix::replace_range() for offset-based fixes instead
Create a fix that deletes an entire line
Sourcepub fn insert_after(line: usize, new_text: &str) -> Self
👎Deprecated: Use Fix::replace_range() for offset-based fixes instead
pub fn insert_after(line: usize, new_text: &str) -> Self
Use Fix::replace_range() for offset-based fixes instead
Create a fix that inserts a new line after the specified line
Sourcepub fn replace_range(
start_offset: usize,
end_offset: usize,
new_text: &str,
) -> Self
pub fn replace_range( start_offset: usize, end_offset: usize, new_text: &str, ) -> Self
Create a range-based fix that replaces bytes from start to end offset
This allows multiple fixes on the same line as long as their ranges don’t overlap.
Sourcepub fn is_range_based(&self) -> bool
pub fn is_range_based(&self) -> bool
Check if this is a range-based fix