Claude/refactor main function#21
Merged
Merged
Conversation
- Replace broad `except Exception` with specific exception types across all scripts (data_masking.py, unmask_data.py, diagnose_mapping.py, modules/config.py, modules/tools.py) - Add debug logging to empty `except ImportError: pass` blocks for optional module imports - Add file size validation (100 MB limit) before reading files into memory to prevent DoS - Add mapping file schema validation (validate_mapping_schema) in unmask_data.py - Add missing logger calls alongside warning/error print() statements - Add configurable masking parameters to MaskingRulesConfig (rank_shift, date_shift, brigade range, etc.) - Add missing type hints (tools.py, diagnose_mapping.py, unmask_data.py) - Add .pre-commit-config.yaml (flake8, isort, mypy, trailing whitespace) - Add mypy.ini with per-module configuration - Create CHANGELOG.md with full version history - Add tests for masking_logger (JsonFormatter, ConsoleFormatter, MaskingLogger, file logging) - Add tests for selective module (filters, aliases, groups, roundtrips) - Add tests for password_generator (generate, config, constants, variety) All 397 tests pass. https://claude.ai/code/session_01KpVjBebKBWKQauU4YR5KhH
Split the ~500-line main() function in data_masking.py into 12 well-named helper functions, each with a single responsibility: - _build_parser() — CLI argument parser setup - _load_config() — YAML config loading with error handling - _setup_logger() — structured logging initialization - _apply_selective_filters() — --only/--exclude filter application - _apply_config_settings() — config-based masking rules and system settings - _prepare_output_paths() — output/map/report path computation - _read_input() — file reading with size validation - _run_masking() — masking pipeline dispatcher - _run_multi_pass_masking() — multi-pass re-masking with chain tracking - _run_single_pass_masking() — single-pass masking - _handle_encryption() — mapping file encryption - _write_report() — detailed report generation - _print_summary() — console output summary - _save_results() — orchestrates saving output, mapping, encryption, report The refactored main() is now ~80 lines and reads as a clear pipeline. All 397 tests pass with no behavioral changes. https://claude.ai/code/session_01KpVjBebKBWKQauU4YR5KhH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.