Created
May 27, 2016 17:59
-
-
Save pozorvlak/af43fed67c698b7e255b2feb91731acb to your computer and use it in GitHub Desktop.
This file contains 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/perl | |
# Script to (generate a script to) fix excess use of double-quotes in HAML. | |
# To use: | |
# | |
# haml-lint app/views/ > haml_errors | |
# grep "you don't need string interpolation" haml_errors | awk '{print $1}' > single_quote_me | |
# perl single_quote.pl | |
# bash fixme.sh | |
# git commit -a -m "Use single-quotes in straightforward cases" | |
# | |
# This should fix all the "easy" cases (only one string per line). Eyeball the | |
# file problem_lines, delete any cases where string interpolation is used, | |
# and save it. Then run | |
# | |
# awk '{print $1}' problem_lines > single_quote_me | |
# perl single_quote.pl -f | |
# bash fixme.sh | |
# git commit -a -m "Use single-quotes in slightly harder cases" | |
# | |
# Now fix the remaining hard cases by hand. | |
open my $fixups, "<", "single_quote_me"; | |
open my $problem_lines, ">", "problem_lines"; | |
open my $gen_script, ">", "fixme.sh"; | |
my $force = ($ARGV[0] eq "-f"); | |
print $gen_script "#!/bin/sh\n\n"; | |
for my $fixup (<$fixups>) { | |
chomp $fixup; | |
my ($file, $line_num) = split(/:/, $fixup); | |
open my $fh, "<", $file; | |
my @lines = <$fh>; | |
my $line = $lines[$line_num - 1]; | |
my @quotes = ($line =~ /"/g); | |
if ($force || (scalar(@quotes) <= 2)) { | |
my $sed = 'sed -i "' . $line_num . ' s/\"/\'/g"' . " $file\n"; | |
print $gen_script $sed; | |
} else { | |
print $problem_lines "$fixup $line"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment