rust-yaml 1.1.0

A fast, safe YAML 1.2 library for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
# mise tasks for rust-yaml
# =========================
# Migrated from the legacy GNU Makefile. `mise` (https://mise.jdx.dev) is the
# task runner and tool manager that replaces `make`.
#
# Conventions (every task follows these):
#   * Each `run` block is a triple-quoted TOML string.
#   * The first line is a `#!/usr/bin/env bash` shebang โ€” mise runs the block
#     as a real bash script (the "interpreter marker"), not the default `sh`.
#   * `set -euo pipefail` makes every task fail fast: error (-e), unset var (-u)
#     and broken pipe (pipefail) all abort the task.
#
# The markdown tasks use TOML *literal* strings (''' โ€ฆ ''') instead of basic
# ("""), because their embedded awk programs contain backslash regex escapes
# (\. \* \t) that a basic string would mis-parse as invalid escape sequences.
# The shebang + set -euo pipefail convention is identical inside them.
#
# Usage:  mise run <task>   (e.g. `mise run ci`, `mise run test`)
#         mise tasks        (list everything)
#
# Tool management (rustc/cargo) is intentionally left to rustup, mirroring the
# previous Makefile. Add a [tools] section here if you want mise to pin them.

min_version = "2024.1.0"

# ----------------------------------------------------------------------------
# Help
# ----------------------------------------------------------------------------
[tasks.help]
description = "Show available tasks"
run = """
#!/usr/bin/env bash
set -euo pipefail
mise tasks ls
"""

# ----------------------------------------------------------------------------
# Development environment setup
# ----------------------------------------------------------------------------
[tasks.setup]
description = "Set up development environment (git hooks, dependencies, etc.)"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ”ง Setting up development environment..."
if [ ! -d ".githooks" ]; then mkdir -p .githooks; fi
if [ -f ".githooks/commit-msg" ]; then chmod +x .githooks/commit-msg; fi
echo "๐Ÿ”— Configuring git hooks..."
git config --local core.hooksPath .githooks
if [ -f ".gitmessage" ]; then
  echo "๐Ÿ“‹ Setting commit message template..."
  git config --local commit.template .gitmessage
fi
if ! command -v committed >/dev/null 2>&1; then
  echo "๐Ÿ“ฆ Installing committed (Conventional Commits linter)..."
  if command -v cargo-binstall >/dev/null 2>&1; then
    cargo binstall -y committed
  else
    cargo install committed
  fi
fi
echo "๐Ÿฆ€ Checking Rust components..."
if ! rustup component list --installed | grep -q rustfmt; then rustup component add rustfmt; fi
if ! rustup component list --installed | grep -q clippy; then rustup component add clippy; fi
echo "๐Ÿ”ง Git hooks configuration..."
if command -v pre-commit >/dev/null 2>&1; then
  echo "๐Ÿ’ก Pre-commit is available. Choose your hook system:"
  echo "   โ€ข Manual hooks (current): Already configured in .githooks/"
  echo "   โ€ข Enterprise pre-commit: Run 'mise run pre-commit-install'"
  echo "โœ… Manual git hooks remain active"
else
  echo "โœ… Manual git hooks configured in .githooks/"
  echo "๐Ÿ’ก For enterprise-grade hooks: brew install pre-commit && mise run pre-commit-install"
fi
echo "โœ… Development environment setup complete"
"""

[tasks.dev-setup]
description = "Alias for setup"
depends = ["setup"]
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "Development setup complete. Run 'mise tasks' for available commands."
"""

# ----------------------------------------------------------------------------
# Cleaning
# ----------------------------------------------------------------------------
[tasks.clean]
description = "Clean build artifacts and temporary files"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿงน Cleaning build artifacts..."
cargo clean
rm -f debug_*
rm -f test_*
rm -f lcov.info cobertura.xml
rm -rf target/tarpaulin target/llvm-cov
find . -name "*.tmp" -delete
echo "โœ… Clean complete"
"""

# ----------------------------------------------------------------------------
# Testing
# ----------------------------------------------------------------------------
[tasks.test]
description = "Run all tests"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿงช Running tests..."
timeout 30s cargo test --lib --verbose
"""

[tasks.test-release]
description = "Run tests in release mode"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿงช Running tests in release mode..."
timeout 30s cargo test --lib --release --verbose
"""

[tasks.test-all-features]
description = "Run tests with all features"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿงช Running tests with all features..."
timeout 30s cargo test --lib --all-features --verbose || [ $? -eq 124 ]
"""

[tasks.test-no-default]
description = "Run tests without default features"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿงช Running tests without default features..."
timeout 30s cargo test --lib --no-default-features --verbose || [ $? -eq 124 ]
"""

[tasks.test-nocapture]
description = "Run tests with output capture disabled"
alias = "test-verbose"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿงช Running tests with output visible..."
timeout 30s cargo test -- --nocapture
"""

[tasks.test-lib]
description = "Run library tests only"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿงช Running library tests..."
timeout 30s cargo test --lib
"""

[tasks.test-integration]
description = "Run integration tests"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿงช Running integration tests..."
# `--tests` auto-discovers every `tests/*.rs` binary, so newly added test
# files (e.g. `tests/directives.rs`) get picked up here without being
# enumerated. Matches what CI / nextest sees end-to-end.
timeout 300s cargo test --tests
"""

[tasks.test-security]
description = "Run security-specific tests"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ”’ Running security tests..."
timeout 60s cargo test --test security_limits
timeout 60s cargo test --test security_limits test_nested_alias_expansion_limit
"""

[tasks.yaml-test-suite]
description = "Run upstream yaml-test-suite conformance harness"
alias = "test-yaml-suite"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿงช Running yaml/yaml-test-suite conformance harness..."
git submodule update --init --recursive yaml-test-suite/data
timeout 300s cargo test -p yaml-test-suite -- --nocapture
"""

# ----------------------------------------------------------------------------
# Code quality
# ----------------------------------------------------------------------------
[tasks.format]
description = "Format code"
alias = "fmt"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐ŸŽจ Formatting code..."
cargo fmt
"""

[tasks.format-check]
description = "Check code formatting"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐ŸŽจ Checking code formatting..."
cargo fmt --all -- --check
"""

[tasks.lint]
description = "Run clippy lints"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“Ž Running clippy..."
timeout 30s cargo clippy --all-targets --all-features -- -D warnings
"""

[tasks.lint-fix]
description = "Run clippy with automatic fixes"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“Ž Running clippy with fixes..."
timeout 30s cargo clippy --all-targets --all-features --fix -- -D warnings
"""

[tasks.clippy-strict]
description = "Run clippy with strict CI settings"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“Ž Running clippy with strict CI settings..."
timeout 180s cargo clippy --all-targets --all-features -- -D warnings -D clippy::all -D clippy::pedantic -W clippy::nursery \
  -A clippy::needless_raw_string_hashes \
  -A clippy::format_push_string \
  -A clippy::single_char_pattern \
  -A clippy::unreadable_literal \
  -A clippy::manual_string_new \
  -A clippy::write_with_newline \
  -A clippy::uninlined_format_args \
  -A clippy::semicolon_if_nothing_returned \
  -A clippy::explicit_iter_loop \
  -A clippy::inefficient_to_string \
  -A clippy::match_same_arms \
  -A clippy::doc_markdown \
  -A clippy::too_many_lines
"""

# ----------------------------------------------------------------------------
# Security and audit
# ----------------------------------------------------------------------------
[tasks.audit]
description = "Run security audit"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ”’ Running security audit..."
if ! command -v cargo-audit >/dev/null; then cargo install cargo-audit; fi
cargo audit
"""

[tasks.deny]
description = "Run cargo deny checks"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ”’ Running cargo deny checks..."
if ! command -v cargo-deny >/dev/null; then cargo install cargo-deny; fi
timeout 15s cargo deny check
"""

# ----------------------------------------------------------------------------
# Documentation
# ----------------------------------------------------------------------------
[tasks.doc]
description = "Build documentation (treats rustdoc warnings as errors)"
alias = "docs"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“š Building documentation..."
RUSTDOCFLAGS="-D warnings" cargo doc --all-features --no-deps
"""

[tasks.doc-open]
description = "Build and open documentation"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“š Building and opening documentation..."
cargo doc --all-features --no-deps --open
"""

[tasks.doc-private]
description = "Build documentation including private items"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“š Building documentation with private items..."
cargo doc --all-features --no-deps --document-private-items
"""

# ----------------------------------------------------------------------------
# Benchmarking
# ----------------------------------------------------------------------------
[tasks.bench]
description = "Run benchmarks"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "โšก Running benchmarks..."
cargo bench
"""

[tasks.bench-compile]
description = "Compile benchmarks only"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "โšก Compiling benchmarks..."
cargo bench --no-run
"""

# ----------------------------------------------------------------------------
# Coverage
# ----------------------------------------------------------------------------
[tasks.coverage]
description = "Generate test coverage report (same as CI)"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“Š Generating coverage report (CI-compatible)..."
if ! command -v cargo-tarpaulin >/dev/null; then
  echo "Installing cargo-tarpaulin..."
  cargo install cargo-tarpaulin
fi
cargo tarpaulin --lib --tests --out lcov --output-dir . --verbose --workspace --timeout 120 --exclude-files examples/* benches/*
echo "โœ… Coverage report generated: lcov.info"
echo "๐Ÿ“ˆ Coverage summary:"
cargo tarpaulin --lib --tests --print-summary --workspace --timeout 120 --exclude-files examples/* benches/*
"""

[tasks.coverage-html]
description = "Generate HTML coverage report"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“Š Generating HTML coverage report..."
if ! command -v cargo-tarpaulin >/dev/null; then
  echo "Installing cargo-tarpaulin..."
  cargo install cargo-tarpaulin
fi
cargo tarpaulin --lib --tests --out html --output-dir target/tarpaulin --verbose --workspace --timeout 120 --exclude-files examples/* benches/*
echo "โœ… HTML coverage report generated in target/tarpaulin/"
echo "๐Ÿ“‚ Open target/tarpaulin/tarpaulin-report.html in your browser"
"""

[tasks.coverage-llvm]
description = "Generate coverage using llvm-cov (alternative)"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“Š Generating coverage with llvm-cov..."
if ! command -v cargo-llvm-cov >/dev/null; then
  echo "Installing cargo-llvm-cov..."
  cargo install cargo-llvm-cov
fi
cargo llvm-cov --lib --lcov --output-path lcov.info
echo "โœ… Coverage report generated: lcov.info"
"""

[tasks.coverage-llvm-html]
description = "Generate HTML coverage with llvm-cov"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“Š Generating HTML coverage with llvm-cov..."
if ! command -v cargo-llvm-cov >/dev/null; then
  echo "Installing cargo-llvm-cov..."
  cargo install cargo-llvm-cov
fi
cargo llvm-cov --lib --html
echo "โœ… HTML coverage report generated in target/llvm-cov/html/"
"""

[tasks.coverage-clean]
description = "Clean coverage artifacts"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿงน Cleaning coverage artifacts..."
rm -f lcov.info cobertura.xml
rm -rf target/tarpaulin target/llvm-cov
echo "โœ… Coverage artifacts cleaned"
"""

[tasks.coverage-view]
description = "Generate and open HTML coverage report"
depends = ["coverage-html"]
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐ŸŒ Opening coverage report in browser..."
if [ -f target/tarpaulin/tarpaulin-report.html ]; then
  open target/tarpaulin/tarpaulin-report.html 2>/dev/null \
    || xdg-open target/tarpaulin/tarpaulin-report.html 2>/dev/null \
    || echo "Please open target/tarpaulin/tarpaulin-report.html manually"
fi
"""

[tasks.coverage-install-tools]
description = "Install coverage tools"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“ฆ Installing coverage tools..."
cargo install cargo-tarpaulin cargo-llvm-cov
echo "โœ… Coverage tools installed"
"""

# ----------------------------------------------------------------------------
# Build
# ----------------------------------------------------------------------------
[tasks.build]
description = "Build the project"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ”จ Building project..."
cargo build
"""

[tasks.build-release]
description = "Build in release mode"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ”จ Building project in release mode..."
timeout 30s cargo build --release
"""

[tasks.build-all-features]
description = "Build with all features"
alias = "build-all"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ”จ Building project with all features..."
cargo build --all-features
"""

[tasks.examples]
description = "Run examples"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ’ก Running examples..."
cargo run --example library_comparison
"""

# ----------------------------------------------------------------------------
# Package and release
# ----------------------------------------------------------------------------
[tasks.package]
description = "Package the crate"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“ฆ Packaging crate..."
cargo package
"""

[tasks.package-list]
description = "List files that would be packaged"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“ฆ Listing package contents..."
cargo package --list
"""

# ----------------------------------------------------------------------------
# Quality checks (CI-like)
# ----------------------------------------------------------------------------
[tasks.check]
description = "Run basic checks (build, test, format, lint)"
alias = "checks"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "โœ… Running basic checks..."
mise run format-check
mise run lint
mise run test
echo "โœ… All basic checks passed"
"""

[tasks.check-all]
description = "Run all checks including audit and coverage"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "โœ… Running comprehensive checks..."
mise run format-check
mise run lint
mise run test-all-features
mise run test-no-default
mise run audit
mise run doc
mise run bench-compile
mise run check-markdown
echo "โœ… All comprehensive checks passed"
"""

[tasks.ci]
description = "Run CI pipeline locally (same as GitHub Actions)"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ”„ Running CI pipeline locally..."
mise run format-check
mise run clippy-strict
echo "๐Ÿ—๏ธ  Pre-compiling test artifacts (warms dev-deps for subsequent steps)..."
timeout 300s cargo test --no-run --tests --quiet
mise run test-lib
mise run test-integration
mise run test-security
mise run deny
echo "โœ… CI pipeline completed successfully!"
"""

[tasks.quick-check]
description = "Quick development checks (format, clippy, test)"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "โšก Running quick checks..."
mise run format
mise run lint
mise run test-lib
echo "โœ… Quick checks passed!"
"""

[tasks.release-check]
description = "Check if ready for release"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿš€ Checking release readiness..."
mise run check-all
echo "Checking version consistency..."
CARGO_VERSION=$(grep '^version = ' Cargo.toml | sed 's/version = "\\(.*\\)"/\\1/')
if [ -f GitVersion.yml ]; then
  GITVERSION_VERSION=$(grep 'next-version:' GitVersion.yml | sed 's/next-version: "\\?\\(.*\\)"\\?/\\1/' | sed 's/-.*//')
  if [ "$CARGO_VERSION" != "$GITVERSION_VERSION" ]; then
    echo "โŒ Version mismatch: Cargo.toml=$CARGO_VERSION, GitVersion.yml=$GITVERSION_VERSION"
    exit 1
  fi
fi
echo "โœ… Release check passed"
"""

# ----------------------------------------------------------------------------
# Release management
# ----------------------------------------------------------------------------
[tasks.release]
description = "Interactive release (manual process)"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿš€ Manual Release Process"
echo ""
echo "๐Ÿ“‹ Release Steps:"
echo "  1. Update version in Cargo.toml"
echo "  2. Update version in GitVersion.yml"
echo "  3. Run: mise run release-check"
echo "  4. Commit changes with: git commit -m 'chore: release version X.Y.Z [skip ci]'"
echo "  5. Create tag: git tag vX.Y.Z"
echo "  6. Push: git push origin main && git push origin vX.Y.Z"
echo ""
echo "๐Ÿ’ก Or use GitHub Actions 'Manual Version Bump' workflow"
"""

[tasks.release-patch]
description = "Guide for patch release"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿš€ Patch Release Guide"
mise run release
"""

[tasks.release-minor]
description = "Guide for minor release"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿš€ Minor Release Guide"
mise run release
"""

[tasks.release-major]
description = "Guide for major release"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿš€ Major Release Guide"
mise run release
"""

# ----------------------------------------------------------------------------
# Development workflow
# ----------------------------------------------------------------------------
[tasks.pre-commit]
description = "Run pre-commit checks"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ” Running pre-commit checks..."
mise run format
mise run lint
mise run test
echo "โœ… Pre-commit checks passed"
"""

[tasks.pre-push]
description = "Run pre-push checks"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ” Running pre-push checks..."
mise run check-all
echo "โœ… Pre-push checks passed"
"""

# ----------------------------------------------------------------------------
# Commit message validation
# ----------------------------------------------------------------------------
[tasks.commit-lint]
description = "Test commit message format (via committed). Usage: MSG='feat: x' mise run commit-lint  (or: mise run commit-lint -- 'feat: x')"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“ Testing commit message format..."
msg="${MSG:-}"
if [ -z "$msg" ] && [ "$#" -gt 0 ]; then msg="$1"; fi
if [ -z "$msg" ]; then
  echo "Usage: MSG='feat: add new feature' mise run commit-lint"
  echo "   or: mise run commit-lint -- 'feat: add new feature'"
  exit 1
fi
if ! command -v committed >/dev/null 2>&1; then
  echo "โŒ committed not found. Install with: cargo install committed"
  exit 1
fi
printf '%s\\n' "$msg" | committed --commit-file -
echo "โœ… Commit message format is valid"
"""

# ----------------------------------------------------------------------------
# Git workflow helpers
# ----------------------------------------------------------------------------
[tasks.git-status]
description = "Show git status with helpful formatting"
run = """
#!/usr/bin/env bash
set -euo pipefail
if [ -z "$(git status --porcelain)" ]; then
  echo "โœ… Working directory clean"
else
  echo "๐Ÿ“‚ Working directory changes:"
  git status --short
fi
"""

# ----------------------------------------------------------------------------
# Pre-commit hooks management
# ----------------------------------------------------------------------------
[tasks.pre-commit-install]
description = "Install pre-commit hooks (replaces manual git hooks)"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ”ง Installing pre-commit hooks..."
if ! command -v pre-commit >/dev/null; then
  echo "โŒ pre-commit not found. Install with: brew install pre-commit"
  exit 1
fi
echo "๐Ÿ“ Switching from manual git hooks to pre-commit..."
git config --unset-all core.hooksPath || true
pre-commit install --install-hooks
pre-commit install --hook-type commit-msg
echo "โœ… Pre-commit hooks installed (manual .githooks disabled)"
"""

[tasks.pre-commit-run]
description = "Run pre-commit hooks on all files"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ” Running pre-commit hooks on all files..."
timeout 120s pre-commit run --all-files
"""

[tasks.pre-commit-dev]
description = "Run pre-commit hooks (without timeout for development)"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ” Running pre-commit hooks..."
pre-commit run --all-files
"""

[tasks.pre-commit-update]
description = "Update pre-commit hooks to latest versions"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "โฌ†๏ธ  Updating pre-commit hooks..."
pre-commit autoupdate
"""

[tasks.pre-commit-clean]
description = "Clean pre-commit cache"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿงน Cleaning pre-commit cache..."
pre-commit clean
"""

[tasks.pre-commit-rust]
description = "Run only Rust-specific pre-commit hooks"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿฆ€ Running Rust-specific pre-commit hooks..."
pre-commit run rust-fmt rust-clippy rust-check rust-test rust-doc
"""

[tasks.pre-commit-quick]
description = "Run quick pre-commit hooks (skip tests and audits)"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "โšก Running quick pre-commit hooks..."
SKIP=rust-test,rust-coverage,rust-audit,rust-deny pre-commit run --all-files
"""

[tasks.pre-commit-security]
description = "Run security-focused pre-commit hooks"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ”’ Running security-focused pre-commit hooks..."
pre-commit run detect-private-key detect-secrets rust-audit rust-deny
"""

# ----------------------------------------------------------------------------
# Installation and dependencies
# ----------------------------------------------------------------------------
[tasks.install-tools]
description = "Install additional development tools"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ”ง Installing development tools..."
if ! command -v cargo-audit >/dev/null; then cargo install cargo-audit; fi
if ! command -v cargo-llvm-cov >/dev/null; then cargo install cargo-llvm-cov; fi
if ! command -v cargo-criterion >/dev/null; then cargo install cargo-criterion; fi
if ! command -v cargo-flamegraph >/dev/null; then cargo install flamegraph; fi
echo "โœ… Development tools installed"
"""

# ----------------------------------------------------------------------------
# Version information
# ----------------------------------------------------------------------------
[tasks.version]
description = "Show version information"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“‹ Version Information:"
echo "Cargo version: $(grep '^version = ' Cargo.toml | sed 's/version = "\\(.*\\)"/\\1/')"
if [ -f GitVersion.yml ]; then
  echo "GitVersion next: $(grep 'next-version:' GitVersion.yml | sed 's/next-version: "\\?\\(.*\\)"\\?/\\1/')"
fi
if command -v git >/dev/null && git rev-parse --git-dir >/dev/null 2>&1; then
  echo "Git commit: $(git rev-parse --short HEAD)"
  echo "Git branch: $(git branch --show-current)"
fi
"""

# ----------------------------------------------------------------------------
# Debug and troubleshooting
# ----------------------------------------------------------------------------
[tasks.debug-env]
description = "Show development environment information"
run = """
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ” Development Environment:"
echo "Rust version: $(rustc --version)"
echo "Cargo version: $(cargo --version)"
if command -v committed >/dev/null; then echo "committed version: $(committed --version)"; fi
echo "Git hooks path: $(git config --get core.hooksPath || echo 'default')"
echo "Commit template: $(git config --get commit.template || echo 'none')"
"""

# ----------------------------------------------------------------------------
# Markdown and documentation
# ----------------------------------------------------------------------------
# NOTE: literal ''' strings โ€” the embedded awk uses \. \* \t regex escapes that
# a basic """ string would reject as invalid TOML escape sequences.
[tasks.check-markdown]
description = "Check markdown formatting (strict โ€” any warning fails the target)"
run = '''
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“ Checking markdown formatting..."
fail=0
for file in *.md; do
  if [ -f "$file" ]; then
    echo "Checking $file..."
    echo "=== MD022 (blank line before heading) ==="
    awk 'BEGIN { in_fence = 0; prev = ""; issues = 0 }
      /^```/ { in_fence = !in_fence; prev = $0; next }
      in_fence { prev = $0; next }
      NR > 1 && /^#{1,6} / && prev != "" { print "  Line " NR ": " $0; issues++ }
      { prev = $0 }
      END { exit (issues > 0 ? 1 : 0) }' "$file" || fail=1
    echo "=== MD032 (blank line before list) ==="
    awk 'BEGIN { in_fence = 0; prev = ""; issues = 0 }
      /^```/ { in_fence = !in_fence; prev = $0; next }
      in_fence { prev = $0; next }
      NR > 1 && (/^[-*+] / || /^[0-9]+\. /) && prev != "" \
        && prev !~ /^[-*+] / && prev !~ /^[0-9]+\. / \
        && prev !~ /^[ \t]/ { print "  Line " NR ": " $0; issues++ }
      { prev = $0 }
      END { exit (issues > 0 ? 1 : 0) }' "$file" || fail=1
    echo ""
  fi
done
if [ $fail -ne 0 ]; then
  echo "โŒ Markdown checks failed โ€” fix the listed lines or update the source files"
  exit 1
fi
echo "โœ… Markdown checks passed"
'''

[tasks.fix-markdown]
description = "Fix common markdown formatting issues"
run = '''
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“ Fixing markdown issues (MD022: blanks around headings, MD031: blanks around fences, MD032: blanks around lists, bold-as-headings)..."
for file in *.md docs/*.md; do
  if [ -f "$file" ]; then
    echo "Processing $file..."
    awk 'BEGIN { prev_line = ""; in_code_block = 0; last_was_blank = 0; need_blank_after = 0 }
      /^```/ {
        if (!in_code_block) {
          if (NR > 1 && !last_was_blank) { print "" }
          in_code_block = 1; print; need_blank_after = 0
        } else {
          in_code_block = 0; print; need_blank_after = 1
        }
        prev_line = $0; last_was_blank = 0; next
      }
      in_code_block { print; prev_line = $0; last_was_blank = 0; next }
      /^#{1,6} \*\*.*\*\*/ { gsub(/\*\*/, "", $0) }
      /^#{1,6} / {
        if (need_blank_after) { print ""; need_blank_after = 0 }
        if (NR > 1 && !last_was_blank && prev_line !~ /^#{1,6} /) { print "" }
        print; prev_line = $0; last_was_blank = 0; next
      }
      /^[-*+] / || /^[0-9]+\. / {
        if (need_blank_after) { print ""; need_blank_after = 0 }
        if (NR > 1 && !last_was_blank && prev_line !~ /^[-*+] / && prev_line !~ /^[0-9]+\. / && prev_line !~ /^  /) { print "" }
        print; prev_line = $0; last_was_blank = 0; next
      }
      /^$/ {
        if (need_blank_after) { need_blank_after = 0 }
        print; prev_line = $0; last_was_blank = 1; next
      }
      {
        if (need_blank_after) { print ""; need_blank_after = 0 }
        if (prev_line ~ /^#{1,6} / && !last_was_blank) { print "" }
        if ((prev_line ~ /^[-*+] / || prev_line ~ /^[0-9]+\. /) && $0 !~ /^[-*+] / && $0 !~ /^[0-9]+\. / && $0 !~ /^  / && !last_was_blank) { print "" }
        print; prev_line = $0; last_was_blank = 0
      }' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
    echo "Fixed $file"
  fi
done
echo "โœ… Markdown formatting completed!"
'''

[tasks.check-markdown-detailed]
description = "Check markdown with detailed line numbers"
run = '''
#!/usr/bin/env bash
set -euo pipefail
echo "๐Ÿ“ Detailed markdown check..."
for file in *.md; do
  if [ -f "$file" ]; then
    echo "=== Analyzing $file ==="
    awk 'BEGIN { prev_line = ""; line_num = 0; issues = 0 }
      { line_num++ }
      /^#{1,6} / {
        if (line_num > 1 && prev_line !~ /^$/) {
          print "MD022 - Line " line_num ": Missing blank line before heading: " $0; issues++
        }
      }
      /^[-*+] / || /^[0-9]+\. / {
        if (line_num > 1 && prev_line !~ /^$/ && prev_line !~ /^[-*+] / && prev_line !~ /^[0-9]+\. / && prev_line !~ /^  /) {
          print "MD032 - Line " line_num ": Missing blank line before list: " $0; issues++
        }
      }
      { prev_line = $0 }
      END {
        if (issues == 0) print "โœ… No issues found";
        else print "โŒ Found " issues " issues"
      }' "$file"
    echo ""
  fi
done
'''