Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: More fmt improvements #224

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cli/src/commands/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ pub fn exec_fmt(
.align_patterns(config.patterns.align_values)
.indent_section_headers(config.rule.indent_section_headers)
.indent_section_contents(config.rule.indent_section_contents)
.indent_spaces(config.rule.indent_spaces);
.indent_spaces(config.rule.indent_spaces)
.newline_before_curly_brace(config.rule.newline_before_curly_brace)
.empty_line_before_section_header(
config.rule.empty_line_before_section_header,
)
.empty_line_after_section_header(
config.rule.empty_line_after_section_header,
);
let mut changed = false;

for file in files {
Expand Down
9 changes: 9 additions & 0 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ pub struct Rule {
pub indent_section_contents: bool,
/// Number of spaces for indent. Set to 0 to use tabs.
pub indent_spaces: u8,
/// Insert a newline after the rule declaration but before the curly brace.
pub newline_before_curly_brace: bool,
/// Insert an empty line before section headers.
pub empty_line_before_section_header: bool,
/// Insert an empty line after section headers.
pub empty_line_after_section_header: bool,
}

/// Meta specific formatting information.
Expand All @@ -57,6 +63,9 @@ impl Default for Config {
indent_section_headers: true,
indent_section_contents: true,
indent_spaces: 2,
newline_before_curly_brace: false,
empty_line_before_section_header: false,
empty_line_after_section_header: false,
},
meta: Meta { align_values: true },
patterns: Patterns { align_values: true },
Expand Down
54 changes: 54 additions & 0 deletions docs/YARA-X Config Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ The `yr` command looks in `${HOME}/.yara-x.toml` when starting up. If that file
does not exist the default values are used.

An example `.yara-x.toml` file is below, with comments that explain each option.
The values for each option are the default values that are used if omit the
option.

This is the definitive list of supported configuration options, and will be
updated as more are added.

Expand Down Expand Up @@ -60,6 +63,57 @@ rule.indent_section_contents = true
# rule.indent_section_headers and rule.indent_section_contents
rule.indent_spaces = 2

# Add a newline before the curly brace that starts the rule body.
#
# rule a {
# condition:
# true
# }
#
# Becomes:
#
# rule a
# {
# condition:
# true
# }
#
# Note: If you have multiple newlines before the curly brace and this is set to
# `true` then this will ensure exactly two newlines are left.
rule.newline_before_curly_brace = false

# Add an empty line before section headers so that:
#
# rule a {
# strings:
# $ = "AXSERS"
# }
#
# Becomes:
#
# rule a {
#
# strings:
# $ = "AXSERS"
# }
rule.empty_line_before_section_header = false

# Add an empty line after section headers so that:
#
# rule a {
# strings:
# $ = "AXSERS"
# }
#
# Becomes:
#
# rule a {
# strings:
#
# $ = "AXSERS"
# }
rule.empty_line_after_section_header = false

# Align metadata values so that:
#
# rule a {
Expand Down
Loading
Loading