scripts/linter/README.md
This directory contains the linter patch system for OI-wiki, which provides preprocessing and postprocessing capabilities for Markdown files to ensure consistent formatting and style.
The linter system consists of several components:
utils.py: Core utilitiesdecorators.py: Decorators for the linter pipelinepreprocess.py: Preprocessing functions for fixing Markdown formatting issuespostprocess.py: Postprocessing functions for fixing Markdown formatting issueslinter_patch.py: Main entry point script that orchestrates the linting processThe linter uses a decorator-based pipeline system:
@step decorator: Handles skip blocks and line origin tracking@pipeline decorator: Manages file I/O operations and change detectionThe linter supports skip blocks to exclude certain sections from processing:
<!-- scripts.linter.(preprocess|postprocess).function_name off -->
Content that should be skipped during linting
<!-- scripts.linter.(preprocess|postprocess).function_name on -->
Core utilities:
log(): Debug logging function that respects RUNNER_DEBUG environment variable and uses GitHub Actions workflow commandsindex_lfirst_neq(): Utility to find first non-equal element in an iterableDecorators:
@step decorator: Processes content while handling skip blocks and tracking line origins@pipeline decorator: Wraps functions to handle file operationsPreprocessing functions:
fix_details(): Fixes indentation issues in Markdown content
Postprocessing functions:
fix_full_stop(): Fixes full stop issues in Markdown contentfix_quotation(): Fixes quotation issues in Markdown content while preserving apostropheThe main script linter_patch.py provides a command-line interface:
python scripts/linter_patch.py [directory] -m [mode] [-f files...]
Arguments:
directory: Directory to process recursively (optional)-m, --mode: Processing mode (pre for preprocessing, post for postprocessing)-f, --files: Specific files to process (optional)Examples:
# Process all Markdown files in docs directory with preprocessing
python scripts/linter_patch.py ./docs -m pre
# Process specific files
python scripts/linter_patch.py -f file1.md file2.md -m pre
# Process with postprocessing
python scripts/linter_patch.py ./docs -m post
The linter can be integrated into build processes or used as a standalone tool. It respects the .remarkignore file to exclude certain files from processing.
RUNNER_DEBUG: When set to 1, enables detailed debug logging output. This follows GitHub Actions' default debug logging environment variable as described in the GitHub Actions documentation..remarkignore: Contains list of files to ignore during processing (one filename per line)preprocess.py or postprocess.py)@step decorator to handle skip blockslinter_patch.pyEnable debug mode by setting the RUNNER_DEBUG environment variable:
export RUNNER_DEBUG=1
python scripts/linter_patch.py ./docs -m pre
This will provide detailed logging about:
The logging system uses GitHub Actions workflow commands (see GitHub Actions workflow commands documentation) for structured output that integrates well with GitHub Actions CI/CD pipelines.
The system includes comprehensive error handling:
RuntimeError with location information