Skip to main content

Blinter is a linter for Windows batch files. It provides comprehensive static analysis to identify syntax errors, security vulnerabilities, performance issues and style problems.

Project description

Blinter 🚀

Blinter is a linter for Windows batch files (.bat and .cmd). It provides comprehensive static analysis to identify syntax errors, security vulnerabilities, performance issues and style problems. Blinter helps you write safer, more reliable and maintainable batch scripts. Even in 2025, batch files deserve professional tooling! 💻

  • Configurable Options - Configurable rules, logging, robust error handling
  • Unicode Support - Support for international characters and filenames
  • Performance Optimized - Handles large files (10MB+) efficiently

Features ✨

🔍 Rule Categories

  • 114 Built-in Rules across 5 severity levels
  • Error Level (E001-E999): Critical syntax errors that prevent execution
  • Warning Level (W001-W999): Potential runtime issues and bad practices
  • Style Level (S001-S999): Code formatting and readability improvements
  • Security Level (SEC001+): Security vulnerabilities and dangerous operations
  • Performance Level (P001-P999): Optimization opportunities and efficiency improvements

📖 For complete rule descriptions with examples and implementation details, see Batch-File-Linter-Requirements.md

📋 Output Format

  • Rule Codes: Each issue has a unique identifier (e.g., E002, W005, SEC003)
  • Clear Explanations: Detailed descriptions of why each issue matters
  • Actionable Recommendations: Specific guidance on how to fix problems
  • Line-by-Line Analysis: Precise location of every issue
  • Context Information: Additional details about detected problems

🚀 Advanced Analysis

  • Static Code Analysis: Detects unreachable code and logic errors
  • Advanced Variable Expansion: Validates percent-tilde syntax (%~n1), string operations, and SET /A arithmetic
  • Command-Specific Validation: FOR loop variations, IF statement best practices, deprecated command detection
  • Variable Tracking: Identifies undefined variables and unsafe usage patterns
  • Security Scanning: Path traversal attacks, command injection risks, unsafe temp file creation
  • Performance Optimization: DIR flag optimization, unnecessary output detection, string operation efficiency
  • Cross-Platform Compatibility: Warns about Windows version issues and deprecated commands
  • Large File Handling: Efficiently processes files up to 10MB+ with performance warnings
  • Robust Encoding Detection: Handles UTF-8, UTF-16, Latin-1 and 6 more encoding formats

Configuration 📝

Blinter supports configuration files to customize its behavior. Create a blinter.ini file in your project directory to set default options.

Creating a Configuration File

Generate a default configuration file with all available options:

python blinter.py --create-config

This creates a blinter.ini file with default settings.

Configuration Options

Section Setting Description Default
[general] recursive Search subdirectories when analyzing folders true
[general] show_summary Display summary statistics after analysis false
[general] max_line_length Maximum line length for S011 rule 120
[general] min_severity Minimum severity level to report None (all)
[rules] enabled_rules Comma-separated list of rules to enable exclusively None (all enabled)
[rules] disabled_rules Comma-separated list of rules to disable None

Command Line Override

Command line options always override configuration file settings:

# Use config file settings
python blinter.py myscript.bat

# Override config to show summary
python blinter.py myscript.bat --summary

# Ignore config file completely
python blinter.py myscript.bat --no-config

Example Configurations

Strict Mode (Errors and Security Only):

[rules]
enabled_rules = E001,E002,E003,E004,E005,E006,E007,E008,E009,E010,E011,E012,E013,E014,E015,E016,E017,E018,SEC001,SEC002,SEC003,SEC004,SEC005,SEC006,SEC007,SEC008,SEC009,SEC010,SEC011,SEC012,SEC013

Style-Free Mode (Disable All Style Rules):

[rules]
disabled_rules = S001,S002,S003,S004,S005,S006,S007,S008,S009,S010,S011,S012,S013,S014,S015,S016,S017,S018,S019,S020

CI/CD Mode (Warnings and Above Only):

[general]
min_severity = WARNING
show_summary = true

Installation 🛠️

🚀 Quick Start (Recommended)

Option 1: Install via pip

pip install Blinter

Option 2: Download standalone executable

  • Download the latest Blinter-v1.0.x-windows.zip from GitHub Releases
  • Extract and run

🔧 Manual Installation

  1. Clone the repository:
git clone https://github.com/tboy1337/Blinter.git
cd Blinter
  1. (Optional) Create a virtual environment:
python -m venv venv
venv\Scripts\activate
  1. (Optional but recommended) Install dependencies:
pip install -r requirements.txt

Prerequisites

  • Python 3.9+ (required for pip installation and development)
  • Windows OS (required for standalone executable)

Usage 📟

Basic Usage

If installed via pip:

# Analyze a single batch file
blinter script.bat

# Analyze all batch files in a directory (recursive)
blinter /path/to/batch/files

# Analyze batch files in directory only (non-recursive)
blinter /path/to/batch/files --no-recursive

# Analyze with summary
blinter script.bat --summary

# Create configuration file
blinter --create-config

# Ignore configuration file
blinter script.bat --no-config

# Get help
blinter --help

If using standalone executable:

# Analyze a single batch file
Blinter.exe script.bat

# Analyze all batch files in a directory (recursive)
Blinter.exe /path/to/batch/files

# Analyze batch files in directory only (non-recursive)
Blinter.exe /path/to/batch/files --no-recursive

# Analyze with summary
Blinter.exe script.bat --summary

# Get help
Blinter.exe --help

If using manual installation:

# Analyze a single batch file
python blinter.py script.bat

# Analyze all batch files in a directory (recursive)
python blinter.py /path/to/batch/files

# Analyze batch files in directory only (non-recursive)
python blinter.py /path/to/batch/files --no-recursive

# Analyze with summary
python blinter.py script.bat --summary

# Create configuration file
python blinter.py --create-config

# Ignore configuration file
python blinter.py script.bat --no-config

# Get help
python blinter.py --help

Command Line Options

  • <path>: Path to a batch file (.bat or .cmd) OR directory containing batch files
  • --summary: Display summary statistics of issues found
  • --severity: Show detailed severity level breakdown (always included)
  • --no-recursive: When processing directories, only analyze files in the specified directory (not subdirectories)
  • --no-config: Don't use configuration file (blinter.ini) even if it exists
  • --create-config: Create a default blinter.ini configuration file and exit
  • --help: Show help menu and rule categories

Note: Command line options override configuration file settings. Blinter automatically looks for blinter.ini in the current directory.

🐍 Programmatic API Usage

Blinter provides a powerful Python API for integration into your applications:

import blinter

# Basic usage
issues = blinter.lint_batch_file("script.bat")
for issue in issues:
    print(f"Line {issue.line_number}: {issue.rule.name} ({issue.rule.code})")

# With custom configuration
from blinter import BlinterConfig, RuleSeverity
config = BlinterConfig(
    max_line_length=80,
    disabled_rules={"S007", "S011"},
    min_severity=RuleSeverity.WARNING
)
issues = blinter.lint_batch_file("script.bat", config=config)

# Process results
for issue in issues:
    print(f"Line {issue.line_number}: {issue.rule.name}")
    print(f"  {issue.rule.explanation}")
    print(f"  Fix: {issue.rule.recommendation}")

# Legacy API (still supported for backward compatibility)
issues = blinter.lint_batch_file(
    "script.bat",
    max_line_length=100,           # Custom line length limit  
    enable_style_rules=False,      # Disable style checks
    enable_performance_rules=True  # Keep performance checks
)

# Thread-safe design allows safe concurrent usage
# You can implement your own concurrent processing if needed
from concurrent.futures import ThreadPoolExecutor

files = ["script1.bat", "script2.cmd", "script3.bat"]
with ThreadPoolExecutor(max_workers=4) as executor:
    results = list(executor.map(blinter.lint_batch_file, files))

🔧 Configuration Options

Parameter Type Default Description
file_path str Required Path to batch file to analyze
max_line_length int 120 Maximum line length for S011 rule
enable_style_rules bool True Enable/disable style-related rules
enable_performance_rules bool True Enable/disable performance rules

Note: Security rules are always enabled for safety.

Supported File Types

  • .bat files (traditional batch files)
  • .cmd files (recommended for modern Windows)
  • Unicode filenames and international characters supported
  • Large files (10MB+) handled efficiently with performance monitoring

📁 Directory Processing

Blinter can analyze entire directories of batch files with powerful options:

  • Recursive Analysis: Automatically finds and processes all .bat and .cmd files in directories and subdirectories
  • Non-Recursive Mode: Use --no-recursive to analyze only files in the specified directory
  • Batch Processing: Handles multiple files efficiently with consolidated reporting
  • Error Resilience: Continues processing other files even if some files have encoding or permission issues
  • Progress Tracking: Shows detailed results for each file plus combined summary statistics

Examples:

# Pip installation:
blinter ./my-batch-scripts                 # Analyze all files recursively
blinter . --no-recursive                   # Current directory only
blinter ./scripts --summary               # With summary statistics

# Standalone executable:
Blinter.exe ./my-batch-scripts            # Analyze all files recursively
Blinter.exe . --no-recursive             # Current directory only
Blinter.exe ./scripts --summary          # With summary statistics

# Manual installation:
python blinter.py ./my-batch-scripts      # Analyze all files recursively
python blinter.py . --no-recursive       # Current directory only  
python blinter.py ./scripts --summary     # With summary statistics

🔥 Integration Example

CI/CD Integration

# Example GitHub Actions workflow
- name: Lint Batch Files
  run: |
    python -c "
    import blinter
    import sys
    issues = blinter.lint_batch_file('deploy.bat')
    errors = [i for i in issues if i.rule.severity.value == 'Error']
    if errors:
        print(f'Found {len(errors)} critical errors!')
        sys.exit(1)
    print(f'✅ Batch file passed with {len(issues)} total issues')
    "

Contributing 🤝

Contributions are welcome!

Ways to Contribute

  • 🐛 Report bugs or issues
  • 💡 Suggest new rules or features
  • 📖 Improve documentation
  • 🧪 Add test cases
  • 🔧 Submit bug fixes or enhancements

License 📄

This project is licensed under the CRL License - see LICENSE.md for details.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

blinter-1.0.4.tar.gz (107.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

blinter-1.0.4-py3-none-any.whl (45.1 kB view details)

Uploaded Python 3

File details

Details for the file blinter-1.0.4.tar.gz.

File metadata

  • Download URL: blinter-1.0.4.tar.gz
  • Upload date:
  • Size: 107.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for blinter-1.0.4.tar.gz
Algorithm Hash digest
SHA256 7a9af013c8b61e7c17611a2ed4a5d19bb057ae714e5eadc2e3ec9241f561e954
MD5 400d39bf136c6fb7addbfbe2d4e44e82
BLAKE2b-256 118a8c7b7f2e87e8fd19c9367f27d6560a7500824760844bff4fa921c72f4d3d

See more details on using hashes here.

File details

Details for the file blinter-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: blinter-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 45.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for blinter-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 33816fbebbe36cb3b9737703b60837a3136487995db38d305d3c7d70f36732d7
MD5 c2a30d839ee1ead20224bcacafae1ef9
BLAKE2b-256 418c03db580df319165436c37009b7875bc627af3fe2d04f9ed75b217a22d3a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page