Skip to content

Instantly share code, notes, and snippets.

@mberlanda
Created July 30, 2018 14:13
Show Gist options
  • Save mberlanda/3fdcc1e11b9a191e06ea08a6fb985407 to your computer and use it in GitHub Desktop.
Save mberlanda/3fdcc1e11b9a191e06ea08a6fb985407 to your computer and use it in GitHub Desktop.
Parse rubocop.yml and find out non existing files
#!/usr/bin/env perl -w
use 5.006;
use strict;
use warnings;
use YAML::Tiny;
use Cwd qw( cwd );
use File::Spec::Functions qw( catfile catdir );
my $yaml = YAML::Tiny->read(
catfile(cwd(), ".rubocop.yml")
);
my @excluded_lines = qw(
require
AllCops
);
my @relevant_options = qw(
Exclude
);
my @excluded_files = ();
foreach my $cop (keys %{$yaml->[0]}) {
if (grep /^$cop$/, @excluded_lines) {
print "Excluded line: $cop\n";
} else {
print "Processing $cop ...\n";
foreach my $opt (keys %{$yaml->[0]{$cop}}) {
if (grep /^$opt$/, @relevant_options) {
foreach my $file (@{$yaml->[0]{$cop}{$opt}}) {
push @excluded_files, $file;
print "$file\n";
}
} else {
print "Skipping $opt ...\n";
}
}
}
}
print "---------------\n\n\n";
print "Files to delete: \n";
foreach my $f (@excluded_files) {
if (! -e $f) {
print "$f\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment