FormatterConfig

Struct FormatterConfig 

Source
pub struct FormatterConfig {
    pub indent_width: usize,
    pub use_tabs: bool,
    pub quote_variables: bool,
    pub use_double_brackets: bool,
    pub normalize_functions: bool,
    pub inline_then: bool,
    pub space_before_brace: bool,
    pub preserve_blank_lines: bool,
    pub max_blank_lines: usize,
    pub ignore_patterns: Vec<String>,
}
Expand description

Configuration for bash script formatting

§Examples

use bashrs::bash_quality::FormatterConfig;

let config = FormatterConfig::default();
assert_eq!(config.indent_width, 2);
assert!(!config.use_tabs);

Fields§

§indent_width: usize

Number of spaces per indentation level (default: 2, bash standard)

§use_tabs: bool

Use tabs instead of spaces for indentation (default: false)

§quote_variables: bool

Quote all variable expansions (default: true)

§use_double_brackets: bool

Use [[ ]] instead of [ ] for tests (default: true)

§normalize_functions: bool

Normalize function syntax to name() { } (default: true)

§inline_then: bool

Put ‘then’ on same line as ‘if’ (default: true)

§space_before_brace: bool

Add space before function braces (default: true)

§preserve_blank_lines: bool

Preserve existing blank lines (default: true)

§max_blank_lines: usize

Maximum consecutive blank lines (default: 2)

§ignore_patterns: Vec<String>

Ignore files matching these patterns (default: empty)

Implementations§

Source§

impl FormatterConfig

Source

pub fn new() -> Self

Create a new configuration with default values

§Examples
use bashrs::bash_quality::FormatterConfig;

let config = FormatterConfig::new();
assert_eq!(config.indent_width, 2);
Source

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, String>

Load configuration from a TOML file

§Errors

Returns an error if:

  • The file cannot be read
  • The TOML is invalid
§Examples
use bashrs::bash_quality::FormatterConfig;

let config = FormatterConfig::from_file(".bashrs-fmt.toml").unwrap();
println!("Indent width: {}", config.indent_width);
Source

pub fn from_toml(toml_str: &str) -> Result<Self, String>

Load configuration from TOML string

§Errors

Returns an error if the TOML is invalid

§Examples
use bashrs::bash_quality::FormatterConfig;

let toml = r#"
indent_width = 4
use_tabs = true
"#;

let config = FormatterConfig::from_toml(toml).unwrap();
assert_eq!(config.indent_width, 4);
assert!(config.use_tabs);
Source

pub fn to_file<P: AsRef<Path>>(&self, path: P) -> Result<(), String>

Save configuration to a TOML file

§Errors

Returns an error if the file cannot be written

§Examples
use bashrs::bash_quality::FormatterConfig;

let config = FormatterConfig::default();
config.to_file(".bashrs-fmt.toml").unwrap();
Source

pub fn to_toml(&self) -> Result<String, String>

Convert configuration to TOML string

§Errors

Returns an error if serialization fails

§Examples
use bashrs::bash_quality::FormatterConfig;

let config = FormatterConfig::default();
let toml = config.to_toml().unwrap();
assert!(toml.contains("indent_width"));
Source

pub fn should_ignore(&self, path: &str) -> bool

Check if a file path should be ignored based on patterns

§Examples
use bashrs::bash_quality::FormatterConfig;

let mut config = FormatterConfig::default();
config.ignore_patterns = vec!["**/test/**".to_string()];

assert!(config.should_ignore("src/test/example.sh"));
assert!(!config.should_ignore("src/main.sh"));
Source

pub fn merge(&mut self, other: Self)

Merge with another configuration, preferring non-default values

§Examples
use bashrs::bash_quality::FormatterConfig;

let mut base = FormatterConfig::default();
let mut override_config = FormatterConfig::default();
override_config.indent_width = 4;

base.merge(override_config);
assert_eq!(base.indent_width, 4);

Trait Implementations§

Source§

impl Clone for FormatterConfig

Source§

fn clone(&self) -> FormatterConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FormatterConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FormatterConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for FormatterConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for FormatterConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,