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

Added possibility to specify global ignores. #73

Closed
wants to merge 11 commits into from
Closed

Added possibility to specify global ignores. #73

wants to merge 11 commits into from

Conversation

mgruner
Copy link
Contributor

@mgruner mgruner commented Jan 13, 2017

As suggested in #70.

@mgruner
Copy link
Contributor Author

mgruner commented Jan 13, 2017

If you agree on this I can try to add test cases and documentation.

@@ -252,6 +252,10 @@ sub new_from_conf_file {
die "no such file '$conf_file'" unless $conf_file->is_file;
my $conf_params = $class->_read_conf_file($conf_file);
my $main_params = delete( $conf_params->{'_'} ) || {};
my $global_ignores = delete $main_params->{'ignore'} || [];
Copy link
Member

Choose a reason for hiding this comment

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

There's no need for delete here.

@@ -252,6 +252,10 @@ sub new_from_conf_file {
die "no such file '$conf_file'" unless $conf_file->is_file;
my $conf_params = $class->_read_conf_file($conf_file);
my $main_params = delete( $conf_params->{'_'} ) || {};
my $global_ignores = delete $main_params->{'ignore'} || [];
for my $plugin_name (keys %{ $conf_params }) {
push @{ $conf_params->{$plugin_name}->{'ignore'} || []}, @$global_ignores;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think altering the plugin config like this is the way to make this work. I know it's the easiest approach, but it doesn't seem right to me.

I think it'd be better to add an attribute to the Code::TidyAll object called global_ignores and then use that in the find_matched_files method.

@mgruner
Copy link
Contributor Author

mgruner commented Jan 13, 2017

I see your point, and I just tried to change it as suggested. There is one drawback with that: if somebody doesn't use find_matched_files, and uses process_paths or similar methods directly, the global ignores will be ignored. 😁 This would also affect the Git handlers in Code::TidyAll, for example. With the more hackish solution that this PR provides, it works well, as the plugins refuse to operate on globally ignored files no matter how the file list was determined. What do you think?

@mgruner
Copy link
Contributor Author

mgruner commented Jan 13, 2017

Ok, please ignore my previous comment. I implemented it as you wished, the tests are all passing.

@@ -112,6 +112,12 @@ has 'plugins' => (
required => 1,
);

has 'global_ignore' => (
is => 'ro',
ias => t('ArrayRef'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo?

@autarch autarch dismissed their stale review January 14, 2017 16:38

Superceded

@autarch
Copy link
Member

autarch commented Jan 14, 2017

This looks generally good modulo the typo that @2shortplanks noticed.

@mgruner
Copy link
Contributor Author

mgruner commented Jan 14, 2017

Fixed. This was a C&P error from a few lines above that had the same error (and I'm not familiar with Moo(se)). I also fixed that line.

Copy link
Member

@autarch autarch left a comment

Choose a reason for hiding this comment

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

I had a few more design comments. Otherwise this looks good but it needs some tests and docs.

@@ -659,6 +669,10 @@ sub find_matched_files {
my $root_length = length( $self->root_dir );
foreach my $plugin ( @{ $self->plugin_objects } ) {
my @selected = grep { -f && !-l } $self->_zglob( $plugin->selects );
if ( @{ $self->global_ignore || [] } ) {
Copy link
Member

Choose a reason for hiding this comment

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

If global_ignore had a default of sub { [] } you wouldn't need the || [] bit here.

Also, this could be combined with the check for the plugin ignores in one map statement and call to $self->_zglob.

has 'select_regex' => ( is => 'lazy' );
has 'selects' => ( is => 'lazy' );
has 'global_ignore_regex' => ( is => 'lazy' );
has 'global_ignores' => ( is => 'lazy' );
Copy link
Member

Choose a reason for hiding this comment

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

Instead of making every plugin generate these two attributes over and over let's just move the regex to Code::TidyAll and then call $self->tidyall->global_ignore_regex in the matches_path method.

@mgruner
Copy link
Contributor Author

mgruner commented Jan 16, 2017

POD and tests modified to cover global ignores. I copied the _parse_zglob_list to the TidyAll object, not sure if that is the best solution.
I also had to add deep cloning in _dump_params because without that the original data structure was altered and broken. You can try that by commenting the dclone call and running the tests. This might add a new dependency to the Storable module, which is in perlcore.
I also added tests for the previous ignore functionality, which were not present so far, AFAICT.

@mgruner
Copy link
Contributor Author

mgruner commented Jan 16, 2017

I could need some help with the Storable issue. It seems that dclone cannot handle CODE refs, which causes failures on unit tests passing in a custom msg_output handler. Maybe it would be better to do without Storable?

@mgruner
Copy link
Contributor Author

mgruner commented Jan 16, 2017

Solved. Dependency on Storable is removed again. Reason was a buggy _recurse_dump() implementation, which was broken at least for array refs.

@autarch
Copy link
Member

autarch commented Jan 19, 2017

Looks like the code isn't tidy ;)

@mgruner
Copy link
Contributor Author

mgruner commented Jan 19, 2017

Should be fixed, sorry.

@autarch
Copy link
Member

autarch commented Feb 1, 2017

I did some additional fiddling and merged this from the CLI. Thanks!

@autarch autarch closed this Feb 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants