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

Determine includes and excludes based on scores #104

Merged
merged 8 commits into from
Oct 31, 2018

Conversation

herregroen
Copy link
Contributor

Include and exclude matches are based on the strength of the match with:

  1. path matches
  2. filename matches
  3. regex matches

Can probably use improvement but this should cover the base scenarios.

tests/IterableCodeExtractorTest.php Outdated Show resolved Hide resolved
src/IterableCodeExtractor.php Outdated Show resolved Hide resolved
src/IterableCodeExtractor.php Outdated Show resolved Hide resolved
$pattern = preg_quote( str_replace( '*', '__wildcard__', $path_or_file ) );
$pattern = '/' . str_replace( '__wildcard__', '(.+)', $pattern ) . '$';
foreach ( $matchers as $path_or_file ) {
if (
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to have a short comment here describing what is being checked. Maybe something like this:

Suggested change
if (
// Without a wildcard, we can directly check the folder hierarchy.
if (


$root_relative_path = str_replace( static::$dir, '', $file->getPathname() );
if ( false !== mb_ereg( $pattern, $root_relative_path ) ) {
if (
Copy link
Member

Choose a reason for hiding this comment

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

This needs a comment as well. I'm not 100% sure what the reason is for checking both ways, I assume this is done for being overly conservative. This certainly needs an explanation.

Copy link
Contributor Author

@herregroen herregroen Oct 31, 2018

Choose a reason for hiding this comment

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

Needed for partial wildcards like this:

Given an include wildcard of: dir/wp-* any directory starting with dir/wp- should always be checked. We're checking if the directory starts with the matcher.

Whereas for normal wildcards the check is the other way around: one/two/three/*.js means that a directory called one should be checked to see if the matcher starts with the directory.

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.

2 participants