Skip to content

Enhanced Max Line Length Rule

Latest

Choose a tag to compare

@floriankraemer floriankraemer released this 04 Dec 19:04
· 1 commit to master since this release
cbebe41

Release Notes - Version 1.6.0

πŸŽ‰ New Features

✨ Enhanced Max Line Length Rule

Enhancement: Flexible Line Type Ignoring

  • Class: Phauthentic\PHPStanRules\CleanCode\MaxLineLengthRule

  • Purpose: Extended to support ignoring multiple types of lines beyond just use statements, providing more granular control over line length checking

  • Key Features:

    • New Array-Based API: Introduced ignoreLineTypes parameter for flexible configuration
    • Multiple Line Types: Support for ignoring use statements, namespace declarations, and docblocks
    • Backward Compatible: Existing ignoreUseStatements parameter continues to work unchanged
    • Selective Control: Choose which line types to ignore independently
  • Supported Line Types:

    • useStatements - Ignore lines containing use statements (e.g., use Some\Very\Long\Namespace\Path\ClassName;)
    • namespaceDeclaration - Ignore lines containing namespace declarations (e.g., namespace App\Some\Very\Long\Namespace\Path;)
    • docBlocks - Ignore lines that are part of docblock comments (e.g., /** This is a very long docblock comment that exceeds the line length limit */)
  • Configuration: Supports new optional parameter:

    • ignoreLineTypes (array, default: []) - Array of line types to ignore with boolean values
    • ignoreUseStatements (boolean, default: false) - Maintained for backward compatibility, takes precedence when set
  • Backward Compatibility:

    • The existing ignoreUseStatements parameter remains fully functional
    • When both ignoreUseStatements and ignoreLineTypes['useStatements'] are set, ignoreUseStatements takes precedence
    • All existing configurations continue to work without modification

πŸ“š Documentation Improvements

πŸ“š Enhanced Max Line Length Rule Documentation

  • Comprehensive Examples: Added detailed configuration examples for:

    • New array-based API (recommended approach)
    • Legacy parameter usage (backward compatible)
    • Selective line type ignoring
    • Combined configurations
  • Parameter Documentation: Complete documentation of all parameters including:

    • maxLineLength - Maximum allowed line length
    • excludePatterns - File exclusion patterns
    • ignoreUseStatements - Legacy parameter for backward compatibility
    • ignoreLineTypes - New array-based configuration option
  • Use Cases Section: Examples showing:

    • Ignoring only use statements
    • Ignoring namespace declarations and docblocks
    • Ignoring all supported line types
    • Combining with file exclusions

πŸš€ Migration Guide

For Existing Users

No Action Required! All existing configurations continue to work without any changes. The new ignoreLineTypes parameter is optional and disabled by default, so your current setup will behave exactly as before.

For New Configurations

Recommended: Use the new array-based API for better flexibility:

ignoreLineTypes:
    useStatements: true
    namespaceDeclaration: true
    docBlocks: true

Legacy: The ignoreUseStatements parameter still works and is fully supported:

ignoreUseStatements: true

πŸ’‘ Why This Matters

The previous version only supported ignoring use statements. Many codebases have long namespace declarations or detailed docblocks that exceed line length limits but are acceptable for readability. This release provides the flexibility to ignore these line types while still enforcing line length limits for actual code logic.

Before (1.5.1): Only use statements could be ignored
After (1.6.0): You can now ignore:

  • Use statements
  • Namespace declarations
  • Docblock comments
  • Any combination of the above

This significantly improves the rule's usability in real-world scenarios where certain types of long lines are acceptable or even preferred for code clarity.


This release represents a major enhancement to the Max Line Length Rule while maintaining 100% backward compatibility with existing configurations. We recommend gradually adopting the new array-based API for better flexibility and future-proofing your configuration.

Full Changelog: 1.5.1...1.6.0