Last active
January 29, 2019 10:36
-
-
Save mberlanda/3769af5af844fdc82fbf9d55f7e250f3 to your computer and use it in GitHub Desktop.
Perl script to parse rubocop configuration files and looking for dead references
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 ); | |
# This scripts allows to find out which files are excluded in .rubocop.yml | |
# and do not exist anymore | |
# Install cpanminus on mac: http://macappstore.org/cpanminus/ | |
# sudo cpanm -i YAML::Tiny | |
# perl rubocop-cleanup.pl | |
# perl rubocop-cleanup.pl .rubocop_todo.yml | |
my ($arg_file) = shift; | |
my $cop_file = $arg_file // catfile(cwd(), ".rubocop.yml"); | |
if (!-e $cop_file) { | |
die "${cop_file} does not exists"; | |
} | |
my $yaml = YAML::Tiny->read($cop_file); | |
my @excluded_lines = qw( | |
inherit_from | |
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