Skip to main content

Config

Struct Config 

Source
pub struct Config {
Show 26 fields pub line_width: usize, pub tab_size: usize, pub use_tabchars: bool, pub max_empty_lines: usize, pub max_lines_hwrap: usize, pub max_pargs_hwrap: usize, pub max_subgroups_hwrap: usize, pub dangle_parens: bool, pub dangle_align: DangleAlign, pub min_prefix_chars: usize, pub max_prefix_chars: usize, pub separate_ctrl_name_with_space: bool, pub separate_fn_name_with_space: bool, pub command_case: CaseStyle, pub keyword_case: CaseStyle, pub enable_markup: bool, pub reflow_comments: bool, pub first_comment_is_literal: bool, pub literal_comment_pattern: String, pub bullet_char: String, pub enum_char: String, pub fence_pattern: String, pub ruler_pattern: String, pub hashruler_min_length: usize, pub canonicalize_hashrulers: bool, pub per_command_overrides: HashMap<String, PerCommandConfig>,
}
Expand description

Full formatter configuration.

Construct Config::default and set fields as needed before passing it to format_source or related functions.

use cmakefmt::{Config, CaseStyle, DangleAlign};

let config = Config {
    line_width: 100,
    command_case: CaseStyle::Lower,
    dangle_parens: true,
    dangle_align: DangleAlign::Open,
    ..Config::default()
};

§Defaults

FieldDefault
line_width80
tab_size2
use_tabcharsfalse
max_empty_lines1
command_caseCaseStyle::Lower
keyword_caseCaseStyle::Upper
dangle_parensfalse
dangle_alignDangleAlign::Prefix
enable_markuptrue
reflow_commentsfalse
first_comment_is_literaltrue

Fields§

§line_width: usize

Maximum rendered line width before wrapping is attempted.

§tab_size: usize

Number of spaces that make up one indentation level when Self::use_tabchars is false.

§use_tabchars: bool

Emit tab characters for indentation instead of spaces.

§max_empty_lines: usize

Maximum number of consecutive empty lines to preserve.

§max_lines_hwrap: usize

Maximum number of wrapped lines tolerated before switching to a more vertical layout.

§max_pargs_hwrap: usize

Maximum number of positional arguments to keep in a hanging-wrap layout before going vertical.

§max_subgroups_hwrap: usize

Maximum number of keyword/flag subgroups to keep in a horizontal wrap.

§dangle_parens: bool

Place the closing ) on its own line when a call wraps.

§dangle_align: DangleAlign

Alignment strategy for a dangling closing ).

§min_prefix_chars: usize

Lower bound used by layout heuristics when deciding whether a command name is short enough to prefer one style over another.

§max_prefix_chars: usize

Upper bound used by layout heuristics when deciding whether a command name is long enough to prefer one style over another.

§separate_ctrl_name_with_space: bool

Insert a space before ( for control-flow commands such as if.

§separate_fn_name_with_space: bool

Insert a space before ( for function/macro definitions.

§command_case: CaseStyle

Output casing policy for command names.

§keyword_case: CaseStyle

Output casing policy for recognized keywords and flags.

§enable_markup: bool

Enable markup-aware comment handling.

§reflow_comments: bool

Reflow plain line comments to fit within the configured width.

§first_comment_is_literal: bool

Preserve the first comment block in a file literally.

§literal_comment_pattern: String

Regex for comments that should never be reflowed.

§bullet_char: String

Preferred bullet character when normalizing list markup.

§enum_char: String

Preferred enumeration punctuation when normalizing numbered list markup.

§fence_pattern: String

Regex describing fenced literal comment blocks.

§ruler_pattern: String

Regex describing ruler-style comments.

§hashruler_min_length: usize

Minimum ruler length before a #----- style line is treated as a ruler.

§canonicalize_hashrulers: bool

Normalize ruler comments when markup handling is enabled.

§per_command_overrides: HashMap<String, PerCommandConfig>

Per-command configuration overrides keyed by lowercase command name.

Implementations§

Source§

impl Config

Source

pub fn for_file(file_path: &Path) -> Result<Self>

Load configuration for a file at the given path.

Searches for the nearest supported user config (.cmakefmt.yaml, .cmakefmt.yml, then .cmakefmt.toml) starting from the file’s directory and walking up to the repository/filesystem root. If none is found, falls back to the same filenames in the home directory.

Source

pub fn from_file(path: &Path) -> Result<Self>

Load configuration from a specific supported config file.

Source

pub fn from_files(paths: &[PathBuf]) -> Result<Self>

Load configuration by merging several supported config files in order.

Later files override earlier files.

Source

pub fn config_sources_for(file_path: &Path) -> Vec<PathBuf>

Return the config files that would be applied for the given file.

When config discovery is used, this is either the nearest supported config file found by walking upward from the file, or a home directory config if no nearer config exists.

Source§

impl Config

Source

pub fn for_command(&self, command_name: &str) -> CommandConfig<'_>

Returns a Config with any per-command overrides applied for the given command name, plus the appropriate space-before-paren setting.

Source

pub fn apply_command_case(&self, name: &str) -> String

Apply the command_case rule to a command name.

Source

pub fn apply_keyword_case(&self, keyword: &str) -> String

Apply the keyword_case rule to a keyword token.

Source

pub fn indent_str(&self) -> String

The indentation string (spaces or tab).

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

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 Config

Source§

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

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

impl Default for Config

Source§

fn default() -> Self

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

impl PartialEq for Config

Source§

fn eq(&self, other: &Config) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Config

Source§

impl StructuralPartialEq for Config

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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