CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-sphinx-lint

Check for stylistic and formal issues in .rst and .py files included in the documentation

Overview
Eval results
Files

configuration.mddocs/

Configuration Options

Configuration system for controlling checker behavior, output formatting, and processing options in sphinx-lint.

Capabilities

Checker Options Configuration

Main configuration class for controlling checker behavior and validation thresholds.

class CheckersOptions:
    """Configuration options for checkers."""
    
    max_line_length = 80
    
    @classmethod
    def from_argparse(cls, namespace):
        """
        Create CheckersOptions from argparse namespace.
        
        Parameters:
        - namespace (argparse.Namespace): from CLI argument parsing
        
        Returns:
        CheckersOptions: instance with values from command-line arguments
        """

Usage Example

from sphinxlint.sphinxlint import CheckersOptions
from sphinxlint import check_file
from sphinxlint.checkers import all_checkers

# Create custom options
options = CheckersOptions()
options.max_line_length = 120

# Use with checking functions
enabled_checkers = {checker for checker in all_checkers.values() if checker.enabled}
errors = check_file("docs/api.rst", enabled_checkers, options)

Command-Line Configuration

The CLI system provides extensive configuration options through command-line arguments.

Checker Selection

# Enable specific checkers (including disabled-by-default ones)
sphinx-lint --enable line-too-long,default-role docs/

# Disable specific checkers
sphinx-lint --disable trailing-whitespace,horizontal-tab docs/

# Complex combinations (evaluated left-to-right)
sphinx-lint --disable all --enable trailing-whitespace docs/
sphinx-lint --enable all --disable line-too-long,default-role docs/

Line Length Configuration

# Set custom line length limit
sphinx-lint --max-line-length 120 docs/

# Use with line-too-long checker (disabled by default)
sphinx-lint --enable line-too-long --max-line-length 88 docs/

Processing Configuration

# Parallel processing configuration
sphinx-lint --jobs 4 docs/           # Use 4 parallel processes
sphinx-lint --jobs auto docs/        # Auto-detect CPU count (default)
sphinx-lint --jobs 1 docs/           # Force single-threaded

# Output sorting configuration
sphinx-lint --sort-by filename docs/              # Sort by filename
sphinx-lint --sort-by line docs/                  # Sort by line number
sphinx-lint --sort-by error_type docs/            # Sort by checker name
sphinx-lint --sort-by filename,line docs/         # Multiple sort criteria

File Filtering Configuration

# Ignore specific paths
sphinx-lint --ignore build/ docs/
sphinx-lint --ignore __pycache__ --ignore "*.tmp" docs/

# Multiple ignore patterns
sphinx-lint -i build/ -i temp/ -i "*.backup" docs/

Verbosity Configuration

# Verbose output (show all checked files)
sphinx-lint --verbose docs/

# List available checkers
sphinx-lint --list
sphinx-lint --list --verbose    # Include detailed descriptions

Configuration Classes and Enums

Sort Field Configuration

Enumeration of available fields for error sorting.

class SortField(enum.Enum):
    """Fields available for sorting error reports"""
    
    FILENAME = 0
    LINE = 1
    ERROR_TYPE = 2
    
    @staticmethod
    def as_supported_options() -> str:
        """
        Return comma-separated list of supported sort field names.
        
        Returns:
        String of lowercase field names separated by commas
        """

Usage Example

from sphinxlint.cli import SortField

# Get available sort options
print(f"Available sort fields: {SortField.as_supported_options()}")

# Use in programmatic sorting
sort_fields = [SortField.FILENAME, SortField.LINE]

Programmatic Configuration

Creating Custom Options

from sphinxlint.sphinxlint import CheckersOptions

# Create with custom settings
options = CheckersOptions()
options.max_line_length = 100

# The options object is passed to all checker functions
# Individual checkers can access configuration through the options parameter

Integration with argparse

import argparse
from sphinxlint.sphinxlint import CheckersOptions

# Create argparse parser
parser = argparse.ArgumentParser()
parser.add_argument('--max-line-length', type=int, default=80)
args = parser.parse_args(['--max-line-length', '120'])

# Convert to CheckersOptions
options = CheckersOptions.from_argparse(args)
print(f"Max line length: {options.max_line_length}")  # Output: 120

Configuration File Support

Currently, sphinx-lint does not support configuration files (like .sphinx-lint.cfg or pyproject.toml sections). All configuration is done through command-line arguments or programmatic API usage.

Integration Recommendations

For project-level configuration, you can:

  1. Use Makefile targets:
lint-docs:
	sphinx-lint --max-line-length 120 --disable trailing-whitespace docs/
  1. Create shell scripts:
#!/bin/bash
# lint-docs.sh
sphinx-lint \
    --max-line-length 120 \
    --disable trailing-whitespace,horizontal-tab \
    --enable line-too-long \
    --jobs auto \
    --sort-by filename,line \
    "$@"
  1. Use in pre-commit hooks:
repos:
  - repo: https://github.com/sphinx-contrib/sphinx-lint
    rev: v1.0.0
    hooks:
      - id: sphinx-lint
        args:
          - --max-line-length=120
          - --disable=trailing-whitespace
          - --enable=line-too-long

Environment Integration

CI/CD Configuration

# GitHub Actions example
- name: Lint documentation
  run: |
    pip install sphinx-lint
    sphinx-lint \
      --max-line-length 88 \
      --enable line-too-long \
      --disable trailing-whitespace \
      --jobs auto \
      --sort-by filename,line \
      docs/

Editor Integration

For editors that support external linters:

// VS Code settings.json example
{
  "python.linting.enabled": true,
  "python.linting.sphinxLintEnabled": true,
  "python.linting.sphinxLintArgs": [
    "--max-line-length=120",
    "--disable=trailing-whitespace"
  ]
}

Performance Configuration

Parallel Processing

The CLI automatically optimizes parallel processing:

  • Files < 8: Always single-threaded (overhead not worth it)
  • Files >= 8: Uses parallel processing based on --jobs setting
  • Default: --jobs auto uses os.cpu_count() for optimal performance

Memory Management

  • Per-file caches are automatically cleared after each file check
  • No persistent state between file checks
  • Memory usage scales with file size and enabled checker count

Install with Tessl CLI

npx tessl i tessl/pypi-sphinx-lint

docs

checkers.md

cli.md

configuration.md

core-checking.md

index.md

tile.json