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

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 4, 2023

Files/FileName: improve handling of files using non-underscore, non-dash 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.

Files/FileName: improve handling of files using different file extensions

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)

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 added 3 commits July 4, 2023 09:06
…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.
…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)
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.
Copy link
Member

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GaryJones GaryJones merged commit a1c5aa4 into develop Jul 4, 2023
35 checks passed
@GaryJones GaryJones deleted the feature/filename-dont-assume-file-extension-and-deal-with-other-sep branch July 4, 2023 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants