Skip to content

v0.1.0 #2

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

Merged
merged 21 commits into from
Feb 19, 2025
Merged
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
4 changes: 4 additions & 0 deletions .cargo/deny.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[licenses]
allow = [
"MIT",
]
27 changes: 27 additions & 0 deletions .github/workflows/rust-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Rust Lint
on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable

# Check formatting
- run: cargo fmt --all -- --check

# Run Clippy with warnings treated as errors
- run: cargo clippy --all-targets --all-features -- -D warnings

# Fail on documentation warnings
- run: RUSTDOCFLAGS="-Dwarnings" cargo doc --no-deps --document-private-items

# Install cargo-deny and check for security issues
- name: Install cargo-deny
run: cargo install cargo-deny
- run: cargo deny check

# Install and run cargo-audit for security vulnerabilities
- run: cargo install cargo-audit
- run: cargo audit
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "string-auto-indent"
version = "0.1.0-alpha1"
version = "0.1.0"
authors = ["Jeremy Harris <jeremy.harris@zenosmosis.com>"]
edition = "2021"
description = "Normalizes multi-line string indentation while preserving platform-specific line endings."
Expand All @@ -9,3 +9,4 @@ license = "MIT"

[dependencies]
doc-comment = "0.3.3"
line-ending = "1.2.0"
87 changes: 74 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Multi-line String Auto Indent
# Multi-line String Auto-Indent

[![made-with-rust][rust-logo]][rust-src-page]
[![crates.io][crates-badge]][crates-page]
Expand Down Expand Up @@ -29,6 +29,10 @@ cargo add string-auto-indent

## Usage

## Example 1: Basic Indentation

This example removes unnecessary leading spaces while preserving the relative indentation of nested lines.

```rust
use string_auto_indent::{auto_indent, LineEnding};

Expand All @@ -38,29 +42,36 @@ let text = r#"
Level 1
Level 2
Level 3
"#;
"#;

// For cross-platform testing
let line_ending = LineEnding::detect(text);
// Expected output after applying auto indentation
let expected = r#"
String Auto Indent

Level 1
Level 2
Level 3
"#;

// With auto-indent
// Verify that `auto_indent` correctly normalizes indentation
assert_eq!(
auto_indent(text),
// For cross-platform testing: Restore platform-specific line endings
line_ending.restore("String Auto Indent\n\nLevel 1\n Level 2\n Level 3\n")
expected,
"The auto_indent function should normalize leading whitespace."
);

// Without auto-indent
assert_eq!(
// Ensure the original text is not identical to the expected output
// This confirms that `auto_indent` actually modifies the string.
assert_ne!(
text,
// For cross-platform testing: Restore platform-specific line endings
line_ending.restore("\n String Auto Indent\n\n Level 1\n Level 2\n Level 3\n"),
expected,
"The original text should *not* be identical to the expected output before normalization."
);
```

### Example Output

**With `auto-indent` enabled.**
#### With `auto-indent`

```text
String Auto Indent
Expand All @@ -70,7 +81,7 @@ Level 1
Level 3
```

**With `auto-intent` disabled.**
#### Without `auto-intent`

```text
String Auto Indent
Expand All @@ -80,6 +91,54 @@ Level 1
Level 3
```

## Example 2: Mixed Indentation

This example demonstrates how `auto_indent` normalizes inconsistent indentation while preserving the relative structure of nested content.

```rust
use string_auto_indent::{auto_indent, LineEnding};

let text = r#"
String Auto Indent

1. Point 1
a. Sub point a
b. Sub point b
2. Point 2
a. Sub point a
b. Sub piont b
1b. Sub piont 1b
"#;

// Expected output after applying auto indentation
let expected = r#"
String Auto Indent

1. Point 1
a. Sub point a
b. Sub point b
2. Point 2
a. Sub point a
b. Sub piont b
1b. Sub piont 1b
"#;

// Verify that `auto_indent` correctly normalizes indentation
assert_eq!(
auto_indent(text),
expected,
"The auto_indent function should normalize leading whitespace."
);

// Ensure the original text is not identical to the expected output
// This confirms that `auto_indent` actually modifies the string.
assert_ne!(
text,
expected,
"The original text should *not* be identical to the expected output before normalization."
);
```

## How It Works

1. Detects the platform’s line endings (`\n`, `\r\n`, `\r`) and normalizes input for processing.
Expand All @@ -93,6 +152,8 @@ Level 1
- Formatting log messages or CLI output while ensuring alignment.
- Cleaning up documentation strings or multi-line literals in indented Rust code.
- Processing structured text while ensuring consistent indentation.
- Declaring multi-line variables in code where the indentation should match the codebase for readability, but the actual string content should not retain unnecessary leading spaces.
- Ensuring consistent formatting in generated strings for use in templates, serialization, or output rendering.

## License
Licensed under **MIT**. See [`LICENSE`][license-page] for details.
Expand Down
4 changes: 2 additions & 2 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use string_auto_indent::auto_indent;

fn main() {
println!("");
println!();
let text = r#"Example:
A
B
Expand All @@ -15,5 +15,5 @@ fn main() {

println!("Without auto-indent:");
print!("{}", text);
println!("");
println!();
}
Loading