Dead Code Cleanup

January 17, 2026 · View on GitHub

Overview

Task 39 performed a comprehensive cleanup of unused code throughout the codebase, reducing cargo warnings from 153 to 0 while maintaining all existing functionality. The cleanup focused on removing genuinely unused code while preserving aspirational WYSIWYG features with #![allow(dead_code)] annotations.

Summary of Changes

Deleted Files

  • src/files/operations.rs - File I/O utilities that were never used (app uses direct std::fs calls)
  • src/theme/colors.rs - Color constants and utilities never imported outside the module

Removed from src/error.rs

ItemTypeReason
FileNotFoundEnum variantUnused error state
PermissionDeniedEnum variantUnused error state
FileReadEnum variantApp uses FileWrite only
ConfigInvalidEnum variantReplaced by ConfigParse
MarkdownParseEnum variantParser never fails
MarkdownRenderEnum variantRender functions removed
SyntaxLoadEnum variantSyntax loading is infallible
ThemeLoadEnum variantTheme loading is infallible
InitializationEnum variantNot used in current flow
log(), log_with_context()MethodsUnused error logging
is_recoverable(), is_critical()MethodsUnused error categorization
unwrap_or_log_default(), ok_or_log()Trait methodsUnused ResultExt methods
init_logging()FunctionLogging initialized in main.rs

Removed from src/config/

ItemFileReason
ValidationErrorsettings.rsValidation removed in favor of sanitization
Settings::new()settings.rsUse Default::default()
Settings::validate()settings.rsUse sanitize() instead
Settings::is_valid()settings.rsValidation removed
Settings::clear_recent_files()settings.rsUnused method
load_config_strict()persistence.rsUse load_config()
load_or_create_config()persistence.rsUse load_config()
config_exists()persistence.rsUnused check
delete_config()persistence.rsUnused operation

Removed from src/editor/

ItemFileReason
LineNumberGutterline_numbers.rsLogic inlined into widget.rs
LineNumberGutterOutputline_numbers.rsStruct for removed widget
calculate_gutter_width_for_lines()line_numbers.rsInlined into widget.rs
TextStats::format_detailed()stats.rsOnly format_compact() used
Helper functionsstats.rsAll stats via TextStats::from_text()
EditorWidget::frame()widget.rsUnused builder method
EditorWidget::with_settings()widget.rsSettings passed differently
EditorOutput::responsewidget.rsUnused field
EditorOutput::cursor_positionwidget.rsUnused field

Removed from src/theme/

ItemFileReason
ThemeFonts structmod.rsFont scaling not implemented
Entire colors.rscolors.rsModule never imported

Removed from src/markdown/parser.rs

ItemReason
render_to_html()Rendering not used (AST parsing only)
render_to_html_with_options()Rendering not used
MarkdownOptions::gfm()Use Default::default()
MarkdownOptions::minimal()Not used
MarkdownDocument::headings()Document inspection not used
MarkdownDocument::code_blocks()Document inspection not used
MarkdownDocument::links()Document inspection not used
MarkdownDocument::images()Document inspection not used
MarkdownDocument::is_empty()Document inspection not used
MarkdownNode::is_block()Node inspection not used
MarkdownNode::is_inline()Node inspection not used
MarkdownNode::start_columnField never read
MarkdownNode::end_columnField never read

Allowed Dead Code (Aspirational Features)

The following modules have #![allow(dead_code)] because they contain designed-but-not-fully-integrated WYSIWYG editing features:

  • src/markdown/widgets.rs - Editable heading/paragraph/list widgets
  • src/markdown/syntax.rs - Extended syntax highlighting features
  • src/markdown/editor.rs - WYSIWYG editor internals
  • src/state.rs - Comprehensive state management methods
  • src/theme/mod.rs, dark.rs, light.rs, manager.rs - Extended theme utilities

Module Export Cleanup

src/files/mod.rs

  • Removed pub mod operations; (file deleted)
  • Removed re-exports (functions imported directly where needed)

src/editor/mod.rs

  • Removed calculate_gutter_width_for_lines export

src/markdown/mod.rs

  • Removed HeadingLevel, get_highlighter, highlight_code exports

src/theme/mod.rs

  • Removed mod colors; (file deleted)

Test Updates

Tests were updated to:

  1. Remove tests for deleted functionality
  2. Use alternative assertions (e.g., settings.font_size instead of settings.is_valid())
  3. Remove references to deleted methods and types

Final test count: 262 tests pass

Verification

cargo check   # 0 warnings
cargo build   # Success
cargo test    # 262 passed
cargo fmt     # Formatted
cargo clippy  # Only style suggestions remain

Impact on Existing Features

All existing functionality preserved:

  • ✅ File operations (open, save, save as)
  • ✅ Tab management
  • ✅ Theme switching (light/dark/system)
  • ✅ Markdown editing (raw and rendered modes)
  • ✅ Line numbers and text statistics
  • ✅ Recent files menu
  • ✅ Custom title bar and status bar
  • ✅ Keyboard shortcuts