pub struct Config {Show 33 fields
pub disable: bool,
pub line_ending: LineEnding,
pub line_width: usize,
pub tab_size: usize,
pub use_tabchars: bool,
pub fractional_tab_policy: FractionalTabPolicy,
pub max_empty_lines: usize,
pub max_lines_hwrap: usize,
pub max_pargs_hwrap: usize,
pub max_subgroups_hwrap: usize,
pub max_rows_cmdline: usize,
pub always_wrap: Vec<String>,
pub require_valid_layout: bool,
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 explicit_trailing_pattern: String,
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
| Field | Default |
|---|---|
line_width | 80 |
tab_size | 2 |
use_tabchars | false |
max_empty_lines | 1 |
command_case | CaseStyle::Lower |
keyword_case | CaseStyle::Upper |
dangle_parens | false |
dangle_align | DangleAlign::Prefix |
enable_markup | true |
reflow_comments | false |
first_comment_is_literal | true |
Fields§
§disable: boolWhen true, skip all formatting and return the source unchanged.
line_ending: LineEndingOutput line-ending style.
line_width: usizeMaximum rendered line width before wrapping is attempted.
tab_size: usizeNumber of spaces that make up one indentation level when
Self::use_tabchars is false.
use_tabchars: boolEmit tab characters for indentation instead of spaces.
fractional_tab_policy: FractionalTabPolicyHow to handle fractional indentation when Self::use_tabchars is
true.
max_empty_lines: usizeMaximum number of consecutive empty lines to preserve.
max_lines_hwrap: usizeMaximum number of wrapped lines tolerated before switching to a more vertical layout.
max_pargs_hwrap: usizeMaximum number of positional arguments to keep in a hanging-wrap layout before going vertical.
max_subgroups_hwrap: usizeMaximum number of keyword/flag subgroups to keep in a horizontal wrap.
max_rows_cmdline: usizeMaximum rows a hanging-wrap positional group may consume before the layout is rejected and nesting is forced.
always_wrap: Vec<String>Command names (lowercase) that must always use vertical layout, regardless of line width.
require_valid_layout: boolReturn an error when any formatted output line exceeds
Self::line_width.
dangle_parens: boolPlace the closing ) on its own line when a call wraps.
dangle_align: DangleAlignAlignment strategy for a dangling closing ).
min_prefix_chars: usizeLower bound used by layout heuristics when deciding whether a command name is short enough to prefer one style over another.
max_prefix_chars: usizeUpper 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: boolInsert a space before ( for control-flow commands such as if.
separate_fn_name_with_space: boolInsert a space before ( for function/macro definitions.
command_case: CaseStyleOutput casing policy for command names.
keyword_case: CaseStyleOutput casing policy for recognized keywords and flags.
enable_markup: boolEnable markup-aware comment handling.
reflow_comments: boolReflow plain line comments to fit within the configured width.
first_comment_is_literal: boolPreserve the first comment block in a file literally.
literal_comment_pattern: StringRegex for comments that should never be reflowed.
bullet_char: StringPreferred bullet character when normalizing list markup.
enum_char: StringPreferred enumeration punctuation when normalizing numbered list markup.
fence_pattern: StringRegex describing fenced literal comment blocks.
ruler_pattern: StringRegex describing ruler-style comments.
hashruler_min_length: usizeMinimum ruler length before a #----- style line is treated as a ruler.
canonicalize_hashrulers: boolNormalize ruler comments when markup handling is enabled.
explicit_trailing_pattern: StringRegex pattern that marks an inline comment as explicitly trailing its preceding argument. Matching comments are rendered on the same line as the preceding token rather than on their own line.
per_command_overrides: HashMap<String, PerCommandConfig>Per-command configuration overrides keyed by lowercase command name.
Implementations§
Source§impl Config
impl Config
Sourcepub fn for_file(file_path: &Path) -> Result<Self>
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.
Sourcepub fn from_file(path: &Path) -> Result<Self>
pub fn from_file(path: &Path) -> Result<Self>
Load configuration from a specific supported config file.
Sourcepub fn from_files(paths: &[PathBuf]) -> Result<Self>
pub fn from_files(paths: &[PathBuf]) -> Result<Self>
Load configuration by merging several supported config files in order.
Later files override earlier files.
Sourcepub fn from_yaml_str(yaml: &str) -> Result<Self>
pub fn from_yaml_str(yaml: &str) -> Result<Self>
Parse a YAML config string through the same FileConfig schema used by
config files and return the resolved runtime Config.
This validates sections (format: and markup:) and rejects unknown
fields, matching the behavior of file-based config loading.
Sourcepub fn config_sources_for(file_path: &Path) -> Vec<PathBuf>
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
impl Config
Sourcepub fn for_command(&self, command_name: &str) -> CommandConfig<'_>
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.
Sourcepub fn apply_command_case(&self, name: &str) -> String
pub fn apply_command_case(&self, name: &str) -> String
Apply the command_case rule to a command name.
Sourcepub fn apply_keyword_case(&self, keyword: &str) -> String
pub fn apply_keyword_case(&self, keyword: &str) -> String
Apply the keyword_case rule to a keyword token.
Sourcepub fn indent_str(&self) -> String
pub fn indent_str(&self) -> String
The indentation string (spaces or tab).
Sourcepub fn validate_patterns(&self) -> Result<(), String>
pub fn validate_patterns(&self) -> Result<(), String>
Validate that all regex patterns in the config are valid.
Returns Ok(()) if all patterns compile, or an error message
identifying the first invalid pattern.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Config
impl StructuralPartialEq for Config
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.