better comments and naming in bin/twlight_i18n_lint.pl
use strict;
use warnings;
use Term::ANSIColor;
+
# Experimental features add warning output, which we don't want in our CI logs.
no warnings 'experimental';
# Exit code.
@@ -18,8 +19,8 @@ my $input = do { local $/; <> };
# Check for newlines that can cause message mismatches with translatewiki.
my @newline_errors = ($input =~ /(?<!_)_\(\n(([ \t]*)?"[^\n]*"\n?)*([ \t]*)\)/sg);
foreach my $match (@newline_errors) {
- my $error = "ugettext messages should't be preceded by a newline";
- print_error($error, $filename, $input, $match);
+ my $message = "ugettext messages should't be preceded by a newline";
+ print_error($message, $filename, $input, $match);
}
# Check for messages not preceded by a translator comment.
@@ -28,22 +29,26 @@ foreach my $match (@newline_errors) {
# We're keeping it the pattern well within the limitations of the engine.
my @missing_comment_errors = ($input =~ /(?<!# Translators:[^\n]{1,240}\n)([^\n]*(?<!_)_\((([ \t]*)?"[^\n]*"\n?)*([ \t]*)\)[^\n]\n)/sg);
foreach my $match (@missing_comment_errors) {
- my $error = "Missing Translator comment";
- print_error($error, $filename, $input, $match);
+ my $message = "Missing Translator comment";
+ print_error($message, $filename, $input, $match);
}
-# Print the errors.
+# Prints errors. Surpise!
sub print_error {
- my $error = $_[0];
+ my $message = $_[0];
my $filename = $_[1];
my @input = split /\n/, $_[2];
+ # Drop newlines that complicate comparison.
chomp(my $match = $_[3]);
+ # Drop zero-length matches.
if (length($match) > 0) {
+ # Loop through the input lines
for my $i (0 .. $#input) {
+ # Print the error with line number when we get to the match.
if ("$input[$i]" eq "$match") {
my $number = $i + 1;
$code = 1;
- print colored("ERROR: $error\n$filename:$number\n$match\n", 'red');
+ print colored("ERROR: $message\n$filename:$number\n$match\n", 'red');
}
}
}
