Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add KeywordCase rule for Fortran keyword casing #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Arjunmehta312
Copy link

@Arjunmehta312 Arjunmehta312 commented Jan 22, 2025

Add KeywordCase rule to enforce consistent Fortran keyword casing

Description

Adds a new rule to enforce consistent casing of Fortran keywords through configurable regex patterns. This helps maintain consistent code style across Fortran codebases by ensuring keywords like PROGRAM, SUBROUTINE, etc. follow specified case patterns.

Implementation Details

  • Added new KeywordCase class that inherits from FortranRule
  • Uses regex pattern matching similar to existing KindPattern rule (reference lines 533-619 in fortran.py)
  • Default pattern enforces lowercase (^[a-z]+$) but allows custom patterns
  • Integrates with existing rule framework and FortranSource infrastructure
  • Follows project's established pattern for rule implementation

Example Configuration

from stylist.fortran import KeywordCase
from stylist.style import Style

# Default - enforce lowercase keywords
style = Style(KeywordCase())

# Custom pattern - enforce uppercase
style = Style(KeywordCase(r'^[A-Z]+$'))

Testing

Added comprehensive test suite including:

  • Default lowercase pattern validation
  • Custom pattern validation
  • Integration with existing rule framework
  • Line number reporting accuracy
  • Edge cases like comments and strings

Documentation

  • Added rule documentation to user manual
  • Included example configurations
  • Added docstrings following project conventions
  • Updated rule list in documentation

Related Issues

Closes #144

Checklist

  • Code follows project style guidelines
  • Added comprehensive tests
  • Updated documentation
  • Added copyright headers
  • All tests pass
  • Type hints included
  • No new warnings from mypy/flake8

Adds new rule to enforce consistent casing of Fortran keywords using regex patterns. Default enforces lowercase but supports custom patterns.
@Arjunmehta312
Copy link
Author

Please do review and allow merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fortran keywords to match regex
1 participant