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

Files/FileName: various improvements #2285

Commits on Jul 4, 2023

  1. Files/FileName: improve handling of files using non-underscore, non-d…

    …ash word separators
    
    Addresses Gary's question in 2154:
    
    > I can see there are some test files with extra `.` in (and not just underscores), but I was wondering if an incorrect file name like `class.my-class.php` might be detected, as the checking for hyphenation only replaces underscores.
    
    I have tested this and while the file would already be flagged by the "class name vs file name check", the "is hyphenated" check would not flag the file.
    
    Fixed now. Includes extra tests.
    
    Note: this fix requires that the numbered test files we were using have to be renamed as the `.#.inc` would cause the sniff to throw errors when there shouldn't be any.
    
    Related to issue 2164, but doesn't fix it completely.
    jrfnl committed Jul 4, 2023
    Configuration menu
    Copy the full SHA
    9c87876 View commit details
    Browse the repository at this point in the history
  2. Files/FileName: improve handling of files using different file extens…

    …ions
    
    Addresses Gary's second question in 2154:
    
    > I also see `substr( $file_name, 0, -4 )`, which is assuming that a PHP-rendered file will always have a three letter file extension, but I wonder if someone could break that assumption with `--extensions=php3,myphp` or similar.
    
    While I still think we should add a rule about requiring the `.php` extension to the handbook (after a Make post), as that rule currently doesn't exist, the sniff should not assume that all files will have a three character file extension.
    
    Fixed now. Includes extra tests.
    
    Related to issue 2164, but doesn't fix it completely. (the "check for a `.php` file extension" is not addressed yet as this is not a handbook rule at this time)
    jrfnl committed Jul 4, 2023
    Configuration menu
    Copy the full SHA
    04516e5 View commit details
    Browse the repository at this point in the history
  3. Files/FileName: update for changes in WP Core

    In WP 6.1.0, the classes contained in the files listed in `$class_exceptions` were moved to files which comply with the file name requirements.
    The original files still remain, but no longer contain a class, so we no longer need to make an exception for these in the `check_filename_has_class_prefix()` check.
    
    However, with the stricter check for hyphenation-only word separators as introduced in the earlier commit, we do need to continue making an exception for these files for the `check_filename_is_hyphenated()` check.
    
    For that reason, the properties remain.
    
    Having said that, in this commit:
    * I remove the check against these properties from the `check_filename_has_class_prefix()` check.
    * The properties are renamed to `$*hyphenation_exceptions` to better reflect what they are used for.
    * Two additional non-compliant files from WP Core are added to the list.
    jrfnl committed Jul 4, 2023
    Configuration menu
    Copy the full SHA
    39183db View commit details
    Browse the repository at this point in the history